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

@@ -43,9 +43,10 @@ class FastGPTClient(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.Client(
base_url=base_url,
timeout=httpx.Timeout(timeout, connect=5.0),
base_url=self.base_url,
timeout=httpx.Timeout(timeout, connect=connect_timeout),
)
def __enter__(self):
@@ -206,6 +207,19 @@ class FastGPTClient(BaseClientMixin):
try:
error_data = response.json()
message = error_data.get("message", f"HTTP {response.status_code}")
except httpx.ResponseNotRead:
try:
response.read()
error_data = response.json()
message = error_data.get("message", f"HTTP {response.status_code}")
except Exception:
error_text = ""
try:
error_text = response.text.strip()
except Exception:
error_text = ""
message = error_text or 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}"