OpenAI

All about OpenAI.
package main

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

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

func main() {
	openai, err := llm.NewOpenAI(os.Getenv("OPENAI_API_KEY"), func(o *llm.OpenAIOptions) {
		o.Temperature = 0.2 // optional
	})
	if err != nil {
		log.Fatal(err)
	}

	pv := prompt.StringPromptValue("What year was Einstein born?")

	result, err := model.GeneratePrompt(context.Background(), openai, pv)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.Generations[0].Text) // Output: Einstein was born in 1879.
}

Streaming

package main

import (
	"context"
	"log"
	"os"

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

func main() {
	openai, err := llm.NewOpenAI(os.Getenv("OPENAI_API_KEY"), func(o *llm.OpenAIOptions) {
		o.MaxTokens = 256
		o.Stream = true
		o.Callbacks = []schema.Callback{callback.NewStreamWriterHandler()}
	})
	if err != nil {
		log.Fatal(err)
	}

	if _, err := model.GeneratePrompt(context.Background(), openai, prompt.StringPromptValue("Write me a song about sparkling water.")); err != nil {
		log.Fatal(err)
	}
}
Output:
```text
Verse 1:
There's a little sparkle...
Last modified December 21, 2023: Update docs (17b4336)