Skip to content

Commit e5883ec

Browse files
authored
fix: sglang tool call and response_format (#3392)
1 parent ab69753 commit e5883ec

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

camel/models/sglang_model.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,24 @@ async def _arun(
286286
with self._lock:
287287
# Update last run time
288288
self.last_run_time = time.time()
289+
async_client = self._async_client
289290

290-
if self._client is None:
291+
if async_client is None:
291292
raise RuntimeError(
292293
"Client is not initialized. Ensure the server is running."
293294
)
294295

295-
response = await self._async_client.chat.completions.create(
296+
# Prepare additional parameters
297+
extra_params: Dict[str, Any] = {}
298+
if response_format is not None:
299+
extra_params["response_format"] = response_format
300+
if tools is not None:
301+
extra_params["tools"] = tools
302+
303+
response = await async_client.chat.completions.create(
296304
messages=messages,
297305
model=self.model_type,
306+
**extra_params,
298307
**self.model_config_dict,
299308
)
300309
update_current_observation(
@@ -352,15 +361,24 @@ def _run(
352361
with self._lock:
353362
# Update last run time
354363
self.last_run_time = time.time()
364+
client = self._client
355365

356-
if self._client is None:
366+
if client is None:
357367
raise RuntimeError(
358368
"Client is not initialized. Ensure the server is running."
359369
)
360370

361-
response = self._client.chat.completions.create(
371+
# Prepare additional parameters
372+
extra_params: Dict[str, Any] = {}
373+
if response_format is not None:
374+
extra_params["response_format"] = response_format
375+
if tools is not None:
376+
extra_params["tools"] = tools
377+
378+
response = client.chat.completions.create(
362379
messages=messages,
363380
model=self.model_type,
381+
**extra_params,
364382
**self.model_config_dict,
365383
)
366384
update_current_observation(

0 commit comments

Comments
 (0)