Skip to content

fix: add _get_model_id() helper to prevent IndexError on missing '/' separator#258

Open
teyrebaz33 wants to merge 1 commit intoOpenGradient:mainfrom
teyrebaz33:fix/readme-model-names-and-enum-values
Open

fix: add _get_model_id() helper to prevent IndexError on missing '/' separator#258
teyrebaz33 wants to merge 1 commit intoOpenGradient:mainfrom
teyrebaz33:fix/readme-model-names-and-enum-values

Conversation

@teyrebaz33
Copy link
Copy Markdown

Summary

Fixes #249

Problem

Both completion() and chat() in llm.py were calling model.split('/')[1] directly. When a caller passes a model string without a / separator, this raises an unhelpful IndexError: list index out of range.

Fix

Added a _get_model_id() helper function that:

  • Handles both TEE_LLM enum instances and plain strings
  • Raises a clear ValueError with an actionable message if the format is invalid
  • Is reused in both completion() and chat() methods

Changes

  • src/opengradient/client/llm.py: Added _get_model_id() helper and replaced both raw .split('/')[1] calls

…separator

Fixes OpenGradient#249

Both completion() and chat() were calling model.split('/')[1] directly,
which raises IndexError when the model string has no '/' separator.

Added a _get_model_id() helper function that:
- Extracts the model value from TEE_LLM enum or plain string
- Raises a clear ValueError with a helpful message if the format is invalid
- Is used in both completion() and chat() methods

Matches the fix suggested in the issue.
Copy link
Copy Markdown
Collaborator

@kylexqian kylexqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError when model string has no / separator

2 participants