-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (51 loc) · 1.16 KB
/
Copy pathmain.go
File metadata and controls
59 lines (51 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"fmt"
"os"
"github.com/zeiss/prompts"
"github.com/zeiss/prompts/ollama"
)
// This example demonstrates how to create a completion request with a message
// It then sends the request to the API and prints the last completion content.
func main() {
client := prompts.NewClient(os.Getenv("OLLAMA_URL"))
provider := ollama.New(client)
msgs := []prompts.Input{
{
Role: prompts.RoleSystem,
Content: []prompts.MessageContent{
{
Content: prompts.MessageContentText{
Text: "You are a helpful assistant. You answer questions to the best of your ability.",
},
},
},
},
{
Role: prompts.RoleUser,
Content: []prompts.MessageContent{
{
Content: prompts.MessageContentText{
Text: "What is the definition of Pi?",
},
},
},
},
}
stream := prompts.NewCompletionEventStream()
go func() {
for event := range stream {
fmt.Println(event.Type)
}
}()
prompt := prompts.NewPrompt(
prompts.WithModel(ollama.DefaultModel),
prompts.WithInput(msgs...),
prompts.WithStream(),
)
err := provider.AsStream(context.Background(), prompt, stream)
if err != nil {
panic(err)
}
}