feat: enhance chat CLI and TUI with initial opener handling and improved prompt logic

This commit is contained in:
Xin Wang
2026-03-10 23:55:53 +08:00
parent ef2614a70a
commit a55ca37c39
5 changed files with 278 additions and 26 deletions

View File

@@ -127,8 +127,9 @@ class AsyncFastGPTClient(BaseClientMixin):
response._stream_context = stream_context
response._stream_context_closed = False
# Override close() to also close the stream context
original_close = response.close
# Preserve the native async response closer and make both
# `await response.close()` and `await response.aclose()` safe.
original_aclose = response.aclose
async def close_with_context():
"""Close both the response and the stream context."""
@@ -136,10 +137,10 @@ class AsyncFastGPTClient(BaseClientMixin):
return
try:
# Close the response first
await original_close()
# Async streaming responses must use `aclose()`.
await original_aclose()
finally:
# Always close the stream context, even if response.close() fails
# Always close the stream context, even if response cleanup fails
if hasattr(response, '_stream_context') and response._stream_context is not None:
try:
await response._stream_context.__aexit__(None, None, None)
@@ -150,6 +151,7 @@ class AsyncFastGPTClient(BaseClientMixin):
response._stream_context_closed = True
response.close = close_with_context
response.aclose = close_with_context
# Safety net: ensure cleanup on garbage collection
def cleanup_stream_context(stream_ctx_ref):