-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm_client.py
More file actions
28 lines (19 loc) · 945 Bytes
/
llm_client.py
File metadata and controls
28 lines (19 loc) · 945 Bytes
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
"""Deterministic mock client emulating an LLM completion API."""
from __future__ import annotations
from typing import Mapping
class MockLLMClient:
"""Return canned responses y exponer tarifa para estimar costos."""
def __init__(self, price_per_1k_tokens: float, response_catalog: Mapping[str, str]):
self.price_per_1k_tokens = price_per_1k_tokens
self._response_catalog = dict(response_catalog)
def complete(self, prompt: str) -> str:
"""Return the first response cuyo identificador esté contenido en el prompt."""
lower_prompt = prompt.lower()
for key, response in self._response_catalog.items():
if key.lower() in lower_prompt:
return response
return self._response_catalog.get(
"__default__",
"Document modular functions, validate with pytest and guard against prompt injection.",
)
__all__ = ["MockLLMClient"]