Spaces:
Sleeping
Sleeping
Download adsp/app/api/routes/chat.py from thanhnv2323/humanize-text-python: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/app/api/routes/chat.py
- Command line
-
hf download hf://spaces/thanhnv2323/humanize-text-python/adsp/app/api/routes/chat.py
-
curl -L -o chat.py https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/app/api/routes/chat.py
1.39 kB
| """Chat API routes.""" | |
| from __future__ import annotations | |
| from typing import Any, Callable | |
| from pydantic import BaseModel, ConfigDict, Field | |
| from adsp.core.types import ChatRequest, ChatResponse | |
| class ChatResponseEnvelope(BaseModel): | |
| model_config = ConfigDict( | |
| json_schema_extra={ | |
| "example": { | |
| "response": { | |
| "persona_id": "curious-connoisseurs", | |
| "answer": "I look for consistent taste, trusted quality, and fair price.", | |
| "context": "", | |
| "citations": [], | |
| "tool_calls": [], | |
| } | |
| } | |
| } | |
| ) | |
| response: ChatResponse = Field(description="Persona chat response payload.") | |
| def register_chat_routes( | |
| app: Any, | |
| *, | |
| get_qa_service: Callable[..., Any], | |
| authorize: Callable[..., Any], | |
| ) -> None: | |
| from fastapi import Depends | |
| def chat(payload: ChatRequest, qa: Any = Depends(get_qa_service)) -> ChatResponseEnvelope: | |
| response = qa.orchestrator.handle(payload) | |
| return ChatResponseEnvelope(response=response) | |