♻️Refactor: 解耦chatAgent调用
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tmc/langchaingo/llms"
|
||||
)
|
||||
|
||||
func Call(llm llms.Model, ctx context.Context) {
|
||||
|
||||
response, err := llms.GenerateFromSinglePrompt(
|
||||
ctx,
|
||||
llm,
|
||||
"Hello! My name is wonder!",
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("AI:", response)
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"agent/agent"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -15,6 +16,8 @@ var (
|
||||
apiKey string
|
||||
baseUrl string
|
||||
model = "stepfun-ai/Step-3.5-Flash"
|
||||
ctx context.Context
|
||||
llm llms.Model
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -26,10 +29,8 @@ func init() {
|
||||
baseUrl = os.Getenv("BASE_URL")
|
||||
fmt.Printf("API Key: %s\n", apiKey)
|
||||
fmt.Printf("Base URL: %s\n", baseUrl)
|
||||
}
|
||||
|
||||
func main() {
|
||||
llm, err := openai.New(
|
||||
llm, err = openai.New(
|
||||
openai.WithBaseURL(baseUrl),
|
||||
openai.WithToken(apiKey),
|
||||
openai.WithModel(model),
|
||||
@@ -39,17 +40,10 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
response, err := llms.GenerateFromSinglePrompt(
|
||||
ctx,
|
||||
llm,
|
||||
"Hello! My name is wonder!",
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("AI:", response)
|
||||
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
agent.Call(llm, ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user