Skip to content
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

Allow Custom URL for OpenAI API #407

Closed
mooangus opened this issue Aug 2, 2023 · 7 comments · Fixed by #725
Closed

Allow Custom URL for OpenAI API #407

mooangus opened this issue Aug 2, 2023 · 7 comments · Fixed by #725

Comments

@mooangus
Copy link

mooangus commented Aug 2, 2023

It would be great if you allowed for a custom URL to be specified for OpenAI's API so we could use Azure OpenAI instance instead.

@jankieAI
Copy link

jankieAI commented Aug 2, 2023

or our own locally hosted endpoint like https://github.com/oobabooga/text-generation-webui

@sabaimran
Copy link
Collaborator

Ah, we can consider that. What would be the reason behind wanting to do that? I'm assuming because you've already gotten a subscription and want to use credits there or some equivalent?

@mooangus
Copy link
Author

Yes. That's correct. My organisation already uses Azure and I can use their end point at no personal cost. As noted by someone else, it would be great if it could just be a custom field to override the OpenAI default. That would allow any custom endpoint for the API.

@difhel
Copy link

difhel commented Oct 6, 2023

+1 for waiting that. It would be great to set a custom endpoint in /config.

@aleung
Copy link

aleung commented Dec 29, 2023

I checked the source code, Khoj uses langchain chat_models.openai.ChatOpenAI, which supports reading OpenAI API base url from environment OPENAI_API_BASE.

I've tried to add this environment into the docker compose file and it works.

@debanjum
Copy link
Member

debanjum commented Jan 1, 2024

Thanks a ton @aleung for looking into this! Glad that a simple change like updating the OPENAI_API_BASE environment variable works. I was able to reproduce this on my end as well using the LiteLLM proxy server and the Mistral API.

Let me update our docs with more complete instructions on how to use this soon.

@tupini07
Copy link

@mooangus I'm curious whether you actually managed to get the connection with Azure working after this change was implemented? Azure uses a different route for the endpoints than OpenAI, and I think there're also some difference in how the payload is built, so I was wondering if simply having the ability to change the URL allowed you to connect to Azure OpenAI?

Perhaps there's some more change necessary to support this: the openai package provides a specific constructor for AzureOpenAI clients. This page highlights the differences between the two https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants