Skip to content

Flexible model client#163

Open
ivanleomk wants to merge 3 commits into
mainfrom
flexible-model-client
Open

Flexible model client#163
ivanleomk wants to merge 3 commits into
mainfrom
flexible-model-client

Conversation

@ivanleomk

@ivanleomk ivanleomk commented Jun 30, 2025

Copy link
Copy Markdown
Contributor

This makes it possible to either use a model string or just override and pass in an instructor client directly. This helps deal with cases where people might need to manually override the client


Important

Enhance model client flexibility by allowing ClusterDescriptionModel, MetaClusterModel, and SummaryModel to accept either a model string or an instructor.AsyncInstructor client.

  • Behavior:
    • ClusterDescriptionModel, MetaClusterModel, and SummaryModel now accept either a model string or an instructor.AsyncInstructor client.
    • Raises ValueError if the model type is neither a string nor an AsyncInstructor.
  • Initialization:
    • In cluster.py, meta_cluster.py, and summarisation.py, the __init__ methods are updated to handle both string model names and instructor client instances.
    • Imports instructor within the __init__ methods to ensure availability when needed.
  • Logging:
    • Updates logging to reflect the use of client instead of model in initialization logs across the three files.

This description was created by Ellipsis for 6b8584f. You can customize this summary. It will automatically update as commits are pushed.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 30, 2025

Copy link
Copy Markdown

Deploying kura with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b8584f
Status: ✅  Deploy successful!
Preview URL: https://1ebf4b22.kura-4ma.pages.dev
Branch Preview URL: https://flexible-model-client.kura-4ma.pages.dev

View logs

Comment thread kura/cluster.py
self.model = model
# Handle both string model names and instructor client instances
if isinstance(model, str):
self.client = instructor.from_provider(model, async_client=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Runtime error: 'instructor' is referenced in init but only imported inside a TYPE_CHECKING block. Import it at runtime (e.g. add a local import) to avoid NameError.

Comment thread kura/summarisation.py Outdated
# Handle both string model names and instructor client instances
if isinstance(model, str):
self.client = instructor.from_provider(model, async_client=True)
if isinstance(model, instructor.AsyncInstructor):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Conditional logic bug: Use 'elif' instead of a second 'if' when checking for instructor.AsyncInstructor, so valid string models don’t trigger the else block.

Suggested change
if isinstance(model, instructor.AsyncInstructor):
elif isinstance(model, instructor.AsyncInstructor):

@patelvivekdev

Copy link
Copy Markdown

If we pass the Gemini model, it is failing because the temperature is passing directly to client.chat.completions.create.

InstructorRetryException: AsyncModels.generate_content() got an unexpected keyword argument 'temperature'

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.

2 participants