-
-
Save zilto/2ebb4d6c8375d19969473beb3ec27230 to your computer and use it in GitHub Desktop.
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
# functions from the same file; embedding_module.py | |
@config.when(embedding_service="openai") | |
def embeddings__openai( | |
embedding_provider: ModuleType, | |
text_contents: list[str], | |
model_name: str = "text-embedding-ada-002", | |
) -> list[np.ndarray]: | |
"""Convert text to vector representations (embeddings) using OpenAI Embeddings API | |
reference: https://github.com/openai/openai-cookbook/blob/main/examples/Get_embeddings.ipynb | |
""" | |
response = embedding_provider.Embedding.create(input=text_contents, engine=model_name) | |
return [np.asarray(obj["embedding"]) for obj in response["data"]] | |
@config.when(embedding_service="cohere") | |
def embeddings__cohere( | |
embedding_provider: cohere.Client, | |
text_contents: list[str], | |
model_name: str = "embed-english-light-v2.0", | |
) -> list[np.ndarray]: | |
"""Convert text to vector representations (embeddings) using Cohere Embed API | |
reference: https://docs.cohere.com/reference/embed | |
""" | |
response = embedding_provider.embed( | |
texts=text_contents, | |
model=model_name, | |
truncate="END", | |
) | |
return [np.asarray(embedding) for embedding in response.embeddings] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment