openai

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 21 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OpenAIDefaultAPIVersion = "2024-12-31"
	OpenAIDefaultMaxTokens  = 4096
)

Variables

This section is empty.

Functions

func ConvertAIChatToUIChat

func ConvertAIChatToUIChat(aiChat uctypes.AIChat) (*uctypes.UIChat, error)

ConvertAIChatToUIChat converts an AIChat to a UIChat for OpenAI

func UpdateToolUseData

func UpdateToolUseData(chatId string, callId string, newToolUseData *uctypes.UIMessageDataToolUse) error

Types

type OpenAIChatMessage

type OpenAIChatMessage struct {
	MessageId          string                         `json:"messageid"` // internal field for idempotency (cannot send to openai)
	Message            *OpenAIMessage                 `json:"message,omitempty"`
	FunctionCall       *OpenAIFunctionCallInput       `json:"functioncall,omitempty"`
	FunctionCallOutput *OpenAIFunctionCallOutputInput `json:"functioncalloutput,omitempty"`
	Usage              *OpenAIUsage
}

func ConvertAIMessageToOpenAIChatMessage

func ConvertAIMessageToOpenAIChatMessage(aiMsg uctypes.AIMessage) (*OpenAIChatMessage, error)

ConvertAIMessageToOpenAIChatMessage converts an AIMessage to OpenAIChatMessage These messages are ALWAYS role "user" Handles text parts, images, PDFs, and text/plain files

func ConvertToolResultsToOpenAIChatMessage

func ConvertToolResultsToOpenAIChatMessage(toolResults []uctypes.AIToolResult) ([]*OpenAIChatMessage, error)

ConvertToolResultsToOpenAIChatMessage converts AIToolResult slice to OpenAIChatMessage slice

func (*OpenAIChatMessage) GetMessageId

func (m *OpenAIChatMessage) GetMessageId() string

func (*OpenAIChatMessage) GetRole added in v0.12.4

func (m *OpenAIChatMessage) GetRole() string

func (*OpenAIChatMessage) GetUsage

func (m *OpenAIChatMessage) GetUsage() *uctypes.AIUsage

type OpenAIFunctionCallErrorOutput

type OpenAIFunctionCallErrorOutput struct {
	Ok    string `json:"ok"`
	Error string `json:"error"`
}

type OpenAIFunctionCallInput

type OpenAIFunctionCallInput struct {
	Type        string                        `json:"type"`                  // Required: The type of the function tool call. Always function_call
	CallId      string                        `json:"call_id"`               // Required: The unique ID of the function tool call generated by the model
	Name        string                        `json:"name"`                  // Required: The name of the function to run
	Arguments   string                        `json:"arguments"`             // Required: A JSON string of the arguments to pass to the function
	Status      string                        `json:"status,omitempty"`      // Optional: The status of the item. One of in_progress, completed, or incomplete
	ToolUseData *uctypes.UIMessageDataToolUse `json:"toolusedata,omitempty"` // Internal field for UI tool use data (must be cleaned before sending to API)

}

func GetFunctionCallInputByToolCallId added in v0.12.2

func GetFunctionCallInputByToolCallId(aiChat uctypes.AIChat, toolCallId string) *OpenAIFunctionCallInput

GetFunctionCallInputByToolCallId returns the OpenAIFunctionCallInput associated with the given ToolCallId, or nil if not found in the AIChat

type OpenAIFunctionCallOutputInput

type OpenAIFunctionCallOutputInput struct {
	Type   string      `json:"type"`    // Required: The type of the function tool call output. Always function_call_output
	CallId string      `json:"call_id"` // Required: The unique ID of the function tool call generated by the model
	Output interface{} `json:"output"`  // Required: Text, image, or file output of the function tool call

}

type OpenAIMessage

type OpenAIMessage struct {
	Role    string                 `json:"role"`
	Content []OpenAIMessageContent `json:"content"`
}

type OpenAIMessageContent

type OpenAIMessageContent struct {
	Type       string `json:"type"` // "input_text", "output_text", "input_image", "input_file", "function_call"
	Text       string `json:"text,omitempty"`
	ImageUrl   string `json:"image_url,omitempty"`
	PreviewUrl string `json:"previewurl,omitempty"` // internal field for 128x128 webp data url (cannot send to API)
	Filename   string `json:"filename,omitempty"`
	FileData   string `json:"file_data,omitempty"`

	// for Tools (type will be "function_call")
	Arguments any    `json:"arguments,omitempty"`
	CallId    string `json:"call_id,omitempty"`
	Name      string `json:"name,omitempty"`
}

