File size: 1,382 Bytes
63f6453 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """Deterministik, önceden yazılmış yanıtlar dönen sahte LLM.
YALNIZCA otomatik testler ve altyapı doğrulaması içindir: ajan döngüsünü, araç çağırmayı,
koşucuları ve ölçümleri gerçek bir model olmadan uçtan uca sınamaya yarar. Gerçek model
başarımı ölçümlerinde kullanılmaz.
"""
from __future__ import annotations
from typing import Any, Callable, Optional, Union
from .base import LLMClient, LLMResponse, ToolCall, ToolSpec
Step = Union[LLMResponse, Callable[[list[dict[str, Any]]], LLMResponse]]
class ScriptedLLM(LLMClient):
def __init__(self, steps: list[Step], model: str = "scripted") -> None:
self.steps = list(steps)
self.model = model
self.calls: list[list[dict[str, Any]]] = []
def chat(self, messages, tools: Optional[list[ToolSpec]] = None, json_mode: bool = False,
temperature: float = 0.2) -> LLMResponse:
self.calls.append(messages)
if not self.steps:
return LLMResponse(content="", tool_calls=[ToolCall("finish", {"summary": "script bitti"})])
step = self.steps.pop(0)
return step(messages) if callable(step) else step
def tool(name: str, **args: Any) -> LLMResponse:
return LLMResponse(content="", tool_calls=[ToolCall(name=name, arguments=args)])
def text(content: str) -> LLMResponse:
return LLMResponse(content=content)
|