-
Notifications
You must be signed in to change notification settings - Fork 276
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 #143
Open
dliubarskyi
wants to merge
3
commits into
main
Choose a base branch
from
migrate-openai-to-http-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 tasks
dliubarskyi
added a commit
to langchain4j/langchain4j
that referenced
this pull request
Feb 13, 2025
## Issue Closes #2468 ## Changes 1. This PR is a continuation of efforts started in #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
srnagar
pushed a commit
to srnagar/langchain4j
that referenced
this pull request
Feb 24, 2025
## 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a part of langchain4j/langchain4j#2529