✨Feat: 前端项目初始化
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package agent
|
||||
|
||||
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) {
|
||||
|
||||
response, err := llms.GenerateFromSinglePrompt(
|
||||
ctx,
|
||||
llm,
|
||||
"Hello! My name is wonder!",
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("AI:", response)
|
||||
|
||||
return response
|
||||
|
||||
}
|
||||
func CallWithMessage(llm llms.Model, ctx context.Context, prompt string) (response string) {
|
||||
|
||||
response, err := llms.GenerateFromSinglePrompt(
|
||||
ctx,
|
||||
llm,
|
||||
"用户正在学习Go语言,你是用户的助手。\n"+prompt,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("AI:", response)
|
||||
|
||||
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.Printf("Prompt err: %v", err)
|
||||
}
|
||||
response = CallWithMessage(llm, ctx, prompt)
|
||||
return response
|
||||
}
|
||||
Reference in New Issue
Block a user