Cohere

All about Cohere.
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/hupe1980/golc/model"
	"github.com/hupe1980/golc/model/chatmodel"
	"github.com/hupe1980/golc/prompt"
)

func main() {
	cohere, err := chatmodel.NewCohere(os.Getenv("COHERE_API_KEY"), func(o *chatmodel.CohereOptions) {
		o.Temperature = 0.7 // optional
	})
	if err != nil {
		log.Fatal(err)
	}

	res, err := model.GeneratePrompt(context.Background(), cohere, prompt.StringPromptValue("How much cost the fish? A short answer please."))
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(res.Generations[0].Text)
}

Streaming

package main

import (
	"context"
	"log"
	"os"

	"github.com/hupe1980/golc/callback"
	"github.com/hupe1980/golc/model"
	"github.com/hupe1980/golc/model/chatmodel"
	"github.com/hupe1980/golc/prompt"
	"github.com/hupe1980/golc/schema"
)

func main() {
	cohere, err := chatmodel.NewCohere(os.Getenv("COHERE_API_KEY"), func(o *chatmodel.CohereOptions) {
		o.Callbacks = []schema.Callback{callback.NewStreamWriterHandler()}
		o.Stream = true
	})
	if err != nil {
		log.Fatal(err)
	}

	if _, err := model.GeneratePrompt(context.Background(), cohere, prompt.StringPromptValue("Write me a song about sparkling water.")); err != nil {
		log.Fatal(err)
	}
}
Last modified December 21, 2023: Update docs (e92768b)