simworld.llm package
Submodules
simworld.llm.a2a_llm module
Local Planner (Activity to Action) LLM class for handling interactions with language models.
- class simworld.llm.a2a_llm.A2ALLM(model_name: str = 'gpt-4o-mini', url: str | None = None, provider: str = 'openai')
Bases:
BaseLLMLocal Planner (Activity to Action) LLM class for handling interactions with language models.
- generate_instructions(system_prompt, user_prompt, images=[], max_tokens=None, temperature=0.7, top_p=1.0, response_format=pydantic.BaseModel)
Generate instructions for the Local Planner system.
- Args:
system_prompt (str): The system prompt for the Local Planner system. user_prompt (str): The user prompt for the Local Planner system. images (list): The images for the Local Planner system. max_tokens (int): The maximum number of tokens for the Local Planner system. temperature (float): The temperature for the Local Planner system. top_p (float): The top_p for the Local Planner system. response_format (BaseModel): The response format for the Local Planner system.
simworld.llm.base_llm module
Base LLM class for handling interactions with language models.
- class simworld.llm.base_llm.BaseLLM(model_name: str, url: str | None = None, provider: str | None = 'openai')
Bases:
objectBase class for interacting with language models through OpenAI-compatible APIs.
- generate_text(system_prompt: str, user_prompt: str, max_tokens: int = 2048, temperature: float = 0.5, top_p: float = None, **kwargs) str | None
Generate text using the language model.
- Args:
system_prompt: System prompt to guide model behavior. user_prompt: User input prompt. max_tokens: Maximum number of tokens to generate. temperature: Sampling temperature. top_p: Top p sampling parameter.
- Returns:
Generated text response or None if generation fails.
simworld.llm.retry module
Retry decorator module for handling LLM API call retries with exponential backoff.
- exception simworld.llm.retry.LLMResponseParsingError
Bases:
ExceptionRaised when LLM response parsing fails.
- simworld.llm.retry.retry_api_call(max_retries: int = 5, initial_delay: float = 1.0, exponential_base: float = 2.0, rate_limit_per_min: int = 20)
Decorator for retrying LLM API calls with exponential backoff.
Handles API-related errors like network issues, timeouts, and rate limits.
- Args:
max_retries: Maximum number of retry attempts before giving up. initial_delay: Initial delay between retries in seconds. exponential_base: Base for exponential backoff calculation. rate_limit_per_min: Maximum number of calls allowed per minute.
- Returns:
Decorated function that implements API retry logic.
Module contents
This package contains the code for the LLM.