更新
This commit is contained in:
@@ -34,8 +34,8 @@ func NewClient(baseURL, apiKey string) *Client {
|
|||||||
|
|
||||||
// CommonResponse 通用响应结构
|
// CommonResponse 通用响应结构
|
||||||
type CommonResponse struct {
|
type CommonResponse struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Data interface{} `json:"data,omitempty"`
|
Data interface{} `json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ func (c *Client) request(ctx context.Context, method, path string, body interfac
|
|||||||
return fmt.Errorf("http request failed with status: %d", resp.StatusCode)
|
return fmt.Errorf("http request failed with status: %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
respBody, err := resp.ReadAll()
|
respBody := resp.ReadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("read response body failed: %w", err)
|
return fmt.Errorf("read response body failed: %w", err)
|
||||||
}
|
}
|
||||||
@@ -106,4 +106,3 @@ func buildQueryString(params map[string]interface{}) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(parts, "&")
|
return strings.Join(parts, "&")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ import (
|
|||||||
|
|
||||||
// ChatCompletionMessage OpenAI 格式的消息
|
// ChatCompletionMessage OpenAI 格式的消息
|
||||||
type ChatCompletionMessage struct {
|
type ChatCompletionMessage struct {
|
||||||
Role string `json:"role"` // "user", "assistant", "system"
|
Role string `json:"role"` // "user", "assistant", "system"
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChatCompletionRequest OpenAI 格式的聊天补全请求
|
// ChatCompletionRequest OpenAI 格式的聊天补全请求
|
||||||
type ChatCompletionRequest struct {
|
type ChatCompletionRequest struct {
|
||||||
Model string `json:"model"` // 模型名称(服务器会自动解析,可设置为任意值)
|
Model string `json:"model"` // 模型名称(服务器会自动解析,可设置为任意值)
|
||||||
Messages []ChatCompletionMessage `json:"messages"` // 消息列表,必须至少包含一条 user 消息
|
Messages []ChatCompletionMessage `json:"messages"` // 消息列表,必须至少包含一条 user 消息
|
||||||
Stream bool `json:"stream,omitempty"` // 是否流式返回,默认 false
|
Stream bool `json:"stream,omitempty"` // 是否流式返回,默认 false
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChatCompletionResponse OpenAI 格式的聊天补全响应(非流式)
|
// ChatCompletionResponse OpenAI 格式的聊天补全响应(非流式)
|
||||||
@@ -29,9 +29,9 @@ type ChatCompletionResponse struct {
|
|||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Choices []struct {
|
Choices []struct {
|
||||||
Index int `json:"index"`
|
Index int `json:"index"`
|
||||||
Message ChatCompletionMessage `json:"message"`
|
Message ChatCompletionMessage `json:"message"`
|
||||||
FinishReason string `json:"finish_reason"`
|
FinishReason string `json:"finish_reason"`
|
||||||
} `json:"choices"`
|
} `json:"choices"`
|
||||||
Usage struct {
|
Usage struct {
|
||||||
PromptTokens int `json:"prompt_tokens"`
|
PromptTokens int `json:"prompt_tokens"`
|
||||||
@@ -47,8 +47,8 @@ type ChatCompletionChunk struct {
|
|||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Choices []struct {
|
Choices []struct {
|
||||||
Index int `json:"index"`
|
Index int `json:"index"`
|
||||||
Delta struct {
|
Delta struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
} `json:"delta"`
|
} `json:"delta"`
|
||||||
@@ -91,7 +91,7 @@ func (c *Client) CreateAgentCompletion(ctx context.Context, agentID string, req
|
|||||||
// 注意:流式响应需要特殊处理,这里返回一个可用于读取流的接口
|
// 注意:流式响应需要特殊处理,这里返回一个可用于读取流的接口
|
||||||
func (c *Client) CreateChatCompletionStream(ctx context.Context, chatID string, req *ChatCompletionRequest) (*StreamReader, error) {
|
func (c *Client) CreateChatCompletionStream(ctx context.Context, chatID string, req *ChatCompletionRequest) (*StreamReader, error) {
|
||||||
req.Stream = true
|
req.Stream = true
|
||||||
apiPath := fmt.Sprintf("/api/v1/chats_openai/%s/chat/completions", chatID)
|
_ = fmt.Sprintf("/api/v1/chats_openai/%s/chat/completions", chatID)
|
||||||
|
|
||||||
// TODO: 实现流式读取逻辑
|
// TODO: 实现流式读取逻辑
|
||||||
return nil, fmt.Errorf("stream mode not implemented yet")
|
return nil, fmt.Errorf("stream mode not implemented yet")
|
||||||
@@ -119,4 +119,3 @@ func (sr *StreamReader) Close() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user