Skip to content

Instantly share code, notes, and snippets.

@Struki84
Created September 19, 2023 17:08
Show Gist options
  • Save Struki84/e61b532b1163fc1c4ae1b2d1cea42645 to your computer and use it in GitHub Desktop.
Save Struki84/e61b532b1163fc1c4ae1b2d1cea42645 to your computer and use it in GitHub Desktop.
func Prompt(input string, options ...chains.ChainCallOption) {
llm, err := openai.NewChat(openai.WithModel("gpt-4"))
if err != nil {
log.Fatal(err)
}
// dsn := "host=localhost user=gpt-admin password=gpt-password dbname=gpt-db port=5432"
// memory := memory.NewPostgreBuffer(dsn)
// memory.SetSession("USID-001")
ctx := context.Background()
search, err := duckduckgo.New(5, "")
if err != nil {
log.Fatal(err)
}
agentTools := []tools.Tool{search}
// executor, err := agents.Initialize(
// llm,
// agentTools,
// agents.ConversationalReactDescription,
// agents.WithMemory(memory),
// agents.WithReturnIntermediateSteps(), // This throws an error
// )
executor, err := agents.Initialize(
llm,
agentTools,
agents.ConversationalReactDescription,
)
if err != nil {
log.Fatal(err)
}
response, err := chains.Run(
ctx,
executor,
input,
chains.WithStreamingFunc(func(ctx context.Context, chunk []byte) error {
fmt.Print(string(chunk))
return nil
}),
)
fmt.Println(response)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment