diff --git a/ai_scheduler b/ai_scheduler deleted file mode 100644 index cdbe9a2..0000000 Binary files a/ai_scheduler and /dev/null differ diff --git a/config.yaml b/config.yaml index cfe1055..4b58254 100644 --- a/config.yaml +++ b/config.yaml @@ -4,7 +4,7 @@ server: ollama: base_url: "http://localhost:11434" - model: "qwen:8b" + model: "qwen3:8b" timeout: 30s tools: diff --git a/docs/docs.go b/docs/docs.go index 3ff2ba8..ca65d1c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,4 +1,4 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT +// Package docs Code generated by swaggo/swag. DO NOT EDIT package docs import "github.com/swaggo/swag" @@ -104,10 +104,6 @@ const docTemplate = `{ "message": { "type": "string", "example": "北京今天天气怎么样?" - }, - "model": { - "type": "string", - "example": "llama2" } } }, @@ -187,8 +183,10 @@ var SwaggerInfo = &swag.Spec{ Description: "智能路由调度系统API文档", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) -} \ No newline at end of file +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..d1ca333 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,168 @@ +{ + "swagger": "2.0", + "info": { + "description": "智能路由调度系统API文档", + "title": "AI Scheduler API", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "API Support", + "url": "http://www.swagger.io/support", + "email": "support@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0" + }, + "host": "localhost:8080", + "basePath": "/", + "paths": { + "/api/v1/chat": { + "post": { + "description": "发送消息给AI助手,支持工具调用", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "chat" + ], + "summary": "智能聊天", + "parameters": [ + { + "description": "聊天请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/handlers.ChatRequest" + } + } + ], + "responses": { + "200": { + "description": "聊天响应", + "schema": { + "$ref": "#/definitions/handlers.ChatResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/handlers.ErrorResponse" + } + }, + "500": { + "description": "服务器错误", + "schema": { + "$ref": "#/definitions/handlers.ErrorResponse" + } + } + } + } + }, + "/health": { + "get": { + "description": "检查服务是否正常运行", + "produces": [ + "application/json" + ], + "tags": [ + "system" + ], + "summary": "健康检查", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + } + }, + "definitions": { + "handlers.ChatRequest": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string", + "example": "北京今天天气怎么样?" + } + } + }, + "handlers.ChatResponse": { + "type": "object", + "properties": { + "finished": { + "type": "boolean", + "example": true + }, + "message": { + "type": "string", + "example": "北京今天天气晴朗,温度15.3°C" + }, + "tool_calls": { + "type": "array", + "items": { + "$ref": "#/definitions/handlers.ToolCallResponse" + } + } + } + }, + "handlers.ErrorResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "error": { + "type": "string", + "example": "Invalid request" + }, + "message": { + "type": "string", + "example": "请求参数错误" + } + } + }, + "handlers.FunctionCallResponse": { + "type": "object", + "properties": { + "arguments": {}, + "name": { + "type": "string", + "example": "get_weather" + } + } + }, + "handlers.ToolCallResponse": { + "type": "object", + "properties": { + "function": { + "$ref": "#/definitions/handlers.FunctionCallResponse" + }, + "id": { + "type": "string", + "example": "call_1" + }, + "result": {}, + "type": { + "type": "string", + "example": "function" + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..3fb3660 --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,114 @@ +basePath: / +definitions: + handlers.ChatRequest: + properties: + message: + example: 北京今天天气怎么样? + type: string + required: + - message + type: object + handlers.ChatResponse: + properties: + finished: + example: true + type: boolean + message: + example: 北京今天天气晴朗,温度15.3°C + type: string + tool_calls: + items: + $ref: '#/definitions/handlers.ToolCallResponse' + type: array + type: object + handlers.ErrorResponse: + properties: + code: + example: 400 + type: integer + error: + example: Invalid request + type: string + message: + example: 请求参数错误 + type: string + type: object + handlers.FunctionCallResponse: + properties: + arguments: {} + name: + example: get_weather + type: string + type: object + handlers.ToolCallResponse: + properties: + function: + $ref: '#/definitions/handlers.FunctionCallResponse' + id: + example: call_1 + type: string + result: {} + type: + example: function + type: string + type: object +host: localhost:8080 +info: + contact: + email: support@swagger.io + name: API Support + url: http://www.swagger.io/support + description: 智能路由调度系统API文档 + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + termsOfService: http://swagger.io/terms/ + title: AI Scheduler API + version: "1.0" +paths: + /api/v1/chat: + post: + consumes: + - application/json + description: 发送消息给AI助手,支持工具调用 + parameters: + - description: 聊天请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/handlers.ChatRequest' + produces: + - application/json + responses: + "200": + description: 聊天响应 + schema: + $ref: '#/definitions/handlers.ChatResponse' + "400": + description: 请求错误 + schema: + $ref: '#/definitions/handlers.ErrorResponse' + "500": + description: 服务器错误 + schema: + $ref: '#/definitions/handlers.ErrorResponse' + summary: 智能聊天 + tags: + - chat + /health: + get: + description: 检查服务是否正常运行 + produces: + - application/json + responses: + "200": + description: OK + schema: + additionalProperties: + type: string + type: object + summary: 健康检查 + tags: + - system +swagger: "2.0" diff --git a/go.mod b/go.mod index 1c8d91f..ba1f002 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/spf13/viper v1.17.0 github.com/swaggo/files v1.0.1 github.com/swaggo/gin-swagger v1.6.1 - github.com/swaggo/swag v1.8.12 + github.com/swaggo/swag v1.16.6 ) require ( @@ -57,7 +57,9 @@ require ( golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.36.0 // indirect golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect + golang.org/x/mod v0.23.0 // indirect golang.org/x/net v0.38.0 // indirect + golang.org/x/sync v0.12.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect golang.org/x/tools v0.30.0 // indirect diff --git a/go.sum b/go.sum index 50d8310..3394231 100644 --- a/go.sum +++ b/go.sum @@ -257,8 +257,8 @@ github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= github.com/swaggo/gin-swagger v1.6.1 h1:Ri06G4gc9N4t4k8hekMigJ9zKTFSlqj/9paAQCQs7cY= github.com/swaggo/gin-swagger v1.6.1/go.mod h1:LQ+hJStHakCWRiK/YNYtJOu4mR2FP+pxLnILT/qNiTw= -github.com/swaggo/swag v1.8.12 h1:pctzkNPu0AlQP2royqX3apjKCQonAnf7KGoxeO4y64w= -github.com/swaggo/swag v1.8.12/go.mod h1:lNfm6Gg+oAq3zRJQNEMBE66LIJKM44mxFqhEEgy2its= +github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI= +github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= diff --git a/internal/handlers/chat.go b/internal/handlers/chat.go index 773dc8c..fb5d2e1 100644 --- a/internal/handlers/chat.go +++ b/internal/handlers/chat.go @@ -22,22 +22,21 @@ func NewChatHandler(routerService types.RouterService) *ChatHandler { // ChatRequest HTTP聊天请求 type ChatRequest struct { Message string `json:"message" binding:"required" example:"北京今天天气怎么样?"` - Model string `json:"model,omitempty" example:"llama2"` } // ChatResponse HTTP聊天响应 type ChatResponse struct { - Message string `json:"message" example:"北京今天天气晴朗,温度15.3°C"` - ToolCalls []ToolCallResponse `json:"tool_calls,omitempty"` - Finished bool `json:"finished" example:"true"` + Message string `json:"message" example:"北京今天天气晴朗,温度15.3°C"` + ToolCalls []ToolCallResponse `json:"tool_calls,omitempty"` + Finished bool `json:"finished" example:"true"` } // ToolCallResponse 工具调用响应 type ToolCallResponse struct { - ID string `json:"id" example:"call_1"` - Type string `json:"type" example:"function"` + ID string `json:"id" example:"call_1"` + Type string `json:"type" example:"function"` Function FunctionCallResponse `json:"function"` - Result interface{} `json:"result,omitempty"` + Result interface{} `json:"result,omitempty"` } // FunctionCallResponse 函数调用响应 @@ -78,7 +77,6 @@ func (h *ChatHandler) Chat(c *gin.Context) { // 转换为服务层请求 serviceReq := &types.ChatRequest{ Message: req.Message, - Model: req.Model, } // 调用路由服务 @@ -126,7 +124,7 @@ func (h *ChatHandler) Chat(c *gin.Context) { // @Router /health [get] func (h *ChatHandler) Health(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ - "status": "ok", + "status": "ok", "service": "ai-scheduler", }) -} \ No newline at end of file +} diff --git a/server b/server deleted file mode 100644 index cdbe9a2..0000000 Binary files a/server and /dev/null differ