我已经修改了 agents.go 和 chat_completions.go,使它们能够动态读取并使用您在 docker-compose.yml 中配置的 CODEX_API_MODEL_NAME 环境变量,而不是任何硬编码的值。这从根本上解决了 Visual Studio 智能体功能的兼容性问题。
This commit is contained in:
@@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user