Spaces:
Sleeping
Sleeping
Download backend/providers/echo.py from monish563/NU-KIOSK-API: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/monish563/NU-KIOSK-API/resolve/main/backend/providers/echo.py
- Command line
-
hf download hf://spaces/monish563/NU-KIOSK-API/backend/providers/echo.py
-
curl -L -o echo.py https://huggingface.co/spaces/monish563/NU-KIOSK-API/resolve/main/backend/providers/echo.py
1.05 kB
| """Debug provider that echoes prompts for offline development.""" | |
| from __future__ import annotations | |
| import time | |
| from typing import Iterable, List | |
| from .base import BaseLLM, ChatMessage, LLMResponse, ProviderConfig | |
| class EchoProvider(BaseLLM): | |
| """Development-only provider that echoes the latest user message.""" | |
| def __init__(self, config: ProviderConfig) -> None: | |
| self.config = config | |
| def describe(cls) -> dict: | |
| return {"name": "echo", "supports_tools": False} | |
| def format_messages(self, messages: Iterable[ChatMessage]) -> List[ChatMessage]: | |
| return list(messages) | |
| def generate(self, messages: Iterable[ChatMessage]) -> LLMResponse: | |
| history = list(messages) | |
| text = history[-1]["content"] if history else "" | |
| timestamp = time.time() | |
| response_text = f"[echo @ {timestamp:.0f}] {text}" | |
| return LLMResponse( | |
| text=response_text, | |
| prompt_tokens=len(history), | |
| response_tokens=len(response_text.split()), | |
| ) | |