File size: 1,050 Bytes
c2b7a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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

    @classmethod
    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()),
        )