Skip to content

Commit cfd500e

Browse files
Nuclear MarmaladeNuclear Marmalade
authored andcommitted
Run ruff format on all files — fixes CI format check
1 parent 4c76e4c commit cfd500e

52 files changed

Lines changed: 2025 additions & 719 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

forge/adapters/claude.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,15 @@ def _convert_tools(tools: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
139139
for tool in tools:
140140
if tool.get("type") == "function":
141141
func = tool["function"]
142-
converted.append({
143-
"name": func["name"],
144-
"description": func.get("description", ""),
145-
"input_schema": func.get("parameters", {"type": "object", "properties": {}}),
146-
})
142+
converted.append(
143+
{
144+
"name": func["name"],
145+
"description": func.get("description", ""),
146+
"input_schema": func.get(
147+
"parameters", {"type": "object", "properties": {}}
148+
),
149+
}
150+
)
147151
elif "name" in tool:
148152
# Already in Anthropic format
149153
converted.append(tool)
@@ -188,13 +192,22 @@ def _call_with_retry(self, func, *args, **kwargs) -> Any:
188192
raise last_error # type: ignore[misc]
189193

190194
def _build_request_kwargs(
191-
self, messages: List[Dict[str, Any]], model: str,
192-
tools: Optional[List[Dict[str, Any]]], timeout: float, temperature: float,
195+
self,
196+
messages: List[Dict[str, Any]],
197+
model: str,
198+
tools: Optional[List[Dict[str, Any]]],
199+
timeout: float,
200+
temperature: float,
193201
) -> Dict[str, Any]:
194202
"""Build the Anthropic Messages API request kwargs."""
195203
system_text, user_messages = self._extract_system(messages)
196204
converted = self._convert_messages(user_messages)
197-
kwargs: Dict[str, Any] = {"model": model, "messages": converted, "max_tokens": 4096, "temperature": temperature}
205+
kwargs: Dict[str, Any] = {
206+
"model": model,
207+
"messages": converted,
208+
"max_tokens": 4096,
209+
"temperature": temperature,
210+
}
198211
if system_text:
199212
kwargs["system"] = system_text
200213
if tools:
@@ -228,7 +241,12 @@ def _do_create():
228241
response = self._call_with_retry(_do_create)
229242
result = self._response_to_ollama_format(response)
230243
usage = response.usage
231-
logger.debug("Claude response: model=%s, input_tokens=%d, output_tokens=%d", model, usage.input_tokens, usage.output_tokens)
244+
logger.debug(
245+
"Claude response: model=%s, input_tokens=%d, output_tokens=%d",
246+
model,
247+
usage.input_tokens,
248+
usage.output_tokens,
249+
)
232250
return result
233251

234252
@staticmethod
@@ -246,12 +264,14 @@ def _response_to_ollama_format(response) -> Dict[str, Any]:
246264
if block.type == "text":
247265
content_text += block.text
248266
elif block.type == "tool_use":
249-
tool_calls.append({
250-
"function": {
251-
"name": block.name,
252-
"arguments": block.input,
253-
},
254-
})
267+
tool_calls.append(
268+
{
269+
"function": {
270+
"name": block.name,
271+
"arguments": block.input,
272+
},
273+
}
274+
)
255275

256276
result: Dict[str, Any] = {
257277
"message": {
@@ -267,9 +287,15 @@ def _response_to_ollama_format(response) -> Dict[str, Any]:
267287

268288
return result
269289

270-
def _build_simple_kwargs(self, prompt: str, model: str, timeout: float, temperature: float, think: bool) -> Dict[str, Any]:
290+
def _build_simple_kwargs(
291+
self, prompt: str, model: str, timeout: float, temperature: float, think: bool
292+
) -> Dict[str, Any]:
271293
"""Build request kwargs for generate_simple."""
272-
kwargs: Dict[str, Any] = {"model": model, "messages": [{"role": "user", "content": prompt}], "max_tokens": 4096}
294+
kwargs: Dict[str, Any] = {
295+
"model": model,
296+
"messages": [{"role": "user", "content": prompt}],
297+
"max_tokens": 4096,
298+
}
273299
if think:
274300
kwargs["temperature"] = 1
275301
kwargs["thinking"] = {"type": "enabled", "budget_tokens": 2048}

forge/adapters/ollama.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ def __init__(
4545
self._default_timeout = default_timeout
4646
self._client = httpx.Client(timeout=default_timeout)
4747

48-
def _build_chat_payload(self, messages: List[Dict[str, Any]], model: str,
49-
tools: Optional[List[Dict[str, Any]]], temperature: float) -> Dict[str, Any]:
48+
def _build_chat_payload(
49+
self,
50+
messages: List[Dict[str, Any]],
51+
model: str,
52+
tools: Optional[List[Dict[str, Any]]],
53+
temperature: float,
54+
) -> Dict[str, Any]:
5055
"""Build the Ollama chat API payload."""
5156
payload: Dict[str, Any] = {
52-
"model": model, "messages": messages, "stream": False,
57+
"model": model,
58+
"messages": messages,
59+
"stream": False,
5360
"options": {"temperature": temperature, "num_predict": 2048},
5461
}
5562
if tools:
@@ -61,7 +68,9 @@ def _log_inference_stats(self, data: Dict[str, Any], model: str) -> None:
6168
eval_count = data.get("eval_count", 0)
6269
eval_duration = data.get("eval_duration", 1)
6370
tokens_per_sec = eval_count / (eval_duration / 1e9) if eval_duration > 0 else 0
64-
logger.debug("Ollama response: model=%s, tokens=%d, tok/s=%.1f", model, eval_count, tokens_per_sec)
71+
logger.debug(
72+
"Ollama response: model=%s, tokens=%d, tok/s=%.1f", model, eval_count, tokens_per_sec
73+
)
6574

6675
def generate(
6776
self,
@@ -82,7 +91,9 @@ def generate(
8291
payload = self._build_chat_payload(messages, model, tools, temperature)
8392

8493
try:
85-
response = self._client.post(f"{self._base_url}/api/chat", json=payload, timeout=timeout)
94+
response = self._client.post(
95+
f"{self._base_url}/api/chat", json=payload, timeout=timeout
96+
)
8697
response.raise_for_status()
8798
data = response.json()
8899
self._log_inference_stats(data, model)

0 commit comments

Comments
 (0)