type OpenAIRequest

type OpenAIRequest struct {
	Background         bool                `json:"background,omitempty"`
	Conversation       string              `json:"conversation,omitempty"`
	Include            []string            `json:"include,omitempty"`
	Input              []any               `json:"input,omitempty"` // either OpenAIMessage or OpenAIFunctionCallInput
	Instructions       string              `json:"instructions,omitempty"`
	MaxOutputTokens    int                 `json:"max_output_tokens,omitempty"`
	MaxToolCalls       int                 `json:"max_tool_calls,omitempty"`
	Metadata           map[string]string   `json:"metadata,omitempty"`
	Model              string              `json:"model,omitempty"`
	ParallelToolCalls  bool                `json:"parallel_tool_calls,omitempty"`
	PreviousResponseID string              `json:"previous_response_id,omitempty"`
	Prompt             *PromptType         `json:"prompt,omitempty"`
	PromptCacheKey     string              `json:"prompt_cache_key,omitempty"`
	Reasoning          *ReasoningType      `json:"reasoning,omitempty"`
	SafetyIdentifier   string              `json:"safety_identifier,omitempty"`
	ServiceTier        string              `json:"service_tier,omitempty"` // "auto", "default", "flex", "priority"
	Store              bool                `json:"store,omitempty"`
	Stream             bool                `json:"stream,omitempty"`
	StreamOptions      *StreamOptionsType  `json:"stream_options,omitempty"`
	Temperature        float64             `json:"temperature,omitempty"`
	Text               *TextType           `json:"text,omitempty"`
	ToolChoice         interface{}         `json:"tool_choice,omitempty"` // "none", "auto", "required", or object
	Tools              []OpenAIRequestTool `json:"tools,omitempty"`
	TopLogprobs        int                 `json:"top_logprobs,omitempty"`
	TopP               float64             `json:"top_p,omitempty"`
	Truncation         string              `json:"truncation,omitempty"` // "auto", "disabled"
}

type OpenAIRequestTool

type OpenAIRequestTool struct {
	Type        string `json:"type"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Parameters  any    `json:"parameters,omitempty"`
	Strict      bool   `json:"strict,omitempty"`
}

func ConvertToolDefinitionToOpenAI

func ConvertToolDefinitionToOpenAI(tool uctypes.ToolDefinition) OpenAIRequestTool

ConvertToolDefinitionToOpenAI converts a generic ToolDefinition to OpenAI format

type OpenAIUsage

type OpenAIUsage struct {
	InputTokens          int                        `json:"input_tokens,omitempty"`
	OutputTokens         int                        `json:"output_tokens,omitempty"`
	TotalTokens          int                        `json:"total_tokens,omitempty"`
	InputTokensDetails   *openaiInputTokensDetails  `json:"input_tokens_details,omitempty"`
	OutputTokensDetails  *openaiOutputTokensDetails `json:"output_tokens_details,omitempty"`
	Model                string                     `json:"model,omitempty"`                // internal field (not from OpenAI API)
	NativeWebSearchCount int                        `json:"nativewebsearchcount,omitempty"` // internal field (not from OpenAI API)
}

type PromptType

type PromptType struct {
	ID        string                 `json:"id"`
	Variables map[string]interface{} `json:"variables,omitempty"`
	Version   string                 `json:"version,omitempty"`
}

type ReasoningType

type ReasoningType struct {
	Effort  string `json:"effort,omitempty"`  // "minimal", "low", "medium", "high"
	Summary string `json:"summary,omitempty"` // "auto", "concise", "detailed"
}

type StreamOptionsType

type StreamOptionsType struct {
	IncludeObfuscation bool `json:"include_obfuscation"`
}

type TextType

type TextType struct {
	Format    interface{} `json:"format,omitempty"`    // Format object, e.g. {"type": "text"}, {"type": "json_object"}, {"type": "json_schema"}
	Verbosity string      `json:"verbosity,omitempty"` // "low", "medium", "high"
}

Jump to

Keyboard shortcuts

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