nextcloud / integration_openai

OpenAI integration in Nextcloud
GNU Affero General Public License v3.0
49 stars 11 forks source link

OpenAI model configuration #2

Closed Dual-0 closed 1 year ago

Dual-0 commented 1 year ago

Hello,

I notice that the used text-davinci-003 model is hardcoded. It would be great to make the model configurable.

As shown in the OpenAI Blog we could use the cheaper ChatGPT model:

The ChatGPT model family we are releasing today, gpt-3.5-turbo, is the same model used in the ChatGPT product. It is priced at $0.002 per 1k tokens, which is 10x cheaper than our existing GPT-3.5 models. It’s also our best model for many non-chat use cases—we’ve seen early testers migrate from text-davinci-003 to gpt-3.5-turbo with only a small amount of adjustment needed to their prompts.

All available models are shown here.

Thanks in advance

julien-nc commented 1 year ago

Hi, the model is not hardcoded. If you're referring to https://github.com/julien-nc/integration_openai/blob/main/lib/AppInfo/Application.php#L26 it is just the default selected one.

If you expand the "Advanced options" in the picker modal, you'll see a model selector. The model list is obtained from the OpenAI API. This list includes gpt-3.5-turbo. Problem is that this model can't be used with the API endpoint currently used by this app. I'll check if it's possible to adjust the endpoint depending on the selected model.

Dual-0 commented 1 year ago

Hi, sorry I missed this. found the "Advanced options". Wouldn't it be good if you can set the default model in the admin section? Thanks for investigation because of the gpt-3.5-turbo model.

julien-nc commented 1 year ago

So the API must be used a bit differently with GPT models. It is now supported by this integration app. There's also a new admin setting to set the global default completion model. Also, the last used model is preselected when reopening the picker (this is user specific). This superseeds the global default.

Could you try v1.0.3-2-nightly?

Dual-0 commented 1 year ago

ohh that was quiet fast! v1.0.3-2-nightly is working very well.

Admin-Panel: image

Integration in Notes App: image

Text in Notes App: image

thanks for the quick implementation!

julien-nc commented 1 year ago

Thanks, that was a quick test as well!

Could you check the new image generation system is also working well? It used to return the direct link to the generated image. It now returns an internal link which has a preview.

Dual-0 commented 1 year ago

When I changed the model in the admin-section and switch to the notes app the model under "advanced options" is still gpt-3.5-turbo. I think the notes app remember the last used model. Is this a bug or a feature?

Part 2: Dall-E is working well too.

image

Result:

image

P.S.: where does the app save the pictures?

julien-nc commented 1 year ago

When I changed the model in the admin-section and switch to the notes app the model under "advanced options" is still gpt-3.5-turbo. I think the notes app remember the last used model. Is this a bug or a feature?

Like i said:

Also, the last used model is preselected when reopening the picker (this is user specific). This superseeds the global default.

Which means, the default model for a user who never used the picker is the one selected by the admin. But after it has been used once, the user's default model is the last used one.

Oh and the picker is independent from the Notes app, also each picker provider is independent from the picker. So the default completion provider is remembered by the OpenAI provider independently of where it's used.

where does the app save the pictures?

Thanks a lot for testing this :blue_heart:. The magic is that NC does not save the pictures. Only the "real" URL to the image is saved in NC's database. The internal links https://blabla.org/apps/integration_openai/i/HASH contain a hash which is kind of the key to get the real image URL in NC. To produce the link preview, NC reads the hash, gets the real image URL, gets the image and provides it as the preview. Your browser actually gets the image with a request to the NC server. I hope it's clear-ish.

PS: While I was reading the OpenAI doc again, I realized they added support for Whisper :tada: So it was quite quick to port what I did in the Replicate integration here and there we go: there's a new smart picker provider to use OpenAI's Whisper's speech-to-text transcription/translation. It would be awesome if you could try it (it's in v1.0.3-3-nightly)

Dual-0 commented 1 year ago

Thanks for clarification and your amazing work. Smart solution to save only the link in the DB.

Whisper Part: The record button doesn't work. Browser permissions are given. Nginx config is straight forward as shown in the nextcloud docs.

julien-nc commented 1 year ago

This is not related with your webserver config. The recording completely happens in the browser. It works fine on my side with latest Firefox and Chromium.

https://user-images.githubusercontent.com/11291457/227792247-bedc3aab-6ca5-46e6-afd4-40f3d646a05c.mp4

What happens on your side when you press the record button?

Dual-0 commented 1 year ago

The record button switches immediately its color and symbol from red back to white. Time is not running and nothing happend. I check this with chromium (Edge + Vivaldi) and on my Pixel (Vivaldi). I tested it within the notes app.

Thanks, that was a quick test as well!

Could you check the new image generation system is also working well? It used to return the direct link to the generated image. It now returns an internal link which has a preview.

Now the previous generated image can't be loaded. (loading circle) After a click on the loading circle its shows me this error:

<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:9f915471-f01e-0050-757d-60ffe4000000 Time:2023-03-27T07:28:51.8578866Z</Message>
<AuthenticationErrorDetail>Signature not valid in the specified time frame: Start [Sat, 25 Mar 2023 17:12:35 GMT] - Expiry [Sat, 25 Mar 2023 19:12:35 GMT] - Current [Mon, 27 Mar 2023 07:28:51 GMT]</AuthenticationErrorDetail>
</Error>
julien-nc commented 1 year ago

For the recording issue, I tried on multiple OS, multiple browsers and it's always working. I don't know what's happening on your side. Any error in the browser console? We can continue this discussion in another issue if you want.

For the images not being accessible anymore, it's on the OpenAI side. They apparently delete the generated images after a few days.