Skip to content

Commit

Permalink
examples: Update openai chat example
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Jan 23, 2024
1 parent 61b3cda commit 309b766
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions examples/openai-chat-example/openai_chat_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,33 @@ import (
)

func main() {
llm, err := openai.NewChat()
llm, err := openai.New()
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
completion, err := llm.Call(ctx, []schema.ChatMessage{
schema.SystemChatMessage{Content: "Hello, I am a friendly chatbot. I love to talk about movies, books and music. Answer in long form yaml."},
schema.HumanChatMessage{Content: "What would be a good company name a company that makes colorful socks?"},
_, err = llm.GenerateContent(ctx, []llms.MessageContent{
{
Role: schema.ChatMessageTypeSystem,
Parts: []llms.ContentPart{
llms.TextContent{
Text: "Hello, I am a friendly chatbot. I love to talk about movies, books and music. Answer in long form yaml.",
},
},
},
{
Role: schema.ChatMessageTypeHuman,
Parts: []llms.ContentPart{
llms.TextContent{
Text: "What would be a good company name a company that makes colorful socks?",
},
},
},
}, llms.WithStreamingFunc(func(ctx context.Context, chunk []byte) error {
fmt.Print(string(chunk))
return nil
}),
)
}))
if err != nil {
log.Fatal(err)
}

fmt.Println(completion)
}

0 comments on commit 309b766

Please sign in to comment.