Files
co-chat/cmd/single/main.go
T

51 lines
995 B
Go
Raw Normal View History

2026-02-28 10:23:32 +08:00
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)
}