Files
langchain-go/main.go
T
2026-03-22 21:25:36 +08:00

50 lines
765 B
Go

package main
import (
"agent/agent"
"context"
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
var (
apiKey string
baseUrl string
model = "stepfun-ai/Step-3.5-Flash"
ctx context.Context
llm llms.Model
)
func init() {
err := godotenv.Load()
if err != nil {
fmt.Println(".env 文件加载失败")
}
apiKey = os.Getenv("API_KEY")
baseUrl = os.Getenv("BASE_URL")
fmt.Printf("API Key: %s\n", apiKey)
fmt.Printf("Base URL: %s\n", baseUrl)
llm, err = openai.New(
openai.WithBaseURL(baseUrl),
openai.WithToken(apiKey),
openai.WithModel(model),
)
if err != nil {
log.Fatal(err)
}
ctx = context.Background()
}
func main() {
agent.Call(llm, ctx)
}