feat 存档

This commit is contained in:
2026-03-21 20:21:37 +08:00
parent 21965ef95e
commit 86c63292b2
39 changed files with 8881 additions and 51 deletions

View File

@@ -18,18 +18,21 @@ func NewAIClient(enableSearch bool, searchStrategy string, temperature float32)
}
}
func (c *Client) RequestAI(pre string, prompt []string, cb func(content string, i int) error) error {
func (c *Client) RequestAI(pre []string, prompt []string, cb func(content string, i int) error) ([]Message, error) {
inToken, outToken := int32(0), int32(0)
messages := []Message{{
Role: "user",
Content: pre,
}}
messages := make([]Message, 0)
for _, s := range pre {
messages = append(messages, Message{
Role: "user",
Content: s,
})
}
for i, step := range prompt {
messages = append(messages, Message{
Role: "user",
Content: step,
})
r, err := request("qwen3-max", Parameters{
r, err := request("qwen-plus", Parameters{
//r, err := request("deepseek-v3.2", Parameters{
EnableSearch: c.enableSearch,
SearchOptions: SearchOptions{
@@ -39,21 +42,21 @@ func (c *Client) RequestAI(pre string, prompt []string, cb func(content string,
Temperature: c.temperature,
}, messages)
if err != nil {
return err
return nil, err
}
inToken += r.Usage.InputTokens
outToken += r.Usage.OutputTokens
if len(r.Output.Choices) == 0 {
fmt.Printf("AI response err, r: %#+v\n", r)
return err
fmt.Printf("AI response err: %+v\n", r)
return nil, err
} else {
messages = append(messages, r.Output.Choices[0].Message)
}
fmt.Printf("AI 回答 %v: %v\n", i, r.Output.Choices[0].Message.Content)
if err = cb(r.Output.Choices[0].Message.Content, i); err != nil {
return err
return nil, err
}
}
fmt.Printf("AI finished, use token: in-%v out-%v\n", inToken, outToken)
return nil
return messages, nil
}

View File

@@ -30,14 +30,19 @@ type SearchOptions struct {
type RequestBody struct {
Model string `json:"model"`
Input Input `json:"input"`
Parameters Parameters `json:"parameters"`
Parameters Parameters `json:"parameters,omitempty"`
}
type ResponseBody struct {
Output struct {
Choices []struct {
Message Message `json:"message"`
StatusCode string `json:"status_code"`
RequestID string `json:"request_id"`
Code string `json:"code"`
Output struct {
Text string `json:"text"`
FinishReason string `json:"finish_reason"`
Choices []struct {
FinishReason string `json:"finish_reason"`
Message Message `json:"message"`
} `json:"choices"`
} `json:"output"`
Usage struct {