更新
This commit is contained in:
@@ -34,8 +34,8 @@ func NewClient(baseURL, apiKey string) *Client {
|
||||
|
||||
// CommonResponse 通用响应结构
|
||||
type CommonResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
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)
|
||||
}
|
||||
|
||||
respBody, err := resp.ReadAll()
|
||||
respBody := resp.ReadAll()
|
||||
if err != nil {
|
||||
return fmt.Errorf("read response body failed: %w", err)
|
||||
}
|
||||
@@ -106,4 +106,3 @@ func buildQueryString(params map[string]interface{}) string {
|
||||
}
|
||||
return strings.Join(parts, "&")
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,15 @@ import (
|
||||
|
||||
// ChatCompletionMessage OpenAI 格式的消息
|
||||
type ChatCompletionMessage struct {
|
||||
Role string `json:"role"` // "user", "assistant", "system"
|
||||
Role string `json:"role"` // "user", "assistant", "system"
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// ChatCompletionRequest OpenAI 格式的聊天补全请求
|
||||
type ChatCompletionRequest struct {
|
||||
Model string `json:"model"` // 模型名称(服务器会自动解析,可设置为任意值)
|
||||
Messages []ChatCompletionMessage `json:"messages"` // 消息列表,必须至少包含一条 user 消息
|
||||
Stream bool `json:"stream,omitempty"` // 是否流式返回,默认 false
|
||||
Model string `json:"model"` // 模型名称(服务器会自动解析,可设置为任意值)
|
||||
Messages []ChatCompletionMessage `json:"messages"` // 消息列表,必须至少包含一条 user 消息
|
||||
Stream bool `json:"stream,omitempty"` // 是否流式返回,默认 false
|
||||
}
|
||||
|
||||
// ChatCompletionResponse OpenAI 格式的聊天补全响应(非流式)
|
||||
@@ -29,9 +29,9 @@ type ChatCompletionResponse struct {
|
||||
Created int64 `json:"created"`
|
||||
Model string `json:"model"`
|
||||
Choices []struct {
|
||||
Index int `json:"index"`
|
||||
Index int `json:"index"`
|
||||
Message ChatCompletionMessage `json:"message"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
} `json:"choices"`
|
||||
Usage struct {
|
||||
PromptTokens int `json:"prompt_tokens"`
|
||||
@@ -47,8 +47,8 @@ type ChatCompletionChunk struct {
|
||||
Created int64 `json:"created"`
|
||||
Model string `json:"model"`
|
||||
Choices []struct {
|
||||
Index int `json:"index"`
|
||||
Delta struct {
|
||||
Index int `json:"index"`
|
||||
Delta struct {
|
||||
Content string `json:"content"`
|
||||
Role string `json:"role"`
|
||||
} `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) {
|
||||
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: 实现流式读取逻辑
|
||||
return nil, fmt.Errorf("stream mode not implemented yet")
|
||||
@@ -119,4 +119,3 @@ func (sr *StreamReader) Close() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user