-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Update watsonx.ai provider to use LiteLLM mixin and list all models #3674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
999c28e
ecafe40
ca771cd
1d941b6
e77b7a1
a4b9b1e
e601fbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
# This source code is licensed under the terms described in the LICENSE file in | ||
# the root directory of this source tree. | ||
|
||
import base64 | ||
import struct | ||
from collections.abc import AsyncIterator | ||
from typing import Any | ||
|
||
|
@@ -16,6 +18,7 @@ | |
OpenAIChatCompletion, | ||
OpenAIChatCompletionChunk, | ||
OpenAICompletion, | ||
OpenAIEmbeddingData, | ||
OpenAIEmbeddingsResponse, | ||
OpenAIEmbeddingUsage, | ||
OpenAIMessageParam, | ||
|
@@ -26,7 +29,6 @@ | |
from llama_stack.log import get_logger | ||
from llama_stack.providers.utils.inference.model_registry import ModelRegistryHelper, ProviderModelEntry | ||
from llama_stack.providers.utils.inference.openai_compat import ( | ||
b64_encode_openai_embeddings_response, | ||
convert_message_to_openai_dict_new, | ||
convert_tooldef_to_openai_tool, | ||
get_sampling_options, | ||
|
@@ -334,6 +336,7 @@ async def openai_chat_completion( | |
api_key=self.get_api_key(), | ||
api_base=self.api_base, | ||
) | ||
logger.info(f"params to litellm (openai compat): {params}") | ||
|
||
return await litellm.acompletion(**params) | ||
|
||
async def check_model_availability(self, model: str) -> bool: | ||
|
@@ -349,3 +352,28 @@ async def check_model_availability(self, model: str) -> bool: | |
return False | ||
|
||
return model in litellm.models_by_provider[self.litellm_provider_name] | ||
|
||
|
||
def b64_encode_openai_embeddings_response( | ||
response_data: list[dict], encoding_format: str | None = "float" | ||
) -> list[OpenAIEmbeddingData]: | ||
""" | ||
Process the OpenAI embeddings response to encode the embeddings in base64 format if specified. | ||
""" | ||
data = [] | ||
for i, embedding_data in enumerate(response_data): | ||
if encoding_format == "base64": | ||
byte_array = bytearray() | ||
for embedding_value in embedding_data["embedding"]: | ||
byte_array.extend(struct.pack("f", float(embedding_value))) | ||
|
||
response_embedding = base64.b64encode(byte_array).decode("utf-8") | ||
else: | ||
response_embedding = embedding_data["embedding"] | ||
data.append( | ||
OpenAIEmbeddingData( | ||
embedding=response_embedding, | ||
index=i, | ||
) | ||
) | ||
return data |
Uh oh!
There was an error while loading. Please reload this page.