Files
hatchet/examples/go/guides/integrations/embedding_openai.go
Gabe Ruttner 5babd09679 docs: chunky overhaul (#3129)
* improve overall docs structure and things
2026-03-04 14:33:15 -08:00

25 lines
549 B
Go

// Third-party integration - requires: go get github.com/sashabaranov/go-openai
// See: /guides/rag-and-indexing
package integrations
import (
"context"
"os"
"github.com/sashabaranov/go-openai"
)
// > OpenAI embedding usage
func Embed(ctx context.Context, text string) ([]float32, error) {
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
resp, err := client.CreateEmbeddings(ctx, openai.EmbeddingRequest{
Model: openai.AdaEmbeddingV2,
Input: text,
})
if err != nil {
return nil, err
}
return resp.Data[0].Embedding, nil
}