from collections.abc import AsyncIterator
from typing import Any
from fim_one.core.model.base import BaseLLM
from fim_one.core.model.types import ChatMessage, LLMResult, StreamChunk
class MyLLM(BaseLLM):
def __init__(self, api_key: str, model: str) -> None:
self._api_key = api_key
self._model = model
@property
def model_id(self) -> str:
return self._model
@property
def abilities(self) -> dict[str, bool]:
return {
"tool_call": True, # supports native function calling
"json_mode": True, # supports response_format JSON mode
"vision": False,
"streaming": True,
}
async def chat(
self,
messages: list[ChatMessage],
*,
tools: list[dict[str, Any]] | None = None,
tool_choice: str | dict[str, Any] | None = None,
temperature: float | None = None,
max_tokens: int | None = None,
response_format: dict[str, Any] | None = None,
) -> LLMResult:
# Call your provider, return LLMResult(message=..., usage=...)
...
async def stream_chat(
self,
messages: list[ChatMessage],
*,
tools: list[dict[str, Any]] | None = None,
tool_choice: str | dict[str, Any] | None = None,
temperature: float | None = None,
max_tokens: int | None = None,
) -> AsyncIterator[StreamChunk]:
# Yield StreamChunk instances as tokens arrive
...
yield # make type-checker happy