feat: add chat_tui example for FastGPT with Textual interface

- Introduced a new example script `chat_tui.py` that provides a full-screen Textual interface for interacting with FastGPT.
- Implemented streaming chat updates, workflow logging, and modal handling for interactive nodes.
- Enhanced FastGPT client with new streaming capabilities and structured event types for better interaction handling.
- Normalized base URL handling in the client to prevent duplicate `/api` paths.
- Added tests for streaming event parsing and interaction handling.
This commit is contained in:
Xin Wang
2026-03-10 15:34:27 +08:00
parent eab8e15cd6
commit ef2614a70a
14 changed files with 1562 additions and 28 deletions

View File

@@ -44,9 +44,10 @@ class AsyncFastGPTClient(BaseClientMixin):
# Initialize base client functionality
super().__init__(api_key, base_url, timeout, max_retries, retry_delay, enable_logging)
connect_timeout = min(float(timeout), 15.0) if timeout and timeout > 0 else 15.0
self._client = httpx.AsyncClient(
base_url=base_url,
timeout=httpx.Timeout(timeout, connect=5.0),
base_url=self.base_url,
timeout=httpx.Timeout(timeout, connect=connect_timeout),
)
async def __aenter__(self):
@@ -270,6 +271,9 @@ class AsyncFastGPTClient(BaseClientMixin):
try:
error_data = response.json()
message = error_data.get("message", f"HTTP {response.status_code}")
except httpx.ResponseNotRead:
message = f"HTTP {response.status_code}"
error_data = None
except (ValueError, KeyError, AttributeError):
# If we can't parse JSON (e.g., streaming response or invalid JSON), use status code
message = f"HTTP {response.status_code}"