mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-23 10:39:45 -05:00
5babd09679
* improve overall docs structure and things
25 lines
549 B
Go
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
|
|
}
|