Skip to content
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

Haystack llm and embedding wrapper #1901

Merged
merged 14 commits into from
Feb 20, 2025

Conversation

sahusiddharth
Copy link
Collaborator

No description provided.

@sahusiddharth sahusiddharth requested review from shahules786 and jjmachan and removed request for shahules786 February 4, 2025 21:15
src/ragas/embeddings/base.py Outdated Show resolved Hide resolved
src/ragas/embeddings/base.py Outdated Show resolved Hide resolved
src/ragas/embeddings/base.py Outdated Show resolved Hide resolved
src/ragas/llms/base.py Outdated Show resolved Hide resolved
src/ragas/llms/base.py Outdated Show resolved Hide resolved
@sahusiddharth sahusiddharth marked this pull request as ready for review February 6, 2025 05:28
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 6, 2025
Comment on lines 4 to 20
try:
from haystack_experimental.core import AsyncPipeline
except ImportError:
raise ImportError(
"haystack-experimental is not installed. Please install it using `pip install haystack-experimental==0.4.0`."
)
try:
from haystack.components.embedders import ( # type: ignore
AzureOpenAITextEmbedder,
HuggingFaceAPITextEmbedder,
OpenAITextEmbedder,
SentenceTransformersTextEmbedder,
)
except ImportError:
raise ImportError(
"pip install haystack-ai is not installed. Please install it using `pip install pip install haystack-ai`."
)
Copy link
Member

Choose a reason for hiding this comment

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

this code still makes haystack a direct dependency for running Ragas

Copy link
Member

Choose a reason for hiding this comment

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

I want you to write test that

  1. removes the haystack lib installed in the dev
  2. tries and imports the module

make sure it is failing

then refer to https://github.com/BerriAI/litellm/blob/5c2839a744814712b9fdeb1dec6609333743f8e9/litellm/llms/bedrock/base_aws_llm.py#L266

here you can see that they only import boto3 when they need it.

write something like that for haystack and make it pass

Copy link
Member

Choose a reason for hiding this comment

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

the failing test before the implementation is important. In order to test this we have to remove the haystack module already installed from python environment

Copy link
Member

@jjmachan jjmachan left a comment

Choose a reason for hiding this comment

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

just look into the last test?

Comment on lines 17 to 24
# Replace the built-in import function with our mock
monkeypatch.setattr(builtins, "__import__", mocked_import)

with pytest.raises(ImportError, match="Haystack is not installed"):
from ragas.llms import HaystackLLMWrapper

HaystackLLMWrapper(haystack_generator=None)

Copy link
Member

Choose a reason for hiding this comment

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

the test should check that we can import other modules too (like LangchainLLMWrapper, without any issues- that part is more important.

What I'm afraid is that because of some import Haystack will become a dependency

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added the test to ensures that:

  • No ImportError is raised for non-Haystack imports when haystack is missing.
  • The Haystack wrapper does raise ImportError in that scenario.

@jjmachan jjmachan merged commit 2bc29a2 into explodinggradients:main Feb 20, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants