2026-03-22 21:25:36 +08:00
|
|
|
package agent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
|
|
|
|
|
"github.com/tmc/langchaingo/llms"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-22 21:45:27 +08:00
|
|
|
func Call(llm llms.Model, ctx context.Context) (response string) {
|
2026-03-22 21:25:36 +08:00
|
|
|
|
|
|
|
|
response, err := llms.GenerateFromSinglePrompt(
|
|
|
|
|
ctx,
|
|
|
|
|
llm,
|
|
|
|
|
"Hello! My name is wonder!",
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("AI:", response)
|
|
|
|
|
|
2026-03-22 21:45:27 +08:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (response string) {
|
|
|
|
|
|
|
|
|
|
response, err := llms.GenerateFromSinglePrompt(
|
|
|
|
|
ctx,
|
|
|
|
|
llm,
|
|
|
|
|
prompt,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("AI:", response)
|
|
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
2026-03-22 21:25:36 +08:00
|
|
|
}
|