chat-console 0.2.0__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
app/utils.py CHANGED
@@ -86,14 +86,12 @@ async def generate_streaming_response(app: 'SimpleChatApp', messages: List[Dict]
86
86
  buffer = []
87
87
  last_update = time.time()
88
88
  update_interval = 0.1 # Update UI every 100ms
89
+ generation_task = None
89
90
 
90
91
  try:
92
+ # The cancellation is now handled by cancelling the asyncio Task in main.py
93
+ # which will raise CancelledError here, interrupting the loop.
91
94
  async for chunk in client.generate_stream(messages, model, style):
92
- # Check if generation was cancelled by the app (e.g., via escape key)
93
- if not app.is_generating:
94
- logger.info("Generation cancelled by app flag.")
95
- break # Exit the loop immediately
96
-
97
95
  if chunk: # Only process non-empty chunks
98
96
  buffer.append(chunk)
99
97
  current_time = time.time()
@@ -102,34 +100,37 @@ async def generate_streaming_response(app: 'SimpleChatApp', messages: List[Dict]
102
100
  if current_time - last_update >= update_interval or len(''.join(buffer)) > 100:
103
101
  new_content = ''.join(buffer)
104
102
  full_response += new_content
105
- # Check again before calling callback, in case it was cancelled during chunk processing
106
- if not app.is_generating:
107
- logger.info("Generation cancelled before UI update.")
108
- break
103
+ # No need to check app.is_generating here, rely on CancelledError
109
104
  await callback(full_response)
110
105
  buffer = []
111
106
  last_update = current_time
112
107
 
113
108
  # Small delay to let UI catch up
114
109
  await asyncio.sleep(0.05)
115
-
116
- # Send any remaining content if generation wasn't cancelled
117
- if buffer and app.is_generating:
110
+
111
+ # Send any remaining content if the loop finished normally
112
+ if buffer:
118
113
  new_content = ''.join(buffer)
119
114
  full_response += new_content
120
115
  await callback(full_response)
121
-
122
- if app.is_generating:
123
- logger.info("Streaming response completed normally.")
124
- else:
125
- logger.info("Streaming response loop exited due to cancellation.")
126
-
116
+
117
+ logger.info("Streaming response loop finished normally.") # Clarify log message
118
+ # Add log before returning
119
+ logger.info(f"generate_streaming_response returning normally. Full response length: {len(full_response)}")
127
120
  return full_response
121
+ except asyncio.CancelledError:
122
+ # This is expected when the user cancels via Escape
123
+ logger.info("Streaming response task cancelled.") # Clarify log message
124
+ # Add log before returning
125
+ logger.info(f"generate_streaming_response returning after cancellation. Partial response length: {len(full_response)}")
126
+ # Do not re-raise CancelledError, let the caller handle it
127
+ return full_response # Return whatever was collected so far (might be partial)
128
128
  except Exception as e:
129
- logger.error(f"Error in streaming response: {str(e)}")
130
- # Ensure the app knows generation stopped on error
131
- app.is_generating = False
132
- raise
129
+ logger.error(f"Error during streaming response: {str(e)}") # Clarify log message
130
+ # Ensure the app knows generation stopped on error ONLY if it wasn't cancelled
131
+ if not isinstance(e, asyncio.CancelledError):
132
+ app.is_generating = False # Reset flag on other errors
133
+ raise # Re-raise other exceptions
133
134
 
134
135
  def ensure_ollama_running() -> bool:
135
136
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chat-console
3
- Version: 0.2.0
3
+ Version: 0.2.5
4
4
  Summary: A command-line interface for chatting with LLMs, storing chats and (future) rag interactions
5
5
  Home-page: https://github.com/wazacraftrfid/chat-console
6
6
  Author: Johnathan Greenaway
@@ -1,23 +1,24 @@
1
- app/__init__.py,sha256=OeqboIrx_Kjea0CY9Be8nLI-No1YWQfqbWIp-4lMOOI,131
1
+ app/__init__.py,sha256=SL20Ng0SdkG6HpNwMI3wEAmSDMvlhYLaAuXs0iAlIL0,130
2
2
  app/config.py,sha256=sKNp6Za4ZfW-CZBOvEv0TncAS77AnKi86hTM51C4KQ4,5227
3
3
  app/database.py,sha256=nt8CVuDpy6zw8mOYqDcfUmNw611t7Ln7pz22M0b6-MI,9967
4
- app/main.py,sha256=PMx9DcD2MAVyqeYanqu6mqr43RG4oXA9jFIdBwoQFQY,48174
4
+ app/main.py,sha256=uuh8z__950Rs-U0X5NmgRAupcSZFREyOazsDbK1eFYM,53365
5
5
  app/models.py,sha256=4-y9Lytay2exWPFi0FDlVeRL3K2-I7E-jBqNzTfokqY,2644
6
- app/utils.py,sha256=AgmLrmyikt1Y7KturNmZVK2eC6de-RfRadVbp3HmUAg,8434
6
+ app/utils.py,sha256=6XSIJBcJPOXPIHnvKvRwnttdRnN9BSlodcKVj57RLeM,8861
7
7
  app/api/__init__.py,sha256=A8UL84ldYlv8l7O-yKzraVFcfww86SgWfpl4p7R03-w,62
8
8
  app/api/anthropic.py,sha256=x5PmBXEKe_ow2NWk8XdqSPR0hLOdCc_ypY5QAySeA78,4234
9
9
  app/api/base.py,sha256=-6RSxSpqe-OMwkaq1wVWbu3pVkte-ZYy8rmdvt-Qh48,3953
10
- app/api/ollama.py,sha256=zFZ3g2sYncvMgcvx92jTCLkigIaDvTuhILcLiCrwisc,11640
10
+ app/api/ollama.py,sha256=NgfETreb7EdFIux9fvkDfIBj77wcJvic77ObUV95TlI,49866
11
11
  app/api/openai.py,sha256=1fYgFXXL6yj_7lQ893Yj28RYG4M8d6gt_q1gzhhjcig,3641
12
12
  app/ui/__init__.py,sha256=RndfbQ1Tv47qdSiuQzvWP96lPS547SDaGE-BgOtiP_w,55
13
13
  app/ui/chat_interface.py,sha256=VwmVvltxS9l18DI9U7kL43t8kSPPNsrkkrrUSoGu16Q,13623
14
14
  app/ui/chat_list.py,sha256=WQTYVNSSXlx_gQal3YqILZZKL9UiTjmNMIDX2I9pAMM,11205
15
+ app/ui/model_browser.py,sha256=5h3gVsuGIUrXjYVF-QclZFhYtX2kH14LvT22Ufm9etg,49453
15
16
  app/ui/model_selector.py,sha256=Aj1irAs9DQMn8wfcPsFZGxWmx0JTzHjSe7pVdDMwqTQ,13182
16
17
  app/ui/search.py,sha256=b-m14kG3ovqW1-i0qDQ8KnAqFJbi5b1FLM9dOnbTyIs,9763
17
18
  app/ui/styles.py,sha256=04AhPuLrOd2yenfRySFRestPeuTPeMLzhmMB67NdGvw,5615
18
- chat_console-0.2.0.dist-info/licenses/LICENSE,sha256=srHZ3fvcAuZY1LHxE7P6XWju2njRCHyK6h_ftEbzxSE,1057
19
- chat_console-0.2.0.dist-info/METADATA,sha256=DPnX1Q1e7iTfNyyQRhJezaUXuHtq1E9mqb7k7gDe0GI,2921
20
- chat_console-0.2.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
21
- chat_console-0.2.0.dist-info/entry_points.txt,sha256=kkVdEc22U9PAi2AeruoKklfkng_a_aHAP6VRVwrAD7c,67
22
- chat_console-0.2.0.dist-info/top_level.txt,sha256=io9g7LCbfmTG1SFKgEOGXmCFB9uMP2H5lerm0HiHWQE,4
23
- chat_console-0.2.0.dist-info/RECORD,,
19
+ chat_console-0.2.5.dist-info/licenses/LICENSE,sha256=srHZ3fvcAuZY1LHxE7P6XWju2njRCHyK6h_ftEbzxSE,1057
20
+ chat_console-0.2.5.dist-info/METADATA,sha256=SShpyDtmGbwmbUj7wdTmdD4mN1xeIdimyMiiZAC0coQ,2921
21
+ chat_console-0.2.5.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
22
+ chat_console-0.2.5.dist-info/entry_points.txt,sha256=kkVdEc22U9PAi2AeruoKklfkng_a_aHAP6VRVwrAD7c,67
23
+ chat_console-0.2.5.dist-info/top_level.txt,sha256=io9g7LCbfmTG1SFKgEOGXmCFB9uMP2H5lerm0HiHWQE,4
24
+ chat_console-0.2.5.dist-info/RECORD,,