openai

package
v0.0.0-...-e2a9449 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpenAIOCRAPIRequestTimeout = time.Duration(env.GetIntFromEnvOrDefault("KNOW_OPENAI_OCR_API_REQUEST_TIMEOUT_SECONDS", defaults.ModelAPIRequestTimeoutSeconds)) * time.Second
View Source
var OpenAIOCRAPITimeout = time.Duration(env.GetIntFromEnvOrDefault("KNOW_OPENAI_OCR_API_TIMEOUT_SECONDS", defaults.ModelAPITimeoutSeconds)) * time.Second

Functions

func EncodeImageToBase64

func EncodeImageToBase64(img image.Image) (string, error)

Types

type Choice

type Choice struct {
	FinishReason string      `json:"finish_reason"`
	Message      RespMessage `json:"message"` // e.g. OpenAI provider resp
	Delta        RespMessage `json:"delta"`   // e.g. Anthropic/Claude provider StreamResponse
}

type ImagePayload

type ImagePayload struct {
	URL string `json:"url,omitempty"`
}

type Message

type Message struct {
	Role    string           `json:"role"`
	Content []MessageContent `json:"content"`
}

type MessageContent

type MessageContent struct {
	Type     string        `json:"type"`
	Text     string        `json:"text,omitempty"`
	ImageURL *ImagePayload `json:"image_url,omitempty"`
}

type OpenAIOCR

type OpenAIOCR struct {
	openai.OpenAIConfig `mapstructure:",squash"`
	Prompt              string
	MaxTokens           *int
	Concurrency         int
}

func (*OpenAIOCR) Configure

func (o *OpenAIOCR) Configure() error

func (*OpenAIOCR) Load

func (o *OpenAIOCR) Load(ctx context.Context, reader io.Reader) ([]vs.Document, error)

func (*OpenAIOCR) SendImageToOpenAI

func (o *OpenAIOCR) SendImageToOpenAI(ctx context.Context, base64Image string) (string, error)

type Payload

type Payload struct {
	Model     string    `json:"model"`
	Messages  []Message `json:"messages"`
	MaxTokens int       `json:"max_tokens"`
}

type RespMessage

type RespMessage struct {
	Content string `json:"content"`
}

type Response

type Response struct {
	Choices []Choice `json:"choices"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL