✨Feat: 适配多个智能体
This commit is contained in:
+24
-1
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/tmc/langchaingo/llms"
|
||||
"github.com/tmc/langchaingo/prompts"
|
||||
)
|
||||
|
||||
func Call(llm llms.Model, ctx context.Context) (response string) {
|
||||
@@ -29,7 +31,7 @@ func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (respon
|
||||
response, err := llms.GenerateFromSinglePrompt(
|
||||
ctx,
|
||||
llm,
|
||||
prompt,
|
||||
"用户正在学习Go语言,你是用户的助手。\n"+prompt,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -40,3 +42,24 @@ func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (respon
|
||||
return response
|
||||
|
||||
}
|
||||
func CallWithAgent(llm llms.Model, ctx context.Context, topic string, promptPath string) (response string) {
|
||||
content, err := os.ReadFile(promptPath)
|
||||
if err != nil {
|
||||
fmt.Printf("File err: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
text := string(content)
|
||||
|
||||
template := prompts.NewPromptTemplate(text, []string{".Knowledge"})
|
||||
prompt, err := template.Format(map[string]any{
|
||||
"Knowledge": topic,
|
||||
})
|
||||
|
||||
fmt.Println("Me: ", prompt)
|
||||
if err != nil {
|
||||
fmt.Errorf("Error: %v", err)
|
||||
}
|
||||
response = CallWithMessage(llm, ctx, prompt)
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user