Best way to use an OpenAI-compatible embedding API #11809
-
Hello everyone! I'm using my own OpenAI-compatible embedding API, the runnable code: from llama_index.embeddings.openai import OpenAIEmbedding
emb_model = OpenAIEmbedding(
api_key="DUMMY_API_KEY",
api_base="http://192.168.0.1:8000",
model_name="intfloat/multilingual-e5-large",
)
emb = emb_model.get_text_embedding("hello world")
print(emb) But if I use the arg
I checked the code in class OpenAIEmbedding(BaseEmbedding):
...
def __init__(
...
self._query_engine = get_engine(mode, model, _QUERY_MODE_MODEL_DICT)
self._text_engine = get_engine(mode, model, _TEXT_MODE_MODEL_DICT)
if "model_name" in kwargs:
model_name = kwargs.pop("model_name")
self._query_engine = self._text_engine = model_name
else:
model_name = model So I'm not sure if it is a good idea to set the |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
Hey there @BeautyyuYanli! Good to see you back in the world of embeddings 🌐🦙 Based on the code and context you've provided, it seems like you're on the right track. Using the In the Here's the relevant part of the code from class OpenAIEmbedding(BaseEmbedding):
...
def __init__(
...
self._query_engine = get_engine(mode, model, _QUERY_MODE_MODEL_DICT)
self._text_engine = get_engine(mode, model, _TEXT_MODE_MODEL_DICT)
if "model_name" in kwargs:
model_name = kwargs.pop("model_name")
self._query_engine = self._text_engine = model_name
else:
model_name = model As for the documentation, I agree with you. It would be beneficial to have more detailed documentation about the usage of I hope this helps! If you have any more questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Greetings! Did you find the way to solve this issue? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
-
What if I created OpenAI-like web application with huggingface models? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
-
Did anyone find a solution to this problem? |
Beta Was this translation helpful? Give feedback.
-
I have found solution for OpenAI-compatible APIs. In my case it's LiteLLM as frontend and ollama as a backend api. Solution is just using langchain openai clients: from llama_index.embeddings.langchain import LangchainEmbedding
from llama_index.llms.langchain import LangChainLLM
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
embed_model = LangchainEmbedding(
langchain_embeddings=OpenAIEmbeddings(
model="snowflake-arctic-embed2:latest",
dimensions=1024,
base_url="http://127.0.0.1:4000",
api_key="key",
timeout=500,
),
)
llm = LangChainLLM(
llm=ChatOpenAI(
model="qwen2.5-coder:32b-instruct-q4",
base_url="http://127.0.0.1:4000",
api_key="key",
disable_streaming="tool_calling",
)
) Libs to install: pip install llama-index-embeddings-langchain
pip install llama-index-llms-langchain
pip install langchain_openai
pip install langchain
pip install langchain_community |
Beta Was this translation helpful? Give feedback.
-
@BeautyyuYanli @WinPooh32 @david1542 @juanluisrosaramos @vikrantdeshpande09876 Here's the non-langchain method for using openai-like API's
|
Beta Was this translation helpful? Give feedback.
@BeautyyuYanli @WinPooh32 @david1542 @juanluisrosaramos @vikrantdeshpande09876
Here's the non-langchain method for using openai-like API's