chat-console 0.3.8__py3-none-any.whl → 0.3.91__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/config.py CHANGED
@@ -175,35 +175,38 @@ CONFIG = load_config()
175
175
 
176
176
  # --- Dynamically update Anthropic models after initial load ---
177
177
  def update_anthropic_models(config):
178
- """Fetch models from Anthropic API and update the config dict."""
178
+ """Update the config with Anthropic models."""
179
179
  if AVAILABLE_PROVIDERS["anthropic"]:
180
180
  try:
181
- from app.api.anthropic import AnthropicClient # Import here to avoid circular dependency at top level
182
- client = AnthropicClient()
183
- fetched_models = client.get_available_models() # This now fetches (or uses fallback)
184
-
185
- if fetched_models:
186
- # Remove old hardcoded anthropic models first
187
- models_to_remove = [
188
- model_id for model_id, info in config["available_models"].items()
189
- if info.get("provider") == "anthropic"
190
- ]
191
- for model_id in models_to_remove:
192
- del config["available_models"][model_id]
193
-
194
- # Add fetched models
195
- for model in fetched_models:
196
- config["available_models"][model["id"]] = {
197
- "provider": "anthropic",
198
- "max_tokens": 4096, # Assign a default max_tokens
199
- "display_name": model["name"]
200
- }
201
- print(f"Updated Anthropic models in config: {[m['id'] for m in fetched_models]}") # Add print statement
202
- else:
203
- print("Could not fetch or find Anthropic models to update config.") # Add print statement
204
-
181
+ # Instead of calling an async method, use a hardcoded fallback list
182
+ # that matches what's in the AnthropicClient class
183
+ fallback_models = [
184
+ {"id": "claude-3-opus-20240229", "name": "Claude 3 Opus"},
185
+ {"id": "claude-3-sonnet-20240229", "name": "Claude 3 Sonnet"},
186
+ {"id": "claude-3-haiku-20240307", "name": "Claude 3 Haiku"},
187
+ {"id": "claude-3-5-sonnet-20240620", "name": "Claude 3.5 Sonnet"},
188
+ {"id": "claude-3-7-sonnet-20250219", "name": "Claude 3.7 Sonnet"},
189
+ ]
190
+
191
+ # Remove old models first
192
+ models_to_remove = [
193
+ model_id for model_id, info in config["available_models"].items()
194
+ if info.get("provider") == "anthropic"
195
+ ]
196
+ for model_id in models_to_remove:
197
+ del config["available_models"][model_id]
198
+
199
+ # Add the fallback models
200
+ for model in fallback_models:
201
+ config["available_models"][model["id"]] = {
202
+ "provider": "anthropic",
203
+ "max_tokens": 4096,
204
+ "display_name": model["name"]
205
+ }
206
+ print(f"Updated Anthropic models in config with fallback list")
207
+
205
208
  except Exception as e:
206
- print(f"Error updating Anthropic models in config: {e}") # Add print statement
209
+ print(f"Error updating Anthropic models in config: {e}")
207
210
  # Keep existing config if update fails
208
211
 
209
212
  return config
app/main.py CHANGED
@@ -20,10 +20,10 @@ file_handler = logging.FileHandler(debug_log_file)
20
20
  file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
21
21
 
22
22
  # Get the logger and add the handler
23
- debug_logger = logging.getLogger("chat-cli-debug")
23
+ debug_logger = logging.getLogger() # Root logger
24
24
  debug_logger.setLevel(logging.DEBUG)
25
25
  debug_logger.addHandler(file_handler)
26
- # Prevent propagation to the root logger (which would print to console)
26
+ # CRITICAL: Force all output to the file, not stdout
27
27
  debug_logger.propagate = False
28
28
 
29
29
  # Add a convenience function to log to this file
@@ -1010,11 +1010,15 @@ class SimpleChatApp(App): # Keep SimpleChatApp class definition
1010
1010
  self._loading_animation_task.cancel()
1011
1011
  self._loading_animation_task = None
1012
1012
  try:
1013
+ # Explicitly hide loading indicator
1013
1014
  loading = self.query_one("#loading-indicator")
1014
1015
  loading.add_class("hidden")
1016
+ loading.remove_class("model-loading") # Also remove model-loading class if present
1017
+ self.refresh(layout=True) # Force a refresh to ensure UI updates
1015
1018
  self.query_one("#message-input").focus()
1016
- except Exception:
1017
- pass # Ignore UI errors during cleanup
1019
+ except Exception as ui_err:
1020
+ debug_log(f"Error hiding loading indicator: {str(ui_err)}")
1021
+ log.error(f"Error hiding loading indicator: {str(ui_err)}")
1018
1022
 
1019
1023
  # Rename this method slightly to avoid potential conflicts and clarify purpose
1020
1024
  async def _handle_generation_result(self, worker: Worker[Optional[str]]) -> None:
@@ -1043,6 +1047,15 @@ class SimpleChatApp(App): # Keep SimpleChatApp class definition
1043
1047
  debug_log(f"Error in generation worker: {error}")
1044
1048
  log.error(f"Error in generation worker: {error}")
1045
1049
 
1050
+ # Explicitly hide loading indicator
1051
+ try:
1052
+ loading = self.query_one("#loading-indicator")
1053
+ loading.add_class("hidden")
1054
+ loading.remove_class("model-loading") # Also remove model-loading class if present
1055
+ except Exception as ui_err:
1056
+ debug_log(f"Error hiding loading indicator: {str(ui_err)}")
1057
+ log.error(f"Error hiding loading indicator: {str(ui_err)}")
1058
+
1046
1059
  # Sanitize error message for UI display
1047
1060
  error_str = str(error)
1048
1061
 
@@ -1069,6 +1082,9 @@ class SimpleChatApp(App): # Keep SimpleChatApp class definition
1069
1082
  debug_log(f"Adding error message: {user_error}")
1070
1083
  self.messages.append(Message(role="assistant", content=user_error))
1071
1084
  await self.update_messages_ui()
1085
+
1086
+ # Force a refresh to ensure UI updates
1087
+ self.refresh(layout=True)
1072
1088
 
1073
1089
  elif worker.state == "success":
1074
1090
  full_response = worker.result
app/ui/chat_interface.py CHANGED
@@ -120,54 +120,61 @@ class MessageDisplay(Static): # Inherit from Static instead of RichLog
120
120
  self.update(self._format_content(self.message.content))
121
121
 
122
122
  async def update_content(self, content: str) -> None:
123
- """Update the message content using Static.update() with optimizations for streaming"""
124
- # Debug print to verify method is being called with content
125
- print(f"MessageDisplay.update_content called with content length: {len(content)}")
126
-
127
- # Quick unchanged content check to avoid unnecessary updates
128
- if self.message.content == content:
129
- print("Content unchanged, skipping update")
130
- return
131
-
132
- # Special handling for "Thinking..." to ensure it gets replaced
133
- if self.message.content == "Thinking..." and content:
134
- print("Replacing 'Thinking...' with actual content")
135
- # Force a complete replacement rather than an append
136
- self.message.content = ""
137
- # Add a debug print to confirm this branch is executed
138
- print("CRITICAL FIX: Replacing 'Thinking...' placeholder with actual content")
139
-
140
- # Update the stored message object content
141
- self.message.content = content
142
-
143
- # Format with fixed-width placeholder to minimize layout shifts
144
- # This avoids text reflowing as new tokens arrive
145
- formatted_content = self._format_content(content)
146
-
147
- # Use a direct update that forces refresh - critical fix for streaming
148
- # This ensures content is immediately visible
149
- print(f"Updating widget with formatted content length: {len(formatted_content)}")
150
- self.update(formatted_content, refresh=True)
151
-
152
- # Force app-level refresh and scroll to ensure visibility
153
- try:
154
- # Always force app refresh for every update
155
- if self.app:
156
- # Force a full layout refresh to ensure content is visible
157
- self.app.refresh(layout=True)
123
+ """Update the message content."""
124
+ import logging
125
+ logger = logging.getLogger(__name__)
126
+ logger.debug(f"MessageDisplay.update_content called with content length: {len(content)}")
127
+
128
+ # Use a lock to prevent race conditions during updates
129
+ if not hasattr(self, '_update_lock'):
130
+ self._update_lock = asyncio.Lock()
131
+
132
+ async with self._update_lock:
133
+ # For initial update from "Thinking..."
134
+ if self.message.content == "Thinking..." and content:
135
+ logger.debug("Replacing 'Thinking...' with initial content")
136
+ self.message.content = content # Update the stored content
137
+ formatted = self._format_content(content)
138
+ self.update(formatted, refresh=True)
158
139
 
159
- # Find the messages container and scroll to end
160
- containers = self.app.query("ScrollableContainer")
161
- for container in containers:
162
- if hasattr(container, 'scroll_end'):
163
- container.scroll_end(animate=False)
140
+ # Force a clean layout update
141
+ try:
142
+ if self.app:
143
+ self.app.refresh(layout=True)
144
+ await asyncio.sleep(0.05) # Small delay for layout to update
164
145
 
165
- # Add an additional refresh after scrolling
166
- self.app.refresh(layout=True)
167
- except Exception as e:
168
- # Log the error and fallback to local refresh
169
- print(f"Error refreshing app: {str(e)}")
170
- self.refresh(layout=True)
146
+ # Find container and scroll
147
+ messages_container = self.app.query_one("#messages-container")
148
+ if messages_container:
149
+ messages_container.scroll_end(animate=False)
150
+ except Exception as e:
151
+ logger.error(f"Error in initial UI update: {str(e)}")
152
+ return
153
+
154
+ # Quick unchanged content check to avoid unnecessary updates
155
+ if self.message.content == content:
156
+ logger.debug("Content unchanged, skipping update")
157
+ return
158
+
159
+ # For subsequent updates
160
+ if self.message.content != content:
161
+ self.message.content = content
162
+ formatted = self._format_content(content)
163
+ self.update(formatted, refresh=True)
164
+
165
+ # Use a more targeted refresh approach
166
+ try:
167
+ if self.app:
168
+ self.app.refresh(layout=False) # Lightweight refresh first
169
+ # Find container and scroll
170
+ messages_container = self.app.query_one("#messages-container")
171
+ if messages_container:
172
+ messages_container.scroll_end(animate=False)
173
+
174
+ # Final full refresh only at end
175
+ self.app.refresh(layout=True)
176
+ except Exception as e:
177
+ logger.error(f"Error refreshing UI: {str(e)}")
171
178
 
172
179
  def _format_content(self, content: str) -> str:
173
180
  """Format message content with timestamp and handle markdown links"""
@@ -191,8 +198,8 @@ class MessageDisplay(Static): # Inherit from Static instead of RichLog
191
198
  # But keep our timestamp markup
192
199
  timestamp_markup = f"[dim]{timestamp}[/dim]"
193
200
 
194
- # Debug print to verify content is being formatted
195
- print(f"Formatting content: {len(content)} chars")
201
+ # Use proper logging instead of print
202
+ logger.debug(f"Formatting content: {len(content)} chars")
196
203
 
197
204
  return f"{timestamp_markup} {content}"
198
205