feat: provider management & chat

This commit is contained in:
Acbox
2026-01-26 23:06:54 +08:00
parent 35a8927a79
commit da6a264699
28 changed files with 4699 additions and 63 deletions
+630 -2
View File
@@ -61,6 +61,98 @@ const docTemplate = `{
}
}
},
"/chat": {
"post": {
"description": "Send a chat message and get a response. The system will automatically select an appropriate chat model from the database.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"chat"
],
"summary": "Chat with AI",
"parameters": [
{
"description": "Chat request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/chat.ChatRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/chat.ChatResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/chat/stream": {
"post": {
"description": "Send a chat message and get a streaming response. The system will automatically select an appropriate chat model from the database.",
"consumes": [
"application/json"
],
"produces": [
"text/event-stream"
],
"tags": [
"chat"
],
"summary": "Stream chat with AI",
"parameters": [
{
"description": "Chat request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/chat.ChatRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/chat.StreamChunk"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/embeddings": {
"post": {
"description": "Create text or multimodal embeddings",
@@ -820,12 +912,20 @@ const docTemplate = `{
},
"/models/enable-as/{enableAs}": {
"get": {
"description": "Get the model that is enabled for a specific purpose (chat, memory, embedding)",
"description": "Get the model that is enabled for a specific purpose (chat, memory, embedding)\nGet the default model configured for a specific purpose (chat, memory, or embedding)",
"tags": [
"models",
"models"
],
"summary": "Get model by enable_as",
"summary": "Get default model by enable_as",
"parameters": [
{
"type": "string",
"description": "Enable as value (chat, memory, embedding)",
"name": "enableAs",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Enable as value (chat, memory, embedding)",
@@ -1129,9 +1229,434 @@ const docTemplate = `{
}
}
}
},
"/providers": {
"get": {
"description": "Get a list of all configured LLM providers, optionally filtered by client type",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "List all LLM providers",
"parameters": [
{
"type": "string",
"description": "Client type filter (openai, anthropic, google, ollama)",
"name": "client_type",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/providers.GetResponse"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new LLM provider configuration",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "Create a new LLM provider",
"parameters": [
{
"description": "Provider configuration",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/providers.CreateRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/providers.GetResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/providers/count": {
"get": {
"description": "Get the total count of providers, optionally filtered by client type",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "Count providers",
"parameters": [
{
"type": "string",
"description": "Client type filter (openai, anthropic, google, ollama)",
"name": "client_type",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/providers.CountResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/providers/name/{name}": {
"get": {
"description": "Get a provider configuration by its name",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "Get provider by name",
"parameters": [
{
"type": "string",
"description": "Provider name",
"name": "name",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/providers.GetResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/providers/{id}": {
"get": {
"description": "Get a provider configuration by its ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "Get provider by ID",
"parameters": [
{
"type": "string",
"description": "Provider ID (UUID)",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/providers.GetResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
},
"put": {
"description": "Update an existing provider configuration",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "Update provider",
"parameters": [
{
"type": "string",
"description": "Provider ID (UUID)",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Updated provider configuration",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/providers.UpdateRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/providers.GetResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
},
"delete": {
"description": "Delete a provider configuration",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"providers"
],
"summary": "Delete provider",
"parameters": [
{
"type": "string",
"description": "Provider ID (UUID)",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"chat.ChatRequest": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"$ref": "#/definitions/chat.Message"
}
},
"model": {
"description": "optional: specific model to use",
"type": "string"
},
"provider": {
"description": "optional: specific provider to use",
"type": "string"
},
"stream": {
"type": "boolean"
}
}
},
"chat.ChatResponse": {
"type": "object",
"properties": {
"finish_reason": {
"type": "string"
},
"message": {
"$ref": "#/definitions/chat.Message"
},
"model": {
"type": "string"
},
"provider": {
"type": "string"
},
"usage": {
"$ref": "#/definitions/chat.Usage"
}
}
},
"chat.Message": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"role": {
"description": "user, assistant, system",
"type": "string"
}
}
},
"chat.StreamChunk": {
"type": "object",
"properties": {
"delta": {
"type": "object",
"properties": {
"content": {
"type": "string"
}
}
},
"finish_reason": {
"type": "string"
},
"model": {
"type": "string"
},
"provider": {
"type": "string"
}
}
},
"chat.Usage": {
"type": "object",
"properties": {
"completion_tokens": {
"type": "integer"
},
"prompt_tokens": {
"type": "integer"
},
"total_tokens": {
"type": "integer"
}
}
},
"handlers.ApplyPatchRequest": {
"type": "object",
"properties": {
@@ -1714,6 +2239,109 @@ const docTemplate = `{
"$ref": "#/definitions/models.ModelType"
}
}
},
"providers.ClientType": {
"type": "string",
"enum": [
"openai",
"openai-compat",
"anthropic",
"google",
"ollama"
],
"x-enum-varnames": [
"ClientTypeOpenAI",
"ClientTypeOpenAICompat",
"ClientTypeAnthropic",
"ClientTypeGoogle",
"ClientTypeOllama"
]
},
"providers.CountResponse": {
"type": "object",
"properties": {
"count": {
"type": "integer"
}
}
},
"providers.CreateRequest": {
"type": "object",
"required": [
"base_url",
"client_type",
"name"
],
"properties": {
"api_key": {
"type": "string"
},
"base_url": {
"type": "string"
},
"client_type": {
"$ref": "#/definitions/providers.ClientType"
},
"metadata": {
"type": "object",
"additionalProperties": true
},
"name": {
"type": "string"
}
}
},
"providers.GetResponse": {
"type": "object",
"properties": {
"api_key": {
"description": "masked in response",
"type": "string"
},
"base_url": {
"type": "string"
},
"client_type": {
"type": "string"
},
"created_at": {
"type": "string"
},
"id": {
"type": "string"
},
"metadata": {
"type": "object",
"additionalProperties": true
},
"name": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
},
"providers.UpdateRequest": {
"type": "object",
"properties": {
"api_key": {
"type": "string"
},
"base_url": {
"type": "string"
},
"client_type": {
"$ref": "#/definitions/providers.ClientType"
},
"metadata": {
"type": "object",
"additionalProperties": true
},
"name": {
"type": "string"
}
}
}
}
}`