-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
Add AI21Embeddings class text embeddings #2253
Merged
hwchase17
merged 9 commits into
langchain-ai:harrison/ai21-embeddings
from
LaloLalo1999:AI21Embeddings
Apr 3, 2023
Merged
Add AI21Embeddings class text embeddings #2253
hwchase17
merged 9 commits into
langchain-ai:harrison/ai21-embeddings
from
LaloLalo1999:AI21Embeddings
Apr 3, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds type annotations to the AI21Embeddings class in the langchain/langchain/embeddings/ai21.py file. The type annotations provide better readability and maintainability for the code, as well as help with type checking and documentation. This change addresses the linting errors identified in the previous pull request and ensures that the code adheres to the project’s coding standards.
This commit addresses the linting errors in the AI21Embeddings class by adding type annotations for the __enter__ and __exit__ methods. Additionally, it replaces the undefined 'client' attribute with the proper ai21.Completion.execute method call in the generate_embeddings method. These changes resolve the linting errors and ensure proper functionality of the AI21Embeddings class.
This commit fixes the remaining lint error by adding the missing type annotation for the `response` variable in the `generate_embeddings` method. This ensures that the code adheres to the type checking requirements, allowing for better maintainability and readability.
This commit adds the missing type annotations in ai21.py, specifically: 1. Importing additional typing hints: Any, Optional, and Dict. 2. Adding type annotations to the __exit__ method parameters. These changes improve the code's readability and type checking capabilities.
hwchase17
reviewed
Apr 1, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this! this should inherit from the existing embedding class, as that will make sure it exposes the right methods
- AI21Embeddings now inherits from the Embeddings base class. - Implemented the embed_documents and embed_query methods in AI21Embeddings. - Updated the import statement to include the Embeddings class from langchain.embeddings.base.
This commit reformats the ai21.py file using the black code formatter to ensure consistency with the project's coding style. Additionally, the AI21Embeddings class now inherits from the Embeddings base class, allowing for seamless integration with the existing embeddings infrastructure.
This commit addresses the linting issues found in the ai21.py file: 1. Removed an unused import (Dict) from the typing module. 2. Sorted and formatted the import block. These changes resolve the linting errors and improve the code quality.
This commit addresses the linting issues reported by the CI pipeline for the langchain/embeddings/ai21.py file. It includes: - Removing unused imports - Sorting and formatting import statements using isort - Ensuring proper indentation and formatting as per the project standards With these changes, the ai21.py file should now pass the lint checks and be ready for integration into the project.
Thanks for the corrections, now it should be working, finally passed the lint checks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds the AI21Embeddings class to the langchain/langchain/embeddings module, providing support for generating text embeddings using the AI21 language model. The new class offers a similar interface as the existing OpenAIEmbeddings class, making it easy to integrate into the existing codebase.
The AI21Embeddings class has the following main methods:
generate_embeddings(texts, model): Generates embeddings for a list of texts using the specified AI21 model.
get_similarity(text1, text2, model): Calculates the similarity between two texts using the specified AI21 model.
The implementation uses the AI21 Python SDK for interacting with the AI21 API and requires an API key for initialization. The class is designed to be flexible and easy to use, allowing users to switch between different AI21 models by simply providing the model name as an argument.
This PR addresses issue #85 and provides an alternative to the existing OpenAI-based text embeddings.
Please let me know if you have any questions or need further changes.