mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-14 13:49:21 +03:00
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633 We added an optional parameter to choose different AI models for providers (like 'text-bison' for provider 'google', 'text-davinci-003' for provider 'openai', etc.). Usage: ```python llm = EdenAI( feature="text", provider="google", params={ "model": "text-bison", # new "temperature": 0.2, "max_tokens": 250, }, ) ``` You can also change the provider + model after initialization ```python llm = EdenAI( feature="text", provider="google", params={ "temperature": 0.2, "max_tokens": 250, }, ) prompt = """ hi """ llm(prompt, providers='openai', model='text-davinci-003') # change provider & model ``` The jupyter notebook as been updated with an example well. Ping: @hwchase17, @baskaryan --------- Co-authored-by: RedhaWassim <rwasssim@gmail.com> Co-authored-by: sam <melaine.samy@gmail.com>
4.2 KiB
4.2 KiB
In [ ]:
export EDENAI_API_KEY="..."In [1]:
from langchain.embeddings.edenai import EdenAiEmbeddingsIn [12]:
embeddings = EdenAiEmbeddings(edenai_api_key="...",provider="...")In [13]:
embeddings = EdenAiEmbeddings(provider="openai")In [14]:
docs = ["It's raining right now", "cats are cute"]
document_result = embeddings.embed_documents(docs)In [15]:
query = "my umbrella is broken"
query_result = embeddings.embed_query(query)In [16]:
import numpy as np
query_numpy = np.array(query_result)
for doc_res, doc in zip(document_result, docs):
document_numpy = np.array(doc_res)
similarity = np.dot(query_numpy, document_numpy) / (
np.linalg.norm(query_numpy) * np.linalg.norm(document_numpy)
)
print(f'Cosine similarity between "{doc}" and query: {similarity}')Cosine similarity between "It's raining right now" and query: 0.849261496107252 Cosine similarity between "cats are cute" and query: 0.7525900655705218