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
15 changes: 13 additions & 2 deletions src/opengradient/client/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ class _ChatParams:
x402_settlement_mode: x402SettlementMode


def _get_model_id(model) -> str:
"""Extract model ID from provider/model-name format, raising ValueError for invalid formats."""
value = model.value if hasattr(model, "value") else str(model)
parts = value.split("/", 1)
if len(parts) != 2:
raise ValueError(
f"Invalid model identifier '{value}'. Expected 'provider/model-name' format."
)
return parts[1]


class LLM:
"""
LLM inference namespace.
Expand Down Expand Up @@ -252,7 +263,7 @@ async def completion(
Raises:
RuntimeError: If the inference fails.
"""
model_id = model.split("/")[1]
model_id = _get_model_id(model)
payload: Dict = {
"model": model_id,
"prompt": prompt,
Expand Down Expand Up @@ -327,7 +338,7 @@ async def chat(
RuntimeError: If the inference fails.
"""
params = _ChatParams(
model=model.split("/")[1],
model=_get_model_id(model),
max_tokens=max_tokens,
temperature=temperature,
stop_sequence=stop_sequence,
Expand Down
Loading