2024-04-15 22:34:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/ollama/ollama/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
client, err := api.ClientFromEnvironment()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
messages := []api.Message{
|
|
|
|
api.Message{
|
|
|
|
Role: "system",
|
|
|
|
Content: "Provide very brief, concise responses",
|
|
|
|
},
|
|
|
|
api.Message{
|
|
|
|
Role: "user",
|
|
|
|
Content: "Name some unusual animals",
|
|
|
|
},
|
|
|
|
api.Message{
|
|
|
|
Role: "assistant",
|
|
|
|
Content: "Monotreme, platypus, echidna",
|
|
|
|
},
|
|
|
|
api.Message{
|
|
|
|
Role: "user",
|
|
|
|
Content: "which of these is the most dangerous?",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
req := &api.ChatRequest{
|
2024-05-03 19:25:04 +00:00
|
|
|
Model: "llama3",
|
2024-04-15 22:34:54 +00:00
|
|
|
Messages: messages,
|
|
|
|
}
|
|
|
|
|
|
|
|
respFunc := func(resp api.ChatResponse) error {
|
|
|
|
fmt.Print(resp.Message.Content)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.Chat(ctx, req, respFunc)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|