llama-stack-mirror/llama_stack/providers/utils
Francisco Arceo 554ada57b0
chore: Add OpenAI compatibility for Ollama embeddings (#2440)
# What does this PR do?
This PR adds OpenAI compatibility for Ollama embeddings. Closes
https://github.com/meta-llama/llama-stack/issues/2428

Summary of changes:
- `llama_stack/providers/remote/inference/ollama/ollama.py`
- Implements the OpenAI embeddings endpoint for Ollama, replacing the
NotImplementedError with a full function that validates the model,
prepares parameters, calls the client, encodes embedding data
(optionally in base64), and returns a correctly structured response.
- Updates import statements to include the new embedding response
utilities.

- `llama_stack/providers/utils/inference/litellm_openai_mixin.py`
- Refactors the embedding data encoding logic to use a new shared
utility (`b64_encode_openai_embeddings_response`) instead of inline
base64 encoding and packing logic.
   - Cleans up imports accordingly.

- `llama_stack/providers/utils/inference/openai_compat.py`
- Adds `b64_encode_openai_embeddings_response` to handle encoding OpenAI
embedding outputs (including base64 support) in a reusable way.
- Adds `prepare_openai_embeddings_params` utility for standardizing
embedding parameter preparation.
   - Updates imports to include the new embedding data class.

- `tests/integration/inference/test_openai_embeddings.py`
- Removes `"remote::ollama"` from the list of providers that skip OpenAI
embeddings tests, since support is now implemented.

## Note

There was one minor issue, which required me to override the
`OpenAIEmbeddingsResponse.model` name with
`self._get_model(model).identifier` name, which is very unsatisfying.

## Test Plan
Unit Tests and integration tests

---------

Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
2025-06-13 14:28:51 -04:00
..
bedrock chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
common chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
datasetio chore(refact): move paginate_records fn outside of datasetio (#2137) 2025-05-12 10:56:14 -07:00
inference chore: Add OpenAI compatibility for Ollama embeddings (#2440) 2025-06-13 14:28:51 -04:00
kvstore feat: add deps dynamically based on metastore config (#2405) 2025-06-05 14:07:25 -07:00
memory feat: update openai tests to work with both clients (#2442) 2025-06-12 16:30:23 -07:00
responses feat: add responses input items api (#2239) 2025-05-24 07:05:53 -07:00
scoring chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
sqlstore feat: add postgres deps to starter distro (#2360) 2025-06-03 11:04:23 -07:00
telemetry feat: Propagate W3C trace context headers from clients (#2153) 2025-05-19 18:56:54 -07:00
tools fix: match mcp headers in provider data to Responses API shape (#2263) 2025-05-25 14:33:10 -07:00
__init__.py API Updates (#73) 2024-09-17 19:51:35 -07:00
pagination.py chore(refact): move paginate_records fn outside of datasetio (#2137) 2025-05-12 10:56:14 -07:00
scheduler.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00