spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/index.html
Apache License 2.0
2.52k stars 608 forks source link

Review how URLs are composed in AI model clients to allow flexibility to change the version field in the URL path. #670

Open markpollack opened 2 months ago

markpollack commented 2 months ago

Several of the AI model implementations add /v1/<path-to-functionality> to the base url. For example the base url in OpenAiConnectionProperties is https://api.openai.com. The class OpenAIApi adds the path but hardcodes the /v1 part.

restClient.post().uri("/v1/chat/completions")

This is done in other AI API implementations. If there is a need to switch to a future v2 then we would need a code change.

Maybe we should make this a configuration property or some other way so that adopting to new versions of endpoints does not require a code change.

this issue was driven by a comment that the official Python api for openai attached assigns api.openai.com/v1 as the base url.

markpollack commented 2 months ago

After thinking about it, is also likely that a v2 of the endpoint would have a different api so a different implementation class would be needed and that is where the v2 should be added to the base url.

So we should keep everything the way it is and follow the correct definition of what is a base url.

The base url strictly speaking is api.openai.com , see https://developer.mozilla.org/en-US/docs/Web/API/URL/URL and other libraries (like the official Python client for open ai) that add “v1” to the base url is wrong. Those libraries will need to likely remove the v1 from their wrongly assigned base url variable once there is a v2.