cloudflare / cloudflare-docs

Cloudflare’s documentation
https://developers.cloudflare.com
Creative Commons Attribution 4.0 International
2.95k stars 3.63k forks source link

Chat completions for ai worker models is broken #15116

Closed kittykatattack closed 3 months ago

kittykatattack commented 3 months ago

Existing documentation URL(s)

https://developers.cloudflare.com/ai-gateway/providers/workersai/

What changes are you suggesting?

The code that shows how access an Open AI compatible chat completion endpoint for ai workers is incorrect:

curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/workers-ai/v1/chat/completions \
 --header 'Authorization: Bearer {cf_api_token}' \
 --header 'Content-Type: application/json' \
 --data '{
      "model": "@cf/meta/llama-3-8b-instruct",
      "messages": [
        {
          "role": "user",
          "content": "What is Cloudflare?"
        }
      ]
    }
'

This consistently produces the following:

{"result":null,"success":false,"errors":[{"code":7009,"message":"Upstream service unavailable"}],"messages":[]}

Additional information

This works fine without issue using the same credentials:

curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/workers-ai/@cf/meta/llama-3-8b-instruct \
 --header 'Authorization: Bearer {cf_api_token}' \
 --header 'Content-Type: application/json' \
 --data '{"prompt": "What is Cloudflare?"}'
kodster28 commented 3 months ago

Howdy @kittykatattack, the current implementation works for me (just re-tested).

From the error message returned, it sounds like this might have been more of a bug with the current product endpoint. Mind re-trying and seeing if you're encountering the same issue?

github-actions[bot] commented 3 months ago

This issue was closed automatically because there has been no response from the original author. As it stands currently, we don't have enough information to take action. If you believe this issue was closed in error, a) apologies and b) open a new issue and reference this one in the body.