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

Cache models in a class attribute to avoid one network request per provider #133

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

julien-nc
Copy link
Member

@julien-nc julien-nc commented Sep 27, 2024

As OpenAI apparently has rate limit on the models endpoint, page loading and requests to /ocs/v2.php/apps/assistant/api/v1/task-types can be slowed down quite a bit because each provider gets the list of models to populate the enum value in their optional input shapes.

Thankfully they all use the same instance of OpenAiAPIService so the model request response can be simply cached in a class attribute.

@kyteinsky
Copy link
Contributor

This cache will be lost for different requests though, no? Different request -> new instance of the service. Would be better to use the local cache with userid in the key, what say you?
Also, with a timeout.

@julien-nc
Copy link
Member Author

This cache will be lost for different requests though, no?

Yes

Would be better to use the local cache with userid in the key, what say you?

With a local cache we can get outdated values. Even if the model list should not change very often, we can't be sure.

Also, with a timeout.

Timeout on what? The request to the models endpoint?

@julien-nc julien-nc merged commit a02bcd8 into main Sep 27, 2024
8 checks passed
@kyteinsky kyteinsky deleted the enh/noid/factorize-getmodels-per-service-instance branch September 27, 2024 14:40
@julien-nc julien-nc mentioned this pull request Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants