From 0e703791ea6475309194e444f717fd9602463a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Wed, 13 Aug 2025 19:14:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E5=B7=B2=E7=BB=8F=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=20agents.go=20=E5=92=8C=20chat=5Fcompletions.go?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E5=AE=83=E4=BB=AC=E8=83=BD=E5=A4=9F=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=AF=BB=E5=8F=96=E5=B9=B6=E4=BD=BF=E7=94=A8=E6=82=A8?= =?UTF-8?q?=E5=9C=A8=20docker-compose.yml=20=E4=B8=AD=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=20CODEX=5FAPI=5FMODEL=5FNAME=20=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E4=BB=BB?= =?UTF-8?q?=E4=BD=95=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84=E5=80=BC=E3=80=82?= =?UTF-8?q?=E8=BF=99=E4=BB=8E=E6=A0=B9=E6=9C=AC=E4=B8=8A=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E4=BA=86=20Visual=20Studio=20=E6=99=BA=E8=83=BD=E4=BD=93?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/controller/copilot/agents.go | 9 ++++++--- internal/controller/copilot/chat_completions.go | 14 ++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/controller/copilot/agents.go b/internal/controller/copilot/agents.go index e543364..9c6a0d1 100644 --- a/internal/controller/copilot/agents.go +++ b/internal/controller/copilot/agents.go @@ -4,6 +4,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gofrs/uuid" "net/http" + "os" ) // GetAgents 获取代理列表 @@ -11,6 +12,8 @@ func GetAgents(c *gin.Context) { requestID := uuid.Must(uuid.NewV4()).String() c.Header("x-github-request-id", requestID) + modelName := os.Getenv("CODEX_API_MODEL_NAME") + c.JSON(http.StatusOK, gin.H{ "agents": []gin.H{ { @@ -19,10 +22,10 @@ func GetAgents(c *gin.Context) { "description": "Ask questions and get answers about your codebase.", "version": "1.0.0", "publisher": "github", - "model": "gpt-4o-mini-2024-07-18", + "model": modelName, "capabilities": "workspace", - "default_model": "gpt-4o-mini-2024-07-18", - "capabilities_model": "gpt-4o-mini-2024-07-18", + "default_model": modelName, + "capabilities_model": modelName, }, }, }) diff --git a/internal/controller/copilot/chat_completions.go b/internal/controller/copilot/chat_completions.go index 8994439..d2dd97b 100644 --- a/internal/controller/copilot/chat_completions.go +++ b/internal/controller/copilot/chat_completions.go @@ -170,19 +170,21 @@ func ChatCompletions(c *gin.Context) { // vs2022FirstChatTemplate is a template for the first chat completion response func vs2022FirstChatTemplate(c *gin.Context) { - fixedOutput := `data: {"id":"f6202f6f-9d13-4518-b34f-65e945b0a1a2","object":"chat.completion.chunk","model":"gpt-4o-mini-2024-07-18","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]} + modelName := os.Getenv("CODEX_API_MODEL_NAME") + template := `data: {"id":"f6202f6f-9d13-4518-b34f-65e945b0a1a2","object":"chat.completion.chunk","model":"%s","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]} -data: {"id":"b2ab39cb-9a84-4006-b470-93a5965c6d69","object":"chat.completion.chunk","model":"gpt-4o-mini-2024-07-18","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]} +data: {"id":"b2ab39cb-9a84-4006-b470-93a5965c6d69","object":"chat.completion.chunk","model":"%s","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]} -data: {"id":"df5f9ce7-b653-4ffb-8d92-e21856ce1ffc","object":"chat.completion.chunk","model":"gpt-4o-mini-2024-07-18","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":"Explain"},"finish_reason":null}]} +data: {"id":"df5f9ce7-b653-4ffb-8d92-e21856ce1ffc","object":"chat.completion.chunk","model":"%s","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":"Explain"},"finish_reason":null}]} -data: {"id":"fb58d66e-bb16-43f2-8470-2de0c8662533","object":"chat.completion.chunk","model":"gpt-4o-mini-2024-07-18","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]} +data: {"id":"fb58d66e-bb16-43f2-8470-2de0c8662533","object":"chat.completion.chunk","model":"%s","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]} -data: {"id":"22ea16e2-766f-4b10-84d0-68399abc9181","object":"chat.completion.chunk","model":"gpt-4o-mini-2024-07-18","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]} +data: {"id":"22ea16e2-766f-4b10-84d0-68399abc9181","object":"chat.completion.chunk","model":"%s","created":1734752124,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]} data: [DONE] ` - _, _ = c.Writer.WriteString(fixedOutput) + formattedOutput := fmt.Sprintf(template, modelName, modelName, modelName, modelName, modelName) + _, _ = c.Writer.WriteString(formattedOutput) c.Writer.Flush() }