I would like to know if it is possible to use openai.ChatCompletion.create and openai.Embedding.create in the same app.
I have seen that OpenRouter does not work for openai.Embedding.create with model text-embedding-ada-002.
Therefore I thought about trying to use OpenRouter key with the openai/gpt-4-32k model for openai.ChatCompletion.create and OpenAI key with the text-embedding-ada-002 model for openai.Embedding.create.
However, I keep getting HTTP code 405 from API when trying to create the Embedding.
My best guess is that since openai.api_base is set to use OpenRouter, then when trying to use openai key to create the embedding, the request is invalid
You can reproduce with the following code:
#openai.api_base = "https://openrouter.ai/api/v1" # not working in here
openai.api_key = os.environ.get("OPEN_AI_KEY") # using open ai key
response = openai.Embedding.create(
input=text,
model="text-embedding-ada-002",
)
# output: HTTP code 405 from API ()
In a different file:
openai.api_base = "https://openrouter.ai/api/v1"
openai.api_key = os.environ.get("OPENROUTER_API_KEY")
res = openai.ChatCompletion.create(
model="openai/gpt-4-32k",
messages=messages,
temperature=temp_var,
headers={
'HTTP-Referer': ${OPENROUTER_REFERRER},
"X-Title": ${OPENROUTER_TITLE},
},
)
# ...