openai

package module
v0.0.0-...-b45b58b Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 24 Imported by: 0

README

OpenAI

The OpenAI provider for facades.AI() of Goravel.

Version

goravel/openai goravel/framework
v1.18.x v1.18.x

Install

Run the command below in your project to install the package automatically:

./artisan package:install github.com/goravel/openai

This registers the service provider and updates config/ai.go so ai.providers.openai.via resolves through openaifacades.OpenAI("openai").

Or check the setup file to install the package manually.

Custom Failover

The provider marks these OpenAI HTTP errors as failoverable by default:

Status Reason
429 Too Many Requests rate_limited
402 Payment Required insufficient_credits
503 Service Unavailable provider_overloaded

Configure failover rules to add OpenAI-specific error message mappings. Plain strings use substring matching, and slash-delimited strings use Go regular expressions.

"openai": map[string]any{
	"key": config.Env("OPENAI_API_KEY", ""),
	"failover": map[string][]string{
		"context_length_exceeded": {
			"maximum context length",
			"/(?i)context.*length/",
		},
	},
	"via": func() (ai.Provider, error) {
		return openaifacades.OpenAI("openai")
	},
}

Testing

Run command below to run all tests:

go test ./...

Run the live OpenAI smoke test with a real API key:

OPENAI_API_KEY=your-key go test -run '^TestProviderPromptIntegration$' -v ./...

The smoke test skips automatically when OPENAI_API_KEY is not set.

Documentation

Index

Constants

View Source
const (
	Binding = "goravel.openai"
	Name    = "OpenAI"
)
View Source
const DefaultAudioModel = "gpt-4o-mini-tts"
View Source
const DefaultDiarizedTranscriptionModel = "gpt-4o-transcribe-diarize"
View Source
const DefaultFemaleVoice = "alloy"
View Source
const DefaultImageModel = "gpt-image-2"
View Source
const DefaultMaleVoice = "ash"
View Source
const DefaultTextModel = "gpt-5.4"
View Source
const DefaultTranscriptionModel = "gpt-4o-mini-transcribe"

Variables

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

func NewOpenAI

func NewOpenAI(config contractsconfig.Config, provider string) (*Provider, error)

func (*Provider) Audio

func (*Provider) DeleteFile

func (r *Provider) DeleteFile(ctx context.Context, id string) error

func (*Provider) GetFile

func (r *Provider) GetFile(ctx context.Context, id string) (contractsai.FileResponse, error)

func (*Provider) Image

func (*Provider) Prompt

func (*Provider) PutFile

func (*Provider) Stream

type ServiceProvider

type ServiceProvider struct{}

func (*ServiceProvider) Boot

func (r *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (r *ServiceProvider) Register(app foundation.Application)

func (*ServiceProvider) Relationship

func (r *ServiceProvider) Relationship() binding.Relationship

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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