Converters
Various conversion classes and methods to convert between Conatus's standardized output and the native format of the AI provider.
For more information, see the Models internals page.
Converters are not part of the public API
The converters are not part of the public API. They are subject to change without warning. Do not be surprised if you find this page particularly messy.
OpenAI Converters¶
Chat Completions API¶
conatus.models.open_ai.cc_conversion
¶
Conversion functions for OpenAI's ChatCompletion API.
OpenAIChatCompletionConverters
¶
Conversion functions for OpenAI's ChatCompletion API.
assistant_message_to_openai_assistant_message
staticmethod
¶
assistant_message_to_openai_assistant_message(
message: AssistantAIMessage,
) -> ChatCompletionAssistantMessageParam
Convert an AssistantAIMessage to an OpenAI assistant message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The AssistantAIMessage to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ChatCompletionAssistantMessageParam
|
The OpenAI assistant message. |
Source code in conatus/models/open_ai/cc_conversion.py
user_message_to_openai_user_message
staticmethod
¶
user_message_to_openai_user_message(
message: UserAIMessage,
) -> ChatCompletionUserMessageParam
Convert a UserAIMessage to an OpenAI user message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The UserAIMessage to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ChatCompletionUserMessageParam
|
The OpenAI user message. |
Source code in conatus/models/open_ai/cc_conversion.py
system_message_to_openai_system_message
staticmethod
¶
system_message_to_openai_system_message(
message: SystemAIMessage, model_name: str | None = None
) -> (
ChatCompletionSystemMessageParam
| ChatCompletionDeveloperMessageParam
)
Convert a SystemAIMessage to an OpenAI system message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The SystemAIMessage to convert.
TYPE:
|
model_name
|
The model name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ChatCompletionSystemMessageParam | ChatCompletionDeveloperMessageParam
|
The OpenAI system message. |
Source code in conatus/models/open_ai/cc_conversion.py
ai_message_to_openai_message
staticmethod
¶
ai_message_to_openai_message(
message: ConversationAIMessage,
) -> ChatCompletionMessageParam
Convert an AI message to an OpenAI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The AI message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ChatCompletionMessageParam
|
The OpenAI message. |
Source code in conatus/models/open_ai/cc_conversion.py
ai_prompt_messages_to_openai_messages
staticmethod
¶
ai_prompt_messages_to_openai_messages(
messages: Iterable[ConversationAIMessage],
) -> list[ChatCompletionMessageParam]
Convert an AI prompt messages to OpenAI messages.
| PARAMETER | DESCRIPTION |
|---|---|
messages
|
The AI prompt messages to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ChatCompletionMessageParam]
|
The OpenAI messages. |
Source code in conatus/models/open_ai/cc_conversion.py
ai_prompt_tools_to_openai_tools
staticmethod
¶
ai_prompt_tools_to_openai_tools(
tools: Iterable[AIToolSpecification] | None,
) -> list[ChatCompletionToolParam] | None
Convert an AI prompt tools to OpenAI tools.
This leverages the generate_openai_json_schema function to convert the
Pydantic model to an OpenAI-compatible JSON schema.
| PARAMETER | DESCRIPTION |
|---|---|
tools
|
The tools to convert to OpenAI tools.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ChatCompletionToolParam] | None
|
The OpenAI tools. |
Source code in conatus/models/open_ai/cc_conversion.py
convert_output_schema_to_openai_output_schema
staticmethod
¶
convert_output_schema_to_openai_output_schema(
output_schema: TypeAdapter[ParamType] | None,
*,
strict_mode: bool = True
) -> (
tuple[ResponseFormatJSONSchema, bool]
| tuple[None, Literal[False]]
)
Convert an output schema to an OpenAI output schema.
Essentially, it's just creating a "structured output" JSON schema.
| PARAMETER | DESCRIPTION |
|---|---|
output_schema
|
The output schema to convert.
TYPE:
|
strict_mode
|
Whether to use strict mode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ResponseFormatJSONSchema, bool] | tuple[None, Literal[False]]
|
If the output schema is not provided, returns None and False. Otherwise, returns the OpenAI output schema and a boolean indicating whether the schema has been converted from a non-object type to an object type. |
Source code in conatus/models/open_ai/cc_conversion.py
openai_response_to_ai_response
staticmethod
¶
openai_response_to_ai_response(
raw_response: ChatCompletion,
prompt: AIPrompt[OutputSchemaType],
model_name: str | None = None,
*,
output_schema_was_converted_to_item_object: bool = False
) -> AIResponse[OutputSchemaType]
Convert an OpenAI response to an AIResponse.
| PARAMETER | DESCRIPTION |
|---|---|
raw_response
|
The OpenAI response to convert.
TYPE:
|
prompt
|
The prompt that was used to generate the response.
TYPE:
|
model_name
|
The model name of the response.
TYPE:
|
output_schema_was_converted_to_item_object
|
Whether the output schema was converted to an item object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIResponse[OutputSchemaType]
|
The AIResponse. |
Source code in conatus/models/open_ai/cc_conversion.py
openai_assistant_message_to_assistant_ai_message
staticmethod
¶
openai_assistant_message_to_assistant_ai_message(
raw_assistant_message: (
ChatCompletionMessage | ChoiceDelta
),
) -> IncompleteAssistantAIMessage
Convert an OpenAI assistant message to an AssistantAIMessage.
| PARAMETER | DESCRIPTION |
|---|---|
raw_assistant_message
|
The OpenAI assistant message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAssistantAIMessage
|
The AssistantAIMessage. |
Source code in conatus/models/open_ai/cc_conversion.py
openai_finish_reason_to_finish_reason
staticmethod
¶
openai_finish_reason_to_finish_reason(
finish_reason: (
Literal[
"stop",
"length",
"tool_calls",
"content_filter",
"function_call",
]
| None
),
) -> FinishReasons | None
Convert an OpenAI finish reason to a FinishReasons.
| PARAMETER | DESCRIPTION |
|---|---|
finish_reason
|
The OpenAI finish reason to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FinishReasons | None
|
The FinishReasons. |
Source code in conatus/models/open_ai/cc_conversion.py
openai_chunk_to_ai_response
staticmethod
¶
openai_chunk_to_ai_response(
chunk: ChatCompletionChunk,
prompt: AIPrompt[OutputSchemaType],
model_name: str | None = None,
) -> IncompleteAIResponse[OutputSchemaType]
Convert an OpenAI chunk to an IncompleteAIResponse.
| PARAMETER | DESCRIPTION |
|---|---|
chunk
|
The OpenAI chunk to convert.
TYPE:
|
prompt
|
The prompt that was used to generate the chunk.
TYPE:
|
model_name
|
The model name of the chunk.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAIResponse[OutputSchemaType]
|
The IncompleteAIResponse. |
Source code in conatus/models/open_ai/cc_conversion.py
openai_usage_to_completion_usage
staticmethod
¶
openai_usage_to_completion_usage(
usage: CompletionUsage | None,
model_name: str | None = None,
) -> CompletionUsage
Convert an OpenAI usage to a CompletionUsage.
We default to 0 if the usage is None.
| PARAMETER | DESCRIPTION |
|---|---|
usage
|
The OpenAI usage to convert to a CompletionUsage.
TYPE:
|
model_name
|
The model name of the completion usage.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompletionUsage
|
The CompletionUsage. |
Source code in conatus/models/open_ai/cc_conversion.py
Responses API¶
conatus.models.open_ai.response_conversion
¶
Conversion functions for OpenAI responses API.
OpenAIResponseConverters
¶
Conversion functions for OpenAI responses API.
AccidentalComputerCallError
¶
Bases: Exception
Raised when OpenAI sends a computer call in ResponseOutputMessage.
This is a bug in OpenAI's API, and they will fix it at some point.
system_message_to_openai_message
staticmethod
¶
system_message_to_openai_message(
message: SystemAIMessage, model_name: str | None = None
) -> EasyInputMessageParam
Convert a SystemAIMessage to an OpenAI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The SystemAIMessage to convert.
TYPE:
|
model_name
|
The model name of the message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EasyInputMessageParam
|
The OpenAI message. |
Source code in conatus/models/open_ai/response_conversion.py
ai_prompt_messages_to_openai_messages
staticmethod
¶
ai_prompt_messages_to_openai_messages(
messages: Iterable[ConversationAIMessage],
) -> ResponseInputParam
Convert an AI prompt messages to OpenAI messages.
| PARAMETER | DESCRIPTION |
|---|---|
messages
|
The AI prompt messages to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResponseInputParam
|
The OpenAI messages. |
Source code in conatus/models/open_ai/response_conversion.py
ai_message_to_openai_message
staticmethod
¶
ai_message_to_openai_message(
message: ConversationAIMessage,
) -> Sequence[ResponseInputItemParam]
Convert an AI message to an OpenAI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The AI message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Sequence[ResponseInputItemParam]
|
The OpenAI message. |
Source code in conatus/models/open_ai/response_conversion.py
assistant_message_to_openai_message
staticmethod
¶
assistant_message_to_openai_message(
message: AssistantAIMessage,
) -> list[ResponseInputItemParam]
Convert an AssistantAIMessage to an OpenAI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The AssistantAIMessage to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ResponseInputItemParam]
|
The OpenAI message. |
Source code in conatus/models/open_ai/response_conversion.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
user_message_to_openai_message
staticmethod
¶
user_message_to_openai_message(
message: UserAIMessage,
) -> EasyInputMessageParam
Convert a UserAIMessage to an OpenAI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The UserAIMessage to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EasyInputMessageParam
|
The OpenAI message. |
Source code in conatus/models/open_ai/response_conversion.py
tool_response_message_to_openai_message
staticmethod
¶
tool_response_message_to_openai_message(
message: ToolResponseAIMessage,
) -> list[FunctionCallOutput | ComputerCallOutput]
Convert a ToolResponseAIMessage to an OpenAI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The ToolResponseAIMessage to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FunctionCallOutput | ComputerCallOutput]
|
The OpenAI message. |
Source code in conatus/models/open_ai/response_conversion.py
computer_tool_call_to_openai_computer_tool_call
staticmethod
¶
computer_tool_call_to_openai_computer_tool_call(
tool_call: ComputerUseAction, uid: str | None
) -> ResponseComputerToolCallParam | None
Convert a ComputerUseAction to an OpenAI computer tool call.
Note that not all ComputerUseActions can be converted to an OpenAI computer tool call. Most of the time, this will not matter, since we convert the ComputerUseAction to an OpenAI computer tool call and vice versa. But if you want to convert computer use actions from Anthropic to OpenAI, some stuff might be lost in translation.
| PARAMETER | DESCRIPTION |
|---|---|
tool_call
|
The ComputerUseAction to convert.
TYPE:
|
uid
|
The ID of the tool call.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResponseComputerToolCallParam | None
|
The OpenAI computer tool call. |
Source code in conatus/models/open_ai/response_conversion.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
ai_prompt_tools_to_openai_tools
staticmethod
¶
Convert an AI prompt tools to OpenAI tools.
| PARAMETER | DESCRIPTION |
|---|---|
prompt
|
The AI prompt to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ToolParam] | None
|
The OpenAI tools. |
Source code in conatus/models/open_ai/response_conversion.py
convert_output_schema_to_openai_output_schema
staticmethod
¶
convert_output_schema_to_openai_output_schema(
output_schema: TypeAdapter[ParamType] | None,
*,
strict_mode: bool = True
) -> (
tuple[ResponseTextConfigParam, bool]
| tuple[None, Literal[False]]
)
Convert an output schema to an OpenAI output schema.
Essentially, it's just creating a "structured output" JSON schema.
| PARAMETER | DESCRIPTION |
|---|---|
output_schema
|
The output schema to convert.
TYPE:
|
strict_mode
|
Whether to use strict mode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ResponseTextConfigParam, bool] | tuple[None, Literal[False]]
|
If the output schema is not provided, returns None and False. Otherwise, returns the OpenAI output schema and a boolean indicating whether the schema has been converted from a non-object type to an object type. |
Source code in conatus/models/open_ai/response_conversion.py
openai_response_to_ai_response
staticmethod
¶
openai_response_to_ai_response(
raw_response: Response,
prompt: AIPrompt[OutputSchemaType],
model_name: str | None = None,
*,
return_incomplete: Literal[True],
output_schema_was_converted_to_item_object: bool = False
) -> IncompleteAIResponse[OutputSchemaType]
openai_response_to_ai_response(
raw_response: Response,
prompt: AIPrompt[OutputSchemaType],
model_name: str | None = None,
*,
return_incomplete: Literal[False],
output_schema_was_converted_to_item_object: bool = False
) -> AIResponse[OutputSchemaType]
openai_response_to_ai_response(
raw_response: Response,
prompt: AIPrompt[OutputSchemaType],
model_name: str | None = None,
*,
return_incomplete: bool = False,
output_schema_was_converted_to_item_object: bool = False
) -> (
AIResponse[OutputSchemaType]
| IncompleteAIResponse[OutputSchemaType]
)
Convert an OpenAI response to an AIResponse.
| PARAMETER | DESCRIPTION |
|---|---|
raw_response
|
The OpenAI response to convert.
TYPE:
|
prompt
|
The prompt to convert.
TYPE:
|
model_name
|
The model name of the response.
TYPE:
|
return_incomplete
|
Whether to return an
TYPE:
|
output_schema_was_converted_to_item_object
|
Whether the output
schema was converted to an item object. This will only be
honored if the method returns a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AIResponse[OutputSchemaType] | IncompleteAIResponse[OutputSchemaType]
|
The AIResponse or IncompleteAIResponse. |
Source code in conatus/models/open_ai/response_conversion.py
openai_assistant_message_to_assistant_ai_message
staticmethod
¶
openai_assistant_message_to_assistant_ai_message(
oai_response: list[ResponseOutputItem],
cu_config: ComputerUseConfig | None = None,
) -> IncompleteAssistantAIMessage
Convert an OpenAI Response to an IncompleteAssistantAIMessage.
| PARAMETER | DESCRIPTION |
|---|---|
oai_response
|
The OpenAI response to convert.
TYPE:
|
cu_config
|
The environment in which the action is executed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAssistantAIMessage
|
The IncompleteAssistantAIMessage. |
Source code in conatus/models/open_ai/response_conversion.py
openai_finish_reason_to_finish_reason
staticmethod
¶
openai_finish_reason_to_finish_reason(
raw_response: Response,
message_received: (
AssistantAIMessage | IncompleteAssistantAIMessage
),
) -> FinishReasons
Convert an OpenAI finish reason to a FinishReasons.
| PARAMETER | DESCRIPTION |
|---|---|
raw_response
|
The OpenAI response to convert.
TYPE:
|
message_received
|
The assistant message received from the OpenAI response. |
| RETURNS | DESCRIPTION |
|---|---|
FinishReasons
|
The FinishReasons. |
Source code in conatus/models/open_ai/response_conversion.py
openai_usage_to_completion_usage
staticmethod
¶
openai_usage_to_completion_usage(
raw_usage: ResponseUsage | None,
model_name: str | None = None,
) -> CompletionUsage
Convert an OpenAI usage to a CompletionUsage.
| PARAMETER | DESCRIPTION |
|---|---|
raw_usage
|
The OpenAI usage to convert.
TYPE:
|
model_name
|
The model name of the completion usage.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompletionUsage
|
The CompletionUsage. |
Source code in conatus/models/open_ai/response_conversion.py
oai_output_msg_to_assistant_ai_msg_parts
staticmethod
¶
oai_output_msg_to_assistant_ai_msg_parts(
oai_output_msg: ResponseOutputMessage,
) -> list[IncompleteAssistantAIMessageContentPart]
Convert an OpenAI msg to an IncompleteAssistantAIMessageContentPart.
| PARAMETER | DESCRIPTION |
|---|---|
oai_output_msg
|
The OpenAI output message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[IncompleteAssistantAIMessageContentPart]
|
The IncompleteAssistantAIMessageContentPart. |
| RAISES | DESCRIPTION |
|---|---|
AccidentalComputerCallError
|
If OpenAI returns a computer call
in a |
Source code in conatus/models/open_ai/response_conversion.py
openai_computer_tool_click_to_computer_use_action
staticmethod
¶
openai_computer_tool_click_to_computer_use_action(
action: ActionClick,
cu_config: ComputerUseConfig,
call_id: str,
) -> ComputerUseAction
Convert an OpenAI computer tool click to a ComputerUseAction.
| PARAMETER | DESCRIPTION |
|---|---|
action
|
The OpenAI computer tool click to convert.
TYPE:
|
cu_config
|
The environment in which the action is executed.
TYPE:
|
call_id
|
The ID of the tool call.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComputerUseAction
|
The ComputerUseAction. |
Source code in conatus/models/open_ai/response_conversion.py
openai_computer_tool_call_to_computer_tool_call
staticmethod
¶
openai_computer_tool_call_to_computer_tool_call(
oai_computer_tool_call: ResponseComputerToolCall,
cu_config: ComputerUseConfig,
call_id: str,
) -> ComputerUseAction
Convert an OpenAI computer tool call to a ComputerUseAction.
| PARAMETER | DESCRIPTION |
|---|---|
oai_computer_tool_call
|
The OpenAI computer tool call to convert.
TYPE:
|
cu_config
|
The environment in which the action is executed.
TYPE:
|
call_id
|
The ID of the tool call.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComputerUseAction
|
The ComputerUseAction. |
Source code in conatus/models/open_ai/response_conversion.py
openai_response_output_item_to_assistant_ai_msg_parts
staticmethod
¶
openai_response_output_item_to_assistant_ai_msg_parts(
oai_output_item: ResponseOutputItem,
cu_config: ComputerUseConfig | None = None,
) -> Sequence[
IncompleteAssistantAIMessageContentPart
| AssistantAIMessageContentToolCallPart
]
Convert an OpenAI output item to an incomplete content part.
Note that we're returning a list, because one OpenAI output item can be converted to multiple content parts (e.g. text and refusal)
| PARAMETER | DESCRIPTION |
|---|---|
oai_output_item
|
The OpenAI output item to convert.
TYPE:
|
cu_config
|
The environment in which the action is executed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Sequence[IncompleteAssistantAIMessageContentPart | AssistantAIMessageContentToolCallPart]
|
The IncompleteAssistantAIMessageContentPart list |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no Computer Use environment is provided, but a computer use output item is nevertheless encountered. |
Source code in conatus/models/open_ai/response_conversion.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
openai_chunk_to_ai_response
staticmethod
¶
openai_chunk_to_ai_response(
chunk: ResponseStreamEvent,
prompt: AIPrompt[OutputSchemaType],
*,
model_name: str | None = None,
cu_config: ComputerUseConfig | None = None
) -> IncompleteAIResponse[OutputSchemaType] | None
Convert an OpenAI chunk to an AIResponse.
| PARAMETER | DESCRIPTION |
|---|---|
chunk
|
The OpenAI chunk to convert.
TYPE:
|
prompt
|
The prompt to convert.
TYPE:
|
model_name
|
The model name of the response.
TYPE:
|
cu_config
|
The environment in which the action is executed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAIResponse[OutputSchemaType] | None
|
The IncompleteAIResponse or None. |
Source code in conatus/models/open_ai/response_conversion.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 | |
Anthropic Converters¶
conatus.models.anthropic.conversion
¶
Conversion functions for Anthropic.
AnthropicConverters
¶
Conversion functions for Anthropic.
CUActionKwargs
¶
Bases: TypedDict
The kwargs for the computer use action.
anthropic_computer_use_block_to_tool_call
staticmethod
¶
anthropic_computer_use_block_to_tool_call(
block: BetaToolUseBlock, cu_config: ComputerUseConfig
) -> ComputerUseAction
Convert an Anthropic computer use block to a tool call.
| PARAMETER | DESCRIPTION |
|---|---|
block
|
The Anthropic computer use block to convert.
TYPE:
|
cu_config
|
The computer use config to use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ComputerUseAction
|
The tool call. |
Source code in conatus/models/anthropic/conversion.py
anthropic_block_to_assistant_msg_parts
staticmethod
¶
anthropic_block_to_assistant_msg_parts(
block: BetaContentBlock,
cu_config: ComputerUseConfig | None = None,
*,
model: Model | None = None,
index: int | None = None
) -> list[
IncompleteAssistantAIMessageContentPart
| AssistantAIMessageContentToolCallPart
]
Convert an Anthropic block to an assistant message part.
| PARAMETER | DESCRIPTION |
|---|---|
block
|
The Anthropic block to convert.
TYPE:
|
cu_config
|
The computer use config to use.
TYPE:
|
model
|
The model that produced the block.
TYPE:
|
index
|
The index of the block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[IncompleteAssistantAIMessageContentPart | AssistantAIMessageContentToolCallPart]
|
The assistant message part. |
Source code in conatus/models/anthropic/conversion.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
anthropic_delta_to_assistant_msg_parts
staticmethod
¶
anthropic_delta_to_assistant_msg_parts(
delta: BetaRawContentBlockDelta,
index: int,
model_name: Model | None = None,
) -> IncompleteAssistantAIMessageContentPart | None
Convert an Anthropic delta to an assistant message part.
| PARAMETER | DESCRIPTION |
|---|---|
delta
|
The Anthropic delta to convert.
TYPE:
|
model_name
|
The name of the model that produced the delta.
TYPE:
|
index
|
The index of the delta.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAssistantAIMessageContentPart | None
|
The assistant message part. |
Source code in conatus/models/anthropic/conversion.py
anthropic_message_to_ai_message
staticmethod
¶
anthropic_message_to_ai_message(
message: BetaMessage,
cu_config: ComputerUseConfig | None = None,
) -> IncompleteAssistantAIMessage
Convert an Anthropic message to an AI message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The Anthropic message to convert.
TYPE:
|
cu_config
|
The computer use config to use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAssistantAIMessage
|
The AI message. |
Source code in conatus/models/anthropic/conversion.py
anthropic_response_to_ai_response
staticmethod
¶
anthropic_response_to_ai_response(
response: BetaMessage,
prompt: AIPrompt[OutputSchemaType],
) -> IncompleteAIResponse[OutputSchemaType]
Convert an Anthropic response to an AI response.
| PARAMETER | DESCRIPTION |
|---|---|
response
|
The Anthropic response to convert.
TYPE:
|
prompt
|
The prompt that was used to generate the response.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAIResponse[OutputSchemaType]
|
The AI response. |
Source code in conatus/models/anthropic/conversion.py
anthropic_stop_reason_to_finish_reason
staticmethod
¶
anthropic_stop_reason_to_finish_reason(
stop_reason: (
Literal[
"end_turn",
"max_tokens",
"stop_sequence",
"tool_use",
"pause_turn",
"refusal",
]
| None
),
) -> FinishReasons | None
Convert an Anthropic stop reason to a finish reason.
| PARAMETER | DESCRIPTION |
|---|---|
stop_reason
|
The Anthropic stop reason to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FinishReasons | None
|
The finish reason. |
Source code in conatus/models/anthropic/conversion.py
anthropic_usage_to_completion_usage
staticmethod
¶
anthropic_usage_to_completion_usage(
usage: BetaUsage, model_name: Model | None = None
) -> CompletionUsage
Convert an Anthropic usage to a completion usage.
| PARAMETER | DESCRIPTION |
|---|---|
usage
|
The Anthropic usage to convert.
TYPE:
|
model_name
|
The name of the model that produced the usage.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompletionUsage
|
The completion usage. |
Source code in conatus/models/anthropic/conversion.py
ai_prompt_to_anthropic_messages
staticmethod
¶
ai_prompt_to_anthropic_messages(
messages: Iterable[ConversationAIMessage],
) -> list[BetaMessageParam]
Convert an AI prompt to a list of Anthropic messages.
| PARAMETER | DESCRIPTION |
|---|---|
messages
|
The messages to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[BetaMessageParam]
|
The list of Anthropic messages. |
Source code in conatus/models/anthropic/conversion.py
ai_message_to_anthropic_message
staticmethod
¶
ai_message_to_anthropic_message(
message: ConversationAIMessage,
) -> BetaMessageParam
Convert an AI message to an Anthropic message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The AI message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BetaMessageParam
|
The list of Anthropic messages. |
Source code in conatus/models/anthropic/conversion.py
user_ai_message_to_anthropic_message
staticmethod
¶
user_ai_message_to_anthropic_message(
message: UserAIMessage,
) -> BetaMessageParam
Convert a user AI message to an Anthropic message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The user AI message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BetaMessageParam
|
The Anthropic message. |
Source code in conatus/models/anthropic/conversion.py
user_ai_msg_content_parts_to_anthropic_content_parts
staticmethod
¶
user_ai_msg_content_parts_to_anthropic_content_parts(
content_parts: list[UserAIMessageContentPart],
) -> list[BetaTextBlockParam | BetaImageBlockParam]
Convert to Anthropic content parts.
| PARAMETER | DESCRIPTION |
|---|---|
content_parts
|
The list of user AI message content parts to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[BetaTextBlockParam | BetaImageBlockParam]
|
The list of Anthropic content parts. |
Source code in conatus/models/anthropic/conversion.py
assistant_ai_message_to_anthropic_message
staticmethod
¶
assistant_ai_message_to_anthropic_message(
message: AssistantAIMessage,
) -> BetaMessageParam
Convert an assistant AI message to an Anthropic message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The assistant AI message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BetaMessageParam
|
The Anthropic message. |
Source code in conatus/models/anthropic/conversion.py
tool_response_ai_message_to_anthropic_message
staticmethod
¶
tool_response_ai_message_to_anthropic_message(
message: ToolResponseAIMessage,
) -> BetaToolResultBlockParam
Convert a tool response AI message to an Anthropic message.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The tool response AI message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BetaToolResultBlockParam
|
The Anthropic message. |
Source code in conatus/models/anthropic/conversion.py
ai_prompt_tools_to_anthropic_tools
staticmethod
¶
Convert an AI prompt to a list of Anthropic tools.
| PARAMETER | DESCRIPTION |
|---|---|
prompt
|
The AI prompt to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[BetaToolUnionParam]
|
The list of Anthropic tools. |
Source code in conatus/models/anthropic/conversion.py
anthropic_chunk_to_incomplete_ai_response
staticmethod
¶
anthropic_chunk_to_incomplete_ai_response(
chunk: BetaRawMessageStreamEvent,
prompt: AIPrompt[OutputSchemaType],
model_name: Model,
) -> IncompleteAIResponse[OutputSchemaType] | None
Convert an Anthropic chunk to an incomplete AI response.
| PARAMETER | DESCRIPTION |
|---|---|
chunk
|
The Anthropic chunk to convert.
TYPE:
|
prompt
|
The prompt that was used to generate the response.
TYPE:
|
model_name
|
The name of the model that produced the chunk.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAIResponse[OutputSchemaType] | None
|
The incomplete AI response. |
Source code in conatus/models/anthropic/conversion.py
convert_output_schema_to_anthropic_tool
staticmethod
¶
convert_output_schema_to_anthropic_tool(
output_schema: TypeAdapter[ParamType] | None,
*,
strict_mode: bool = True
) -> (
tuple[BetaToolParam, bool] | tuple[None, Literal[False]]
)
Convert an output schema to an Anthropic output schema.
| PARAMETER | DESCRIPTION |
|---|---|
output_schema
|
The output schema to convert.
TYPE:
|
strict_mode
|
Whether to use strict mode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[BetaToolParam, bool] | tuple[None, Literal[False]]
|
If the output schema is not provided, returns None and False. Otherwise, returns the Anthropic output schema and a boolean indicating whether the schema has been converted from a non-object type to an item object. |
Source code in conatus/models/anthropic/conversion.py
Google Converters¶
conatus.models.google.conversion
¶
Conversion functions for Google.
GoogleConverters
¶
Conversion functions for Google GenAI.
ai_prompt_to_google_messages
staticmethod
¶
ai_prompt_to_google_messages(
messages: Iterable[ConversationAIMessage],
) -> list[Content]
Convert messages to the Google AI format.
| PARAMETER | DESCRIPTION |
|---|---|
messages
|
The messages to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Content]
|
The converted messages. |
Source code in conatus/models/google/conversion.py
assistant_ai_message_to_google_msg
staticmethod
¶
assistant_ai_message_to_google_msg(
message: AssistantAIMessage,
) -> Content
Convert an assistant message to the Google AI format.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Content
|
The converted message. |
Source code in conatus/models/google/conversion.py
user_ai_message_to_google_msg
staticmethod
¶
user_ai_message_to_google_msg(
message: UserAIMessage,
) -> Content
Convert a user message to the Google AI format.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The message to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Content
|
The converted message. |
Source code in conatus/models/google/conversion.py
ai_prompt_tools_to_google_tools
staticmethod
¶
Convert tools to the Google AI format.
| PARAMETER | DESCRIPTION |
|---|---|
prompt
|
The prompt to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FunctionDeclarationDict] | None
|
The converted tools. |
Source code in conatus/models/google/conversion.py
convert_output_schema_to_google_tool
staticmethod
¶
convert_output_schema_to_google_tool(
output_schema: TypeAdapter[ParamType] | None,
*,
strict_mode: bool = False
) -> tuple[SchemaDict, bool] | tuple[None, Literal[False]]
Convert an output schema to a Google AI tool.
| PARAMETER | DESCRIPTION |
|---|---|
output_schema
|
The output schema to convert.
TYPE:
|
strict_mode
|
Whether to use strict mode.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[SchemaDict, bool] | tuple[None, Literal[False]]
|
A tuple of the converted tool and a boolean indicating whether the conversion was necessary. |
Source code in conatus/models/google/conversion.py
google_response_to_ai_response
staticmethod
¶
google_response_to_ai_response(
response: GenerateContentResponse,
prompt: AIPrompt[OutputSchemaType],
) -> IncompleteAIResponse[OutputSchemaType]
Convert a Google response to an AI response.
| PARAMETER | DESCRIPTION |
|---|---|
response
|
The response to convert.
TYPE:
|
prompt
|
The prompt used to generate the response.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAIResponse[OutputSchemaType]
|
The converted response. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the response is invalid (e.g. no candidates found, no content found in the candidate, no parts found in the content, or no content found in the candidate). |
Source code in conatus/models/google/conversion.py
goog_response_to_assistant_msg
staticmethod
¶
goog_response_to_assistant_msg(
parts: list[Part],
) -> IncompleteAssistantAIMessage
Convert a Google content to an AI message.
| PARAMETER | DESCRIPTION |
|---|---|
parts
|
The parts to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IncompleteAssistantAIMessage
|
The converted message. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a function call name is missing. |
Source code in conatus/models/google/conversion.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
google_response_usage_to_completion_usage
staticmethod
¶
google_response_usage_to_completion_usage(
usage_metadata: (
GenerateContentResponseUsageMetadata | None
),
model_name: str | None = None,
) -> CompletionUsage | None
Convert a Google response usage to a completion usage.
| PARAMETER | DESCRIPTION |
|---|---|
usage_metadata
|
The usage metadata to convert.
TYPE:
|
model_name
|
The model name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompletionUsage | None
|
The converted usage. |