Skip to content
Open
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
11 changes: 8 additions & 3 deletions src/opengradient/client/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class _ChatParams:
x402_settlement_mode: x402SettlementMode


def _model_id(model: str) -> str:
"""Extract model ID from a TEE_LLM value, handling plain strings without separator."""
return model.split("/")[1] if "/" in model else model


class LLM:
"""
LLM inference namespace.
Expand Down Expand Up @@ -277,7 +282,7 @@ async def completion(
Raises:
RuntimeError: If the inference fails.
"""
model_id = model.split("/")[1]
model_id = _model_id(model)
payload: Dict = {
"model": model_id,
"prompt": prompt,
Expand Down Expand Up @@ -360,15 +365,15 @@ async def chat(
RuntimeError: If the inference fails.
"""
if response_format is not None and response_format.type == "json_object":
provider = model.split("/")[0]
provider = model.split("/")[0] if "/" in model else None
if provider == "anthropic":
raise ValueError(
"Anthropic models do not support response_format type 'json_object'. "
"Use ResponseFormat(type='json_schema', json_schema={...}) with an explicit schema instead."
)

params = _ChatParams(
model=model.split("/")[1],
model=_model_id(model),
max_tokens=max_tokens,
temperature=temperature,
stop_sequence=stop_sequence,
Expand Down