Skip to content
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

[CHAT] Refactor ChatGPTProvider to use openai-java client #4556

Closed
wants to merge 2 commits into from

Conversation

bowenliang123
Copy link
Contributor

@bowenliang123 bowenliang123 commented Mar 18, 2023

Why are the changes needed?

  • use Java SDK openai-java for ChatGPT which is popular and listed in official website, https://github.com/TheoKanning/openai-java
  • Focus on lifecycle in ChatGPTProvider, and prevent handling lower-level concepts in details, like POJO mapping, HTTP request handling.
  • follow the changes from upstream changes from OpenAI

How was this patch tested?

  • Add some test cases that check the changes thoroughly including negative and positive cases if possible

  • Add screenshots for manual tests if appropriate

  • Run test locally before make a pull request

@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2023

Codecov Report

Merging #4556 (ecf1e2c) into master (06e69dd) will decrease coverage by 0.04%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master    #4556      +/-   ##
============================================
- Coverage     53.30%   53.26%   -0.04%     
  Complexity       13       13              
============================================
  Files           573      573              
  Lines         31493    31493              
  Branches       4237     4237              
============================================
- Hits          16786    16776      -10     
- Misses        13128    13135       +7     
- Partials       1579     1582       +3     

see 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bowenliang123 bowenliang123 changed the title Refactor ChatGPTProvider to use high-level API with openai-java SDK [CHAT] Refactor ChatGPTProvider to use high-level API with openai-java Mar 19, 2023
@pan3793
Copy link
Member

pan3793 commented Mar 19, 2023

Please check the following things:

  • it introduces new deps into Kyuubi binary tarball, thus LICENSE-binary and NOTICE-binary should be updated
  • the backend of retrofit should be okhttp, please make sure it does not create no-daemon threads which may block engine shutdown.

messages.addLast(new ChatMessage("user", q))
val completionRequest = ChatCompletionRequest.builder()
.messages(messages.asScala.toList.asJava)
.model("gpt-3.5-turbo")
Copy link
Member

Choose a reason for hiding this comment

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

let's make it configurable in next PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Make it configurable of other ChatCompletionRequest settings like model name, max tokens, etc.

@pan3793
Copy link
Member

pan3793 commented Mar 19, 2023

I remember that okhttp provides a mock server module for testing, we can add UT then.

@bowenliang123
Copy link
Contributor Author

Please check the following things:

  • it introduces new deps into Kyuubi binary tarball, thus LICENSE-binary and NOTICE-binary should be updated
  • the backend of retrofit should be okhttp, please make sure it does not create no-daemon threads which may block engine shutdown.

How can I update the LICENSE-binary and NOTICE-binary, in manual way or auto-collect by tools?

@bowenliang123
Copy link
Contributor Author

I remember that okhttp provides a mock server module for testing, we can add UT then.

Shall we do the ut in the next PR ?

@bowenliang123 bowenliang123 changed the title [CHAT] Refactor ChatGPTProvider to use high-level API with openai-java [CHAT] Refactor ChatGPTProvider to use openai-java SDK Mar 19, 2023
@bowenliang123 bowenliang123 changed the title [CHAT] Refactor ChatGPTProvider to use openai-java SDK [CHAT] Refactor ChatGPTProvider to use openai-java client Mar 19, 2023
@pan3793
Copy link
Member

pan3793 commented Mar 19, 2023

How can I update the LICENSE-binary and NOTICE-binary, in manual way or auto-collect by tools?

Currently, we should update them manually, we haven't found a tool smart enough to automatically process them.

@pan3793
Copy link
Member

pan3793 commented Mar 19, 2023

I remember that okhttp provides a mock server module for testing, we can add UT then.

Shall we do the ut in the next PR ?

it's fine.

@github-actions github-actions bot added the kind:infra license, community building, project builds, asf infra related, etc. label Mar 19, 2023
Copy link
Member

@pan3793 pan3793 left a comment

Choose a reason for hiding this comment

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

LGTM, linked in #4549

@bowenliang123
Copy link
Contributor Author

image

Locally tested with the packaged tarball. Works properly as before refactoring, with - message history in the context of session - HTTP proxy

@bowenliang123
Copy link
Contributor Author

Thanks, merged to master.

@bowenliang123 bowenliang123 self-assigned this Mar 19, 2023
@bowenliang123 bowenliang123 added this to the v1.8.0 milestone Mar 19, 2023
@bowenliang123 bowenliang123 deleted the chatgpt-third branch March 19, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:build kind:infra license, community building, project builds, asf infra related, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants