open_ai_adapter
OpenAI LLM adapter for Pipecat.
- pipecat.adapters.services.open_ai_adapter.is_given(value: _T | NotGiven) TypeGuard[_T][source]
Check whether a value was explicitly provided.
Typically used when checking whether a parameter or field typed with OpenAI’s
NotGivenwas set:if is_given(tool_choice): ...
Also acts as a type guard: inside a true branch, the value is narrowed to exclude
OpenAINotGiven(e.g.ChatCompletionToolChoiceOptionParam | OpenAINotGivenbecomesChatCompletionToolChoiceOptionParam).- Parameters:
value – The value to check.
- Returns:
Trueif value is anything other thanNOT_GIVEN.
- class pipecat.adapters.services.open_ai_adapter.OpenAILLMInvocationParams[source]
Bases:
TypedDictContext-based parameters for invoking OpenAI ChatCompletion API.
- messages: list[ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam]
- tools: list[ChatCompletionFunctionToolParam] | NotGiven
- tool_choice: Literal['none', 'auto', 'required'] | ChatCompletionAllowedToolChoiceParam | ChatCompletionNamedToolChoiceParam | ChatCompletionNamedToolChoiceCustomParam | NotGiven
- class pipecat.adapters.services.open_ai_adapter.OpenAILLMAdapter[source]
Bases:
BaseLLMAdapter[OpenAILLMInvocationParams]OpenAI-specific adapter for Pipecat.
Handles:
Extracting parameters for OpenAI’s ChatCompletion API from a universal LLM context
Converting Pipecat’s standardized tools schema to OpenAI’s function-calling format.
Extracting and sanitizing messages from the LLM context for logging about OpenAI.
- property id_for_llm_specific_messages: str
Get the identifier used in LLMSpecificMessage instances for OpenAI.
- get_llm_invocation_params(context: LLMContext, *, system_instruction: str | None = None, convert_developer_to_user: bool) OpenAILLMInvocationParams[source]
Get OpenAI-specific LLM invocation parameters from a universal LLM context.
- Parameters:
context – The LLM context containing messages, tools, etc.
system_instruction – Optional system instruction from service settings or
run_inference. If provided, prepended as a system message.convert_developer_to_user – If True, convert “developer”-role messages to “user”-role messages. Used by OpenAI-compatible services that don’t support the “developer” role.
- Returns:
Dictionary of parameters for OpenAI’s ChatCompletion API.
- to_provider_tools_format(tools_schema: ToolsSchema) list[ChatCompletionFunctionToolParam][source]
Convert function schemas to OpenAI’s function-calling format.
- Parameters:
tools_schema – The Pipecat tools schema to convert.
- Returns:
List of OpenAI formatted function call definitions ready for use with ChatCompletion API.
- get_messages_for_logging(context: LLMContext) list[dict[str, Any]][source]
Get messages from a universal LLM context in a format ready for logging about OpenAI.
Binary data (images, audio) is replaced with short placeholders.
- Parameters:
context – The LLM context containing messages.
- Returns:
List of messages in a format ready for logging about OpenAI.