-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
OpenAI: migrate to HttpClient #2529
Conversation
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ❌ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ❌ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ❌ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ❌ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ❌ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ❌ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ❌ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ❌ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ❌ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ❌ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ❌ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Click here to view this outdated comment. Please see my most recent comment below.Hi @dliubarskyi, thank you very much for your PR! ❤️ I'm a bot powered by Google AI Gemini gemini-2.0-flash-exp. The maintainers of LangChain4j will perform a thorough code review as soon as they can, but in the meantime, here’s a preliminary review from me. I hope you find it helpful.Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
Hi @dliubarskyi, thank you very much for your PR! ❤️ Potential IssuesPotential Breaking Changes
Potential Design Issues
Potential Bugs
TestingChanges in this PR are sufficiently tested: ✅ Suggested Positive Test Scenarios
Suggested Negative Test Scenarios
Suggested Corner Case Test Scenarios
DocumentationChanges in this PR are sufficiently documented: ✅ |
## Issue Closes langchain4j/langchain4j#2468 ## Change This PR is a part of langchain4j/langchain4j#2529 ## General checklist - [ ] There are no breaking changes - [x] I have added unit and/or integration tests for my change - [ ] The tests cover both positive and negative cases - [x] I have manually run all the unit and integration tests in the module I have added/changed, and they are all green - [x] I have added/updated the [documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs) - [x] I have added an example in the [examples repo](https://github.com/langchain4j/langchain4j-examples) (only for "big" features)
## Issue Closes langchain4j#2468 ## Changes 1. This PR is a continuation of efforts started in langchain4j#2413 2. When using `langchain4j-open-ai`, all `OpenAi*Model`s are now using `java.net.http.HttpClient` instead of OkHttp/Retrofit by default. You also have an option to [customize it or plug in any other HTTP client](https://docs.langchain4j.dev/tutorials/customizable-http-client). 3. When using `langchain4j-open-ai-spring-boot-starter`, all `OpenAi*Model`s are now using Spring's `RestClient` instead of OkHttp/Retrofit by default. You also have an option to [customize it or plug in any other HTTP client](https://docs.langchain4j.dev/tutorials/customizable-http-client). 4. `apiKey` is now optional for all `OpenAi*Model`s 5. `OpenAi*Model`s can now throw `dev.langchain4j.exception.HttpException` instead of `dev.ai4j.openai4j.OpenAiHttpException` 6. The default connect timeout is now 15 seconds instead of 60 for all `OpenAi*Model`s. The default read timeout stays the same (60 seconds). 7. To continue using the "demo" key, you now need to specify the `baseUrl` explicitly: ```java OpenAiChatModel model = OpenAiChatModel.builder() .baseUrl("http://langchain4j.dev/demo/openai/v1") .apiKey("demo") .build() ``` 8. If you are using `Proxy`, now you need to configure it directly on the HTTP client of your choice. For example, when using JDK's `HttpClient`: ```java HttpClient.Builder httpClientBuilder = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress("XXX.XXX.XXX.XXX", 1234))); OpenAiChatModel model = OpenAiChatModel.builder() .httpClientBuilder(JdkHttpClient.builder().httpClientBuilder(httpClientBuilder)) .apiKey(System.getenv("OPENAI_API_KEY")) .modelName("gpt-4o-mini") .build(); ``` This also means that all `langchain4j.open-ai.*-model.proxy.*` Spring Boot properties are not working any more. 9. `OpenAiEmbeddingModel`: removed default `modelName` (`TEXT_EMBEDDING_ADA_002`), please set it explicitly now 10. `OpenAiImageModel`: removed `withPersisting` and `persistTo` properties. Persisting images will not be supported any more. 11. `OpenAiLanguageModel` and `OpenAiStreamingLanguageModel`: removed default `modelName` (`GPT_3_5_TURBO_INSTRUCT`) and `temperature` (`0.7`), please set it explicitly now 12. `OpenAiModerationModel`: removed default `modelName` (`TEXT_MODERATION_LATEST`), please set it explicitly now 13. All the `OpenAi*Model` constructors are now accepting a builder object instead of all the properties 14. The `langchain4j-local-ai` module is now also using `java.net.http.HttpClient` instead of OkHttp/Retrofit as it depends on the `langchain4j-open-ai` module ## General checklist - [ ] There are no breaking changes - [X] I have added unit and/or integration tests for my change - [ ] The tests cover both positive and negative cases - [X] I have manually run all the unit and integration tests in the module I have added/changed, and they are all green - [X] I have manually run all the unit and integration tests in the [core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core) and [main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j) modules, and they are all green - [X] I have added/updated the [documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs) - [x] I have added an example in the examples repo: langchain4j/langchain4j-examples#143 - [x] I have added/updated Spring Boot starter: langchain4j/langchain4j-spring#113
## Issue Closes langchain4j#2468 ## Changes 1. This PR is a continuation of efforts started in langchain4j#2413 2. When using `langchain4j-open-ai`, all `OpenAi*Model`s are now using `java.net.http.HttpClient` instead of OkHttp/Retrofit by default. You also have an option to [customize it or plug in any other HTTP client](https://docs.langchain4j.dev/tutorials/customizable-http-client). 3. When using `langchain4j-open-ai-spring-boot-starter`, all `OpenAi*Model`s are now using Spring's `RestClient` instead of OkHttp/Retrofit by default. You also have an option to [customize it or plug in any other HTTP client](https://docs.langchain4j.dev/tutorials/customizable-http-client). 4. `apiKey` is now optional for all `OpenAi*Model`s 5. `OpenAi*Model`s can now throw `dev.langchain4j.exception.HttpException` instead of `dev.ai4j.openai4j.OpenAiHttpException` 6. The default connect timeout is now 15 seconds instead of 60 for all `OpenAi*Model`s. The default read timeout stays the same (60 seconds). 7. To continue using the "demo" key, you now need to specify the `baseUrl` explicitly: ```java OpenAiChatModel model = OpenAiChatModel.builder() .baseUrl("http://langchain4j.dev/demo/openai/v1") .apiKey("demo") .build() ``` 8. If you are using `Proxy`, now you need to configure it directly on the HTTP client of your choice. For example, when using JDK's `HttpClient`: ```java HttpClient.Builder httpClientBuilder = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress("XXX.XXX.XXX.XXX", 1234))); OpenAiChatModel model = OpenAiChatModel.builder() .httpClientBuilder(JdkHttpClient.builder().httpClientBuilder(httpClientBuilder)) .apiKey(System.getenv("OPENAI_API_KEY")) .modelName("gpt-4o-mini") .build(); ``` This also means that all `langchain4j.open-ai.*-model.proxy.*` Spring Boot properties are not working any more. 9. `OpenAiEmbeddingModel`: removed default `modelName` (`TEXT_EMBEDDING_ADA_002`), please set it explicitly now 10. `OpenAiImageModel`: removed `withPersisting` and `persistTo` properties. Persisting images will not be supported any more. 11. `OpenAiLanguageModel` and `OpenAiStreamingLanguageModel`: removed default `modelName` (`GPT_3_5_TURBO_INSTRUCT`) and `temperature` (`0.7`), please set it explicitly now 12. `OpenAiModerationModel`: removed default `modelName` (`TEXT_MODERATION_LATEST`), please set it explicitly now 13. All the `OpenAi*Model` constructors are now accepting a builder object instead of all the properties 14. The `langchain4j-local-ai` module is now also using `java.net.http.HttpClient` instead of OkHttp/Retrofit as it depends on the `langchain4j-open-ai` module ## General checklist - [ ] There are no breaking changes - [X] I have added unit and/or integration tests for my change - [ ] The tests cover both positive and negative cases - [X] I have manually run all the unit and integration tests in the module I have added/changed, and they are all green - [X] I have manually run all the unit and integration tests in the [core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core) and [main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j) modules, and they are all green - [X] I have added/updated the [documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs) - [x] I have added an example in the examples repo: langchain4j/langchain4j-examples#143 - [x] I have added/updated Spring Boot starter: langchain4j/langchain4j-spring#113
This is a part of langchain4j/langchain4j#2529
Issue
Closes #2468
Changes
langchain4j-open-ai
, allOpenAi*Model
s are now usingjava.net.http.HttpClient
instead of OkHttp/Retrofit by default. You also have an option to customize it or plug in any other HTTP client.langchain4j-open-ai-spring-boot-starter
, allOpenAi*Model
s are now using Spring'sRestClient
instead of OkHttp/Retrofit by default. You also have an option to customize it or plug in any other HTTP client.apiKey
is now optional for allOpenAi*Model
sOpenAi*Model
s can now throwdev.langchain4j.exception.HttpException
instead ofdev.ai4j.openai4j.OpenAiHttpException
OpenAi*Model
s. The default read timeout stays the same (60 seconds).baseUrl
explicitly:Proxy
, now you need to configure it directly on the HTTP client of your choice. For example, when using JDK'sHttpClient
:This also means that all
langchain4j.open-ai.*-model.proxy.*
Spring Boot properties are not working any more.9.
OpenAiEmbeddingModel
: removed defaultmodelName
(TEXT_EMBEDDING_ADA_002
), please set it explicitly now10.
OpenAiImageModel
: removedwithPersisting
andpersistTo
properties. Persisting images will not be supported any more.11.
OpenAiLanguageModel
andOpenAiStreamingLanguageModel
: removed defaultmodelName
(GPT_3_5_TURBO_INSTRUCT
) andtemperature
(0.7
), please set it explicitly now12.
OpenAiModerationModel
: removed defaultmodelName
(TEXT_MODERATION_LATEST
), please set it explicitly now13. All the
OpenAi*Model
constructors are now accepting a builder object instead of all the properties14. The
langchain4j-local-ai
module is now also usingjava.net.http.HttpClient
instead of OkHttp/Retrofit as it depends on thelangchain4j-open-ai
moduleGeneral checklist