feat: enhance chat CLI and TUI with initial opener handling and improved prompt logic
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user