51 lines
995 B
Go
51 lines
995 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/tmc/langchaingo/llms"
|
|
"github.com/tmc/langchaingo/llms/openai"
|
|
)
|
|
|
|
func main() {
|
|
apiKey := "sk-angtzujyplaqsrxvlxkmjahpyxwnhhaonnfamokggxclmdlv"
|
|
baseUrl := "https://api.siliconflow.cn/v1"
|
|
|
|
//baseUrl := "https://api.siliconflow.cn/v1/chat/completions"
|
|
model := "Pro/deepseek-ai/DeepSeek-V3.2"
|
|
|
|
if apiKey == "" {
|
|
log.Fatal("apiKey is empty")
|
|
}
|
|
|
|
llm, err := openai.New(
|
|
openai.WithToken(apiKey),
|
|
openai.WithBaseURL(baseUrl),
|
|
)
|
|
|
|
if err != nil {
|
|
log.Fatalf("初始化失败: %v\nAPI Key: %s\nBase URL: %s", err, apiKey, baseUrl)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
prompt := "哟什么风把您给吹来了"
|
|
|
|
message := []llms.MessageContent{
|
|
llms.TextParts(llms.ChatMessageTypeHuman, prompt),
|
|
}
|
|
|
|
response, err := llm.GenerateContent(ctx, message,
|
|
llms.WithModel(model),
|
|
)
|
|
|
|
if err != nil {
|
|
log.Fatalf("调用失败: %v\n模型: %s", err, model)
|
|
}
|
|
|
|
fmt.Println("模型响应:", response.Choices[0].Content)
|
|
|
|
}
|