Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TMWebDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def handle(self) -> None:
except Exception as e:
print(f"Error handling message: {e}")
if hasattr(self, 'data'): print(self.data)
def connected(self): (f"New connection from {self.address}")
def connected(self): print(f"New connection from {self.address}")
def handle_close(self):
print(f"WS Connection closed: {self.address}")
driver._unregister_client(self)
Expand Down
12 changes: 6 additions & 6 deletions llmcore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, json, re, time, requests, sys, threading, urllib3, base64, importlib, uuid
import os, json, re, time, requests, sys, threading, urllib3, base64, importlib, uuid, copy
from datetime import datetime
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
_RESP_CACHE_KEY = str(uuid.uuid4())
Expand Down Expand Up @@ -595,9 +595,9 @@ def _ensure_thinking_blocks(messages, model):
class ClaudeSession(BaseSession):
def raw_ask(self, messages):
messages = _fix_messages(messages)
if self.max_tokens is None: self.max_tokens = 8192
max_tokens = self.max_tokens or 8192
headers = {"x-api-key": self.api_key, "Content-Type": "application/json", "anthropic-version": "2023-06-01", "anthropic-beta": "prompt-caching-2024-07-31"}
payload = {"model": self.model, "messages": messages, "max_tokens": self.max_tokens, "stream": self.stream}
payload = {"model": self.model, "messages": messages, "max_tokens": max_tokens, "stream": self.stream}
if self.temperature != 1: payload["temperature"] = self.temperature
self._apply_claude_thinking(payload)
if self.system: payload["system"] = [{"type": "text", "text": self.system, "cache_control": {"type": "persistent"}}]
Expand Down Expand Up @@ -644,7 +644,7 @@ def __init__(self, cfg):
self._device_id = uuid.uuid4().hex + uuid.uuid4().hex[:32]
self.tools = None
def raw_ask(self, messages):
if self.max_tokens is None: self.max_tokens = 8192
max_tokens = self.max_tokens or 8192
model = self.model
messages = _fix_messages(messages)
if 'claude' in model.lower(): messages = _drop_unsigned_thinking(messages)
Expand All @@ -657,7 +657,7 @@ def raw_ask(self, messages):
"user-agent": self.user_agent, "x-app": "cli"}
if self.api_key.startswith("sk-ant-"): headers["x-api-key"] = self.api_key
else: headers["authorization"] = f"Bearer {self.api_key}"
payload = {"model": model, "messages": messages, "max_tokens": self.max_tokens, "stream": self.stream}
payload = {"model": model, "messages": messages, "max_tokens": max_tokens, "stream": self.stream}
if self.temperature != 1: payload["temperature"] = self.temperature
self._apply_claude_thinking(payload)
payload["metadata"] = {"user_id": json.dumps({"device_id": self._device_id, "account_uuid": self._account_uuid, "session_id": self._session_id}, separators=(',', ':'))}
Expand Down Expand Up @@ -748,7 +748,7 @@ def __init__(self, backend, auto_save_tokens=True):
self.log_path = None

def chat(self, messages, tools=None):
tools = json.loads(json.dumps(tools, ensure_ascii=False)) if tools else tools
tools = copy.deepcopy(tools) if tools else tools
for t in tools or []:
f = t.get('function', {})
if f.get('name') == 'file_write':
Expand Down