I made this script mainly targeted for nextcloud assistant because cloudflare provides Ai endpoints as openai API format for a good number of requests (almost for free) so why not use it instead of hosting our own instance of AI.
Request:
curl https://api.cloudflare.com/client/v4/accounts/{accountid}/ai/v1/models \
-H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXX"
Response:
{"result":null,"success":false,"errors":[{"code":7001,"message":"GET not supported for requested URI."}],"messages":[]}
This is because cloudflare doesn't provide /v1/models
in their API to solve this i created this script which returns the list of models from the list specified in main.py
and rest requests are directly passed to the cloudflare API.
2. Get account id and API key from cloudflare more info
docker run -d -e ACCOUNTID=XXXXXXXXXXXX -p 5050:5050 ghcr.io/sai80082/cf-ai:main
replace the XXXXXXXXXXXX
with the account id obtained from cloudflare
-
Go to administration settings -> Artificial intelligence
-
Under OpenAI and LocalAI integration change
Congratulations now you have AI in your nextcloud instace.
Beta models in cloudflare ai dont get counted towards your requests but cloudflare can move them to stable so be careful. you can find all the models here.
Contributions are most welcome like improving the documentation, adding new models to the list,etc