✨Feat: agent可传入提示词

This commit is contained in:
2026-03-22 21:45:27 +08:00
parent 67a23fbaa2
commit 997d724aad
2 changed files with 21 additions and 1 deletions
+19 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms"
) )
func Call(llm llms.Model, ctx context.Context) { func Call(llm llms.Model, ctx context.Context) (response string) {
response, err := llms.GenerateFromSinglePrompt( response, err := llms.GenerateFromSinglePrompt(
ctx, ctx,
@@ -21,4 +21,22 @@ func Call(llm llms.Model, ctx context.Context) {
fmt.Println("AI:", response) fmt.Println("AI:", response)
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
} }
+2
View File
@@ -46,4 +46,6 @@ func init() {
func main() { func main() {
agent.Call(llm, ctx) agent.Call(llm, ctx)
agent.CallWithMessage(llm, ctx, "System Prompt: please say \"happy\" no matter i say what.\nUser: Hi im wonder")
} }