INNER CODE UNIT · Python

__init__

mfmezger/conversational-agent-langchain · frontend/client.py:12

    def __init__(self, base_url: str | None = None) -> None:
        """Initialize the client."""
        if base_url:
            self.base_url = base_url
        else:
            host = os.getenv("BACKEND_HOST", "localhost")
            port = os.getenv("BACKEND_PORT", "8001")
            self.base_url = f"http://{host}:{port}"

    async def chat_stream(self, messages: list[dict], collection_name: str = "default") -> AsyncGenerator[str, None]:
        """Stream chat response from the backend."""
        payload = {"messages": messages, "collection_name": collection_name}
        headers = {"accept": "application/json", "Content-Type": "application/json"}
        async with httpx.AsyncClient(timeout=600.0) as client, client.stream("POST", f"{self.base_url}/rag/stream", json=payload, headers=headers) as response:
            response.raise_for_status()
            async for line in response.aiter_lines():
                yield line

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…