feat: make litellm dependency optional#973
Conversation
…ed after merge with main" This reverts commit d77e3c6.
…oper cleanup of weaviate resources between tests
…er, remove LiteLLM dependency from VertexAI embedder
…l used in examples, remove useless TYPE_CHECKING
Code Coverage SummaryDetailsDiff against mainResults for commit: 46c33ba Minimum allowed coverage is ♻️ This comment has been updated with latest results |
…hub + fix another mypy issue
5fc31ab to
2a07b8e
Compare
…67-feat-make-litellm-dependency-optional # Conflicts: # examples/core/prompt/multimodal_with_pdf.py # examples/evaluate/dataset-generator/config/generate.yaml # packages/ragbits-chat/pyproject.toml # packages/ragbits/pyproject.toml # pyproject.toml # uv.lock
puzzle-solver
left a comment
There was a problem hiding this comment.
Overall looks good, but we need to make sure that this is the direction we want to go in. I would suggest leaving the LiteLLM dependency to not make a breaking change yet and independently add OpenAI/Anthropic/Google providers. Also, we need to make sure that the implementations of them are correct, including token counting and cost estimation, which right now is broken.
Eventually, I think adding something like RagbitsLLM that routes between the three providers would be cool (similarly to LiteLLM). LiteLLM would be a fallback to other models if needed.
| """ | ||
| Dataclass that represents available call options for the OpenAIEmbedder client. | ||
| Each of them is described in the | ||
| [OpenAI API documentation](https://platform.openai.com/docs/api-reference/embeddings/create). |
| class OpenAILLMOptions(LLMOptions): | ||
| """ | ||
| Dataclass that represents all available LLM call options for the OpenAI client. | ||
| Each of them is described in the [OpenAI API documentation](https://platform.openai.com/docs/api-reference/chat). |
There was a problem hiding this comment.
404 not found. I think openai made their documentation a little bit more confusing recently.
| """ | ||
|
|
||
| frequency_penalty: float | None | NotGiven = NOT_GIVEN | ||
| max_tokens: int | None | NotGiven = NOT_GIVEN |
There was a problem hiding this comment.
max_tokens here are declared again, even though base LLMOptions already has it. I know that it's not a scope of this PR, but other classes don't provide it, so we need some consistency. I think some set of parameters can be potentially moved to the base LLMOptions class (also temperature and top_p). Or we can ditch the LLMOptions class completely, since it doesn't really provide much value.
| """ | ||
| Returns 0.0 — cost estimation is not bundled; use OpenAI usage dashboard for billing details. | ||
| """ | ||
| return 0.0 |
There was a problem hiding this comment.
I mean, this is not too great. We probably shouldn't return 0 for a cost just like that if we actually have this method.
There was a problem hiding this comment.
This is also the case for Gemini and Anthropic
| return sum(len(enc.encode(str(msg.get("content") or ""))) for msg in prompt.chat) | ||
| except KeyError: | ||
| pass | ||
| return sum(len(str(msg.get("content") or "")) for msg in prompt.chat) |
There was a problem hiding this comment.
Not a good fallback, we should probably add tiktoken to dependencies explicitly when the user wants to use openai, otherwise they will silently get completely wrong token counts (number of characters is probably a few times higher than number of tokens)
Breaking change: LiteLLM becomes an optional dependency.
New LLM implementations: OpenAILLM, AnthropicLLM, GeminiLLM
New embedder implementations: OpenAIEmbedder, GeminiEmbedder.
note: this branch contains changes from add-docker-containers-for-integration-testing branch which hasn't been merged to main yet