38 lines
926 B
Go
38 lines
926 B
Go
package main
|
|
|
|
import (
|
|
"github.com/ssgo/httpclient"
|
|
"github.com/ssgo/log"
|
|
"time"
|
|
)
|
|
|
|
type Ans struct {
|
|
Choices []struct {
|
|
Message struct {
|
|
Content string
|
|
}
|
|
}
|
|
}
|
|
|
|
func ask(text string) string {
|
|
log.DefaultLogger.Info("start ask", "text", text)
|
|
ansR := httpclient.GetClient(time.Second*60).Post("https://api.ppinfra.com/v3/openai/chat/completions", map[string]any{
|
|
"model": "deepseek/deepseek-r1/community",
|
|
"messages": []map[string]any{
|
|
{
|
|
"role": "user",
|
|
"content": text,
|
|
},
|
|
},
|
|
"response_format": map[string]any{"type": "text"},
|
|
//Bearer后面写ppinfra的apikey
|
|
}, "Content-Type", "application/json", "Authorization", "Bearer sk_siUuVF2utu9Mg0-LM5aM1KteXNQand33myY2iTq7Pcw")
|
|
if err := ansR.Error; err != nil {
|
|
log.DefaultLogger.Error("ask error", "err", err)
|
|
}
|
|
ans := Ans{}
|
|
ansR.To(&ans)
|
|
log.DefaultLogger.Info("ask stopped", "ans", ans)
|
|
return ans.Choices[0].Message.Content
|
|
}
|