mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-12 04:00:42 +00:00
fix(mypy): resolve OpenAI SDK NotGiven/Omit type mismatches
Refactor embeddings API calls to avoid NotGiven/Omit type incompatibility by conditionally building kwargs dict with only non-None parameters. - openai_mixin.py: Build kwargs conditionally for embeddings.create() - gemini.py: Apply same pattern + add Any import This approach avoids type:ignore comments by not passing NOT_GIVEN sentinel values that conflict with Omit type annotations in OpenAI SDK. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d009dc29f7
commit
864a5ff19b
2 changed files with 25 additions and 24 deletions
|
|
@ -351,22 +351,22 @@ class OpenAIMixin(NeedsRequestProviderData, ABC, BaseModel):
|
|||
"""
|
||||
Direct OpenAI embeddings API call.
|
||||
"""
|
||||
# Prepare request parameters
|
||||
request_params = {
|
||||
# Build kwargs conditionally to avoid NotGiven/Omit type mismatch
|
||||
# The OpenAI SDK uses Omit in signatures but NOT_GIVEN has type NotGiven
|
||||
kwargs: dict[str, Any] = {
|
||||
"model": await self._get_provider_model_id(params.model),
|
||||
"input": params.input,
|
||||
"encoding_format": params.encoding_format if params.encoding_format is not None else NOT_GIVEN,
|
||||
"dimensions": params.dimensions if params.dimensions is not None else NOT_GIVEN,
|
||||
"user": params.user if params.user is not None else NOT_GIVEN,
|
||||
}
|
||||
if params.encoding_format is not None:
|
||||
kwargs["encoding_format"] = params.encoding_format
|
||||
if params.dimensions is not None:
|
||||
kwargs["dimensions"] = params.dimensions
|
||||
if params.user is not None:
|
||||
kwargs["user"] = params.user
|
||||
if params.model_extra:
|
||||
kwargs["extra_body"] = params.model_extra
|
||||
|
||||
# Add extra_body if present
|
||||
extra_body = params.model_extra
|
||||
if extra_body:
|
||||
request_params["extra_body"] = extra_body
|
||||
|
||||
# Call OpenAI embeddings API with properly typed parameters
|
||||
response = await self.client.embeddings.create(**request_params)
|
||||
response = await self.client.embeddings.create(**kwargs)
|
||||
|
||||
data = []
|
||||
for i, embedding_data in enumerate(response.data):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue