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

Add support for proxying open AI chat completion through cloud #148

Merged
merged 16 commits into from
Dec 16, 2023

Conversation

MrStashley
Copy link

@MrStashley MrStashley commented Dec 15, 2023

Screen Shot 2023-12-14 at 8 02 52 PM Added support for proxying open ai chat completion through cloud, this allows users to not have to specify their own openai token

If token is not set, chat completion will now be proxied through the cloud. You can unset your token through the UI.
the cloud uses the default model, currently "gpt-3.5-turbo".
It allows you to set max tokens and max choices parameter

If you don't have telemetry set to on, you cannot use this feature

-- CONSIDERATIONS --
For now, this is set to only hit our dev lambda server. When we deploy the completion code to our prod lambda server, we should add a check for is dev or prod

-- TESTING --
I tested with telemetry on and off, and confirmed that the correct error shows. I have tested the channel timeout and confirm that if the socket hangs, the channel will timeout and send an error, and then the terminal can continue as normal.

I have tested all of the standard code paths, confirmed that when token is set we will still do completion locally, and when token is not set we will do cloud completion. I confirmed that token can now be set to empty string, and it looks good in the ui (it goes back to "not set"). I have also checked socket failed to connect error.

There are some more unlikely error paths that I haven't checked because I didn't reproduce that error, like json decode, etc etc. I also haven't tested socket connect timeout error, but I expect these paths to work as described because the behavior is fairly standard

What do we think about the way I do testing? I can write unit tests in the future

@CLAassistant
Copy link

CLAassistant commented Dec 15, 2023

CLA assistant check
All committers have signed the CLA.

if opts.Model == "" {
return nil, fmt.Errorf("no openai model specified")
}
conn, _, err := websocket.DefaultDialer.Dial(AWSLambdaCentralWSAddr, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Use DialContext and we should set some sensible timeout value for connecting

Copy link
Author

Choose a reason for hiding this comment

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

Addressed, set a 20 second timeout

@sawka
Copy link
Member

sawka commented Dec 15, 2023

I'm thinking we should completely remove the non-streaming paths in the code. Not sure they are really useful. Can't think of a time when we wouldn't want to stream the results back?

@MrStashley
Copy link
Author

MrStashley commented Dec 15, 2023

High latency environments might want non streaming completion?
But even then streaming might be better?

web security considerations?
Not sure

I think removing it makes sense

@MrStashley MrStashley force-pushed the MrStashley-openai-cloud-completion branch from 8abde7e to 5d0dd32 Compare December 15, 2023 20:01
@MrStashley MrStashley marked this pull request as ready for review December 15, 2023 20:03
@MrStashley MrStashley force-pushed the MrStashley-openai-cloud-completion branch from 2175ae9 to 037c4b8 Compare December 15, 2023 20:07
}
cloudCompletionRequestConfig := sstore.OpenAICloudCompletionRequest{
Prompt: prompt,
MaxTokens: opts.MaxTokens,
Copy link
Author

Choose a reason for hiding this comment

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

I still let the user specify max tokens and max choices for the cloud, should I use the defaults instead or is this ok?

Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't let the user specify these. We should just set them in the cloud.

@@ -66,6 +67,10 @@ const TermFontSizeMax = 24

const TsFormatStr = "2006-01-02 15:04:05"

const OpenAIPacketTimeout = 10 * time.Second

const OpenAICloudCompletionTelemetryOffErrorMsg = "In order to protect against abuse, you must have telemetry turned on in order to use Wave's free AI features. If you do not want to turn telemetry on, you can still use Wave's AI features by adding your own OpenAI key in Settings. Note that when you use your own key, requests are not proxied through Wave's servers and will be sent directly to the OpenAI API."
Copy link
Member

Choose a reason for hiding this comment

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

nit: there's a few double spaces between sentences in this message

@sawka sawka merged commit 4ccd62f into main Dec 16, 2023
4 checks passed
@MrStashley MrStashley deleted the MrStashley-openai-cloud-completion branch February 15, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants