38 lines
656 B
Go
38 lines
656 B
Go
![]() |
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
|
||
|
"github.com/jmorganca/ollama/api"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
client, err := api.ClientFromEnvironment()
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
req := &api.GenerateRequest{
|
||
|
Model: "gemma",
|
||
|
Prompt: "how many planets are there?",
|
||
|
|
||
|
// set streaming to false
|
||
|
Stream: new(bool),
|
||
|
}
|
||
|
|
||
|
ctx := context.Background()
|
||
|
respFunc := func(resp api.GenerateResponse) error {
|
||
|
// Only print the response here; GenerateResponse has a number of other
|
||
|
// interesting fields you want to examine.
|
||
|
fmt.Println(resp.Response)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
err = client.Generate(ctx, req, respFunc)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}
|