LLMClient
LLM adapter providing unified async call interface.
Class
LLMClient
class LLMClient:
def __init__(
self,
api_key: str,
base_url: str = "https://api.deepseek.com",
model: str = "deepseek-chat",
timeout: int = 30,
max_retries: int = 3
)
Parameters:
api_key(str): API keybase_url(str): API base URLmodel(str): Model nametimeout(int): Timeout in secondsmax_retries(int): Maximum retry count
Methods
chat_completion
async def chat_completion(
self,
system_prompt: str,
user_prompt: str,
temperature: float = 0.7,
max_tokens: int = 2000
) -> str
Send chat completion request.
Parameters:
system_prompt(str): System promptuser_prompt(str): User prompttemperature(float): Temperature parameter, controls randomnessmax_tokens(int): Maximum generation tokens
Returns:
str: LLM response content
Exceptions:
LLMTimeoutError: Request timeoutLLMParseError: Response parsing failed
close
Close client connection.
Features
- Auto Retry: Automatically retry on failure, up to
max_retriestimes - Timeout Control: Support custom timeout
- Async Support: Fully async implementation, supports high concurrency