chatopenai

package
v2.34.9 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearPreviousResponseID

func ClearPreviousResponseID(providerOptions fantasy.ProviderOptions) fantasy.ProviderOptions

ClearPreviousResponseID returns a clone of providerOptions with PreviousResponseID cleared on the OpenAI Responses options. The original providerOptions is not modified.

func EnsureResponseIncludes

func EnsureResponseIncludes(
	values []fantasyopenai.IncludeType,
) []fantasyopenai.IncludeType

EnsureResponseIncludes adds the OpenAI encrypted reasoning include required for Responses API reasoning continuity when it is not already present.

func ExtractResponseIDIfStored

func ExtractResponseIDIfStored(
	providerOptions fantasy.ProviderOptions,
	metadata fantasy.ProviderMetadata,
) string

ExtractResponseIDIfStored returns the OpenAI response ID only when the provider options indicate store=true. Response IDs from store=false turns are not persisted server-side and cannot be used for chaining.

func FilterPromptForChainMode

func FilterPromptForChainMode(
	prompt []fantasy.Message,
	info ChainModeInfo,
) []fantasy.Message

FilterPromptForChainMode keeps only system messages and the trailing user messages that still contribute model-visible content to the current turn. Assistant and tool messages are dropped because the provider already has them via the previous_response_id chain.

func HasPreviousResponseID

func HasPreviousResponseID(providerOptions fantasy.ProviderOptions) bool

HasPreviousResponseID checks whether the provider options contain an OpenAI Responses entry with a non-empty PreviousResponseID.

func IncludeFromChat

func IncludeFromChat(values []string) []fantasyopenai.IncludeType

IncludeFromChat converts chat-config include values to OpenAI Responses include values and ignores unsupported entries.

func IsReasoningModel

func IsReasoningModel(modelID string) bool

IsReasoningModel reports whether a model ID follows OpenAI reasoning model naming conventions.

func IsResponsesStoreEnabled

func IsResponsesStoreEnabled(opts fantasy.ProviderOptions) bool

IsResponsesStoreEnabled checks if the OpenAI Responses provider options are present and have Store set to true. When true, the provider stores conversation history server-side, enabling follow-up chaining via PreviousResponseID.

func ProviderOptionsFromChatConfig

func ProviderOptionsFromChatConfig(
	model fantasy.LanguageModel,
	options *codersdk.ChatModelOpenAIProviderOptions,
) fantasy.ProviderOptionsData

ProviderOptionsFromChatConfig converts chat model OpenAI options to fantasy provider options used for inference calls.

func ReasoningEffortFromChat

func ReasoningEffortFromChat(value *string) *fantasyopenai.ReasoningEffort

ReasoningEffortFromChat normalizes chat-config reasoning effort values for OpenAI and returns the canonical provider effort value.

func ResponsesLogProbsFromChatConfig

func ResponsesLogProbsFromChatConfig(
	options *codersdk.ChatModelOpenAIProviderOptions,
) any

ResponsesLogProbsFromChatConfig maps chat-config log probability options to the value expected by OpenAI Responses provider options.

func ServiceTierFromChat

func ServiceTierFromChat(value *string) *fantasyopenai.ServiceTier

ServiceTierFromChat normalizes chat-config service tier values for OpenAI Responses API and returns the canonical provider service tier value.

func ShouldActivateChainMode

func ShouldActivateChainMode(
	providerOptions fantasy.ProviderOptions,
	info ChainModeInfo,
	modelConfigID uuid.UUID,
	isPlanModeTurn bool,
) bool

ShouldActivateChainMode reports whether a follow-up turn can use previous_response_id instead of replaying history. It requires store=true, a matching model config, meaningful trailing user input, non-plan mode, complete local tool state, and confirmation that tool results were sent to the provider.

func TextVerbosityFromChat

func TextVerbosityFromChat(value *string) *fantasyopenai.TextVerbosity

TextVerbosityFromChat normalizes chat-config text verbosity values for OpenAI and returns the canonical provider verbosity value.

func UsesResponsesOptions

func UsesResponsesOptions(model fantasy.LanguageModel) bool

UsesResponsesOptions reports whether the model should use OpenAI Responses API provider options.

func WebSearchTool

func WebSearchTool(options *codersdk.ChatModelOpenAIProviderOptions) (fantasy.Tool, bool)

WebSearchTool returns the OpenAI provider-native web search tool when enabled by the model provider options.

func WithPreviousResponseID

func WithPreviousResponseID(
	opts fantasy.ProviderOptions,
	previousResponseID string,
) fantasy.ProviderOptions

WithPreviousResponseID shallow-clones the provider options map and the OpenAI Responses entry, setting PreviousResponseID on the clone. The original map and entry are not mutated.

Types

type ChainModeInfo

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

ChainModeInfo holds the information needed to determine whether a follow-up turn can use OpenAI's previous_response_id chaining instead of replaying full conversation history.

func ResolveChainMode

func ResolveChainMode(messages []database.ChatMessage) ChainModeInfo

ResolveChainMode scans DB messages from the end to inspect the current trailing user turn and detect whether the immediately preceding assistant/tool block can chain from a provider response ID.

func (ChainModeInfo) ContributingTrailingUserCount

func (c ChainModeInfo) ContributingTrailingUserCount() int

ContributingTrailingUserCount returns the number of trailing user messages that materially change the provider input.

func (ChainModeInfo) HasUnresolvedLocalToolCalls

func (c ChainModeInfo) HasUnresolvedLocalToolCalls() bool

HasUnresolvedLocalToolCalls reports whether PreviousResponseID points at an assistant message with pending local tool calls.

func (ChainModeInfo) ModelConfigID

func (c ChainModeInfo) ModelConfigID() uuid.UUID

ModelConfigID returns the model configuration used to produce the assistant message referenced by PreviousResponseID.

func (ChainModeInfo) PreviousResponseID

func (c ChainModeInfo) PreviousResponseID() string

PreviousResponseID returns the provider response ID from the last assistant message, if any.

func (ChainModeInfo) ProviderMissingToolResults

func (c ChainModeInfo) ProviderMissingToolResults() bool

ProviderMissingToolResults reports whether PreviousResponseID points at an assistant message with local tool results, but no follow-up assistant message confirms those tool results were sent to the provider (not just persisted locally).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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