ractogateway.adapters.base
Base adapter and shared response models.
Every LLM provider adapter inherits from BaseLLMAdapter and implements
the same interface: tool translation, request building, execution, and
response normalisation.
- class ractogateway.adapters.base.FinishReason(*values)[source]
-
Why the model stopped generating.
- STOP = 'stop'
- TOOL_CALL = 'tool_call'
- LENGTH = 'length'
- CONTENT_FILTER = 'content_filter'
- ERROR = 'error'
- class ractogateway.adapters.base.ToolCallResult(**data)[source]
Bases:
BaseModelA single tool/function call returned by the model.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- id: str
- name: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ractogateway.adapters.base.ChatTurn[source]
Bases:
TypedDictOne prior chat message used as conversational history.
- role: Literal['system', 'user', 'assistant']
- content: str
- class ractogateway.adapters.base.LLMResponse(**data)[source]
Bases:
BaseModelUnified, provider-agnostic response envelope.
Every adapter’s
run()method returns one of these, regardless of whether the underlying provider is OpenAI, Gemini, or Anthropic.Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- tool_calls: list[ToolCallResult]
- finish_reason: FinishReason
- raw: Any
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- ractogateway.adapters.base.strip_markdown_fences(text)[source]
Remove markdown code fences that wrap JSON payloads.
- Return type:
- ractogateway.adapters.base.try_parse_json(text)[source]
Attempt to parse text as JSON after stripping fences.
Returns
Noneif the text is not valid JSON or is a JSON primitive (number, boolean, string) — only JSON objects and arrays are returned.
- class ractogateway.adapters.base.BaseLLMAdapter(model, *, api_key=None, **kwargs)[source]
Bases:
ABCAbstract base class that every provider adapter must implement.
- Parameters:
- provider: str = 'base'
- abstractmethod translate_tools(registry)[source]
Convert canonical
ToolSchemaobjects into the provider’s native tool/function-calling format.
- abstractmethod run(prompt, user_message, *, history=None, tools=None, temperature=0.0, max_tokens=4096, **kwargs)[source]
Execute a prompt against the provider and return a normalised response.
- Return type:
- abstractmethod async arun(prompt, user_message, *, history=None, tools=None, temperature=0.0, max_tokens=4096, **kwargs)[source]
Async variant of
run().- Return type: