Skip to content

Conversation

@habuma
Copy link
Member

@habuma habuma commented Aug 31, 2023

Spring AI currently is fixed on using the official OpenAI URL when working with OpenAI. This makes it impossible to use Spring AI against a locally running OpenAI API such as LocalAI.

This PR exposes a new property (spring.ai.openai.base-url) that allows for custom configuration of the base URL. It still defaults to the official OpenAI API, though.

For example, to use this with a locally running LocalAI listening on port 8080, the following entry can be added to the application.properties file:

spring.ai.openai.base-url=http://localhost:8080/ 
@Bean
public OpenAiService theoOpenAiService(OpenAiProperties openAiProperties) {
if (!StringUtils.hasText(openAiProperties.getApiKey())) {
throw new IllegalArgumentException(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to only force an API key if the URL was anything other than the default base URL (maybe that's too complex or nondeterministic)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen two cases of model hosting projects that expose the OpenAI API locally and do not require a key. I think we can remove the requirement for a key when the base url is not https://api.openai.com and see how it goes.

@markpollack
Copy link
Member

I have merged this, just adding a comment that the underlying library will likely add this support as they have an open issue for it. I also enforced the use of the API KEY only if the baseUrl is pointing to api.openai.com

commit; 0218069

Thanks for the contribution.

@markpollack markpollack closed this Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants