Closed pangzixiang closed 1 month ago
PR #1456
I don't think this is a bug, try to remove the final "/" from the base url
I don't think this is a bug, try to remove the final "/" from the base url
no, we can't. I did try before, and found retrofit would validate the base url and throw exception if the base url not ends with "/".
and for this issue, here is the reference from the source code https://github.com/square/retrofit/blob/trunk/retrofit%2Fsrc%2Fmain%2Fjava%2Fretrofit2%2FRetrofit.java#L570-L594. I think the root cause is we are not using retrofit in a correct way.
I could replicate it but this problem happens only if your base url has an additional path like "http://example.com/ollama-api". I believe the PR is not suitable because would fail other cases like "http://example.com" when there is no need for "/" in the end of the url, did you run the tests? Probably should have another solution for this problem instead of removing the slash of the OllamaApi
I could replicate it but this problem happens only if your base url has an additional path like "http://example.com/ollama-api". I believe the PR is not suitable because would fail other cases like "http://example.com" when there is no need for "/" in the end of the url, did you run the tests? Probably should have another solution for this problem instead of removing the slash of the OllamaApi
yes, i have run all the tests, and tried few new tests for different base url in my branch:
http://example.com retrofit would automatically convert to http://example.com/
http://example.com/ happy case
http://example.com/path throw IllegalArgumentException, as the base url with additonal path must end in /
http://example.com/path/ happy case
Actually, the examples in the retrofit2 document also showing that the first slash is no need.
I think it is best to maintain OllamaApi convention of using the beginning slash for defining the endpoints. Maybe change something in OllamaClient, If it doesnt work maybe there is something in Retrofit we can try.
I think it is best to maintain OllamaApi convention of using the beginning slash for defining the endpoints. Maybe change something in OllamaClient, If it doesnt work maybe there is something in Retrofit we can try.
No, we can't do anything as this is the behavior of Retrofit. And this issue is only related to how we use Retrofit. What we can do is just to follow the doc to use Retrofit in standard way.
Endpoint values which contain a leading / are absolute.
Absolute values retain only the host from baseUrl and ignore any specified path components.
Base URL: http://example.com/api/
Endpoint: /foo/bar/
Result: http://example.com/foo/bar/
Base URL: http://example.com/
Endpoint: /foo/bar/
Result: http://example.com/foo/bar/
Is there any reason why you want to keep the leading slash?
Is there any reason why you want to keep the leading slash?
I thought lc4j was using this convention, but I took a look there are not many classes (probably they will require this change too), I think this is ok, only would suggest adding some tests, also you could add the same idea of OpenAiClient that appends the trailing slash when it doesn't exists, so "http://example.com/path" would not fail.
Is there any reason why you want to keep the leading slash?
I thought lc4j was using this convention, but I took a look there are not many classes (probably they will require this change too), I think this is ok, only would suggest adding some tests, also you could add the same idea of OpenAiClient that appends the trailing slash when it doesn't exists, so "http://example.com/path" would not fail.
test cases added (as I am not able to config the base url of ollama dev container, I use mock server to test it), and the same logic of OpenAiClient applied to OllamaClient.
Describe the bug The value of the APIs path in OllamaApi.class is wrong, which are starting with '/'. Therefore, if the baseUrl ends with path, like http://host:port/ollama-api/, the retrofit2 would ignore the path and the final URL would become http://host:port/api/chat. According to the retrofit2 document, we should remove the '/' at the beginning to fix this bug!!!
Log and Stack trace
To Reproduce
Expected behavior
Please complete the following information: