dify icon indicating copy to clipboard operation
dify copied to clipboard

completion-messages api got error

Open vkiller opened this issue 2 years ago • 6 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

official version

Cloud or Self Hosted

Cloud

Steps to reproduce

According https://github.com/langgenius/dify/blob/b1918dae5ecc4270266dcbcfad493f265d5f907a/web/app/components/develop/template/template.zh.mdx#L145

curl -X POST 'https://api.dify.ai/v1/completion-messages' \
--header 'Authorization: Bearer app-xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {
      "query": "Hello, world!"
    },
    "response_mode": "streaming",
    "user": "abc-123"
}'

Then got below

{"code": "app_unavailable", "message": "App unavailable, please check your app configurations.", "status": 400}

and post man also get the same error Screen Shot 2024-09-07 at 10 13 51 PM

✔️ Expected Behavior

should show response

❌ Actual Behavior

400 error

vkiller avatar Sep 07 '24 14:09 vkiller

I found a similar closed issue that might help. The issue 访问API返回: {"code": "invalid_param", "message": "not enough....."} was resolved by ensuring the Authorization header includes Bearer before the API key [1].

To resolve the "App unavailable, please check your app configurations" error when making a POST request to the https://api.dify.ai/v1/completion-messages endpoint, follow these steps:

  1. Check API Access Configuration:

    • Navigate to your application in the Dify dashboard.
    • Go to API Access in the left-side navigation.
    • Ensure that your application is properly configured and that you have the correct API key.
  2. Verify API Key:

    • Make sure you are using the correct API key in your request. The API key should be included in the Authorization header as shown in the example below:
curl -X POST 'https://api.dify.ai/v1/completion-messages' \
--header 'Authorization: Bearer app-xxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {
      "query": "Hello, world!"
    },
    "response_mode": "streaming",
    "user": "abc-123"
}'
  1. Ensure Application is Active:

    • Verify that your application is active and not in a disabled or inactive state.
  2. Check for Correct Endpoint Usage:

    • Ensure you are using the correct endpoint and that the request payload is properly formatted. The inputs parameter should contain the query key with the input text, and the response_mode should be either streaming or blocking.
  3. Check for Common Errors:

    • Ensure that your request does not trigger common errors such as invalid_param, provider_not_initialize, provider_quota_exceeded, model_currently_not_support, or completion_request_error.

By following these steps, you should be able to resolve the error and successfully make a POST request to the https://api.dify.ai/v1/completion-messages endpoint [2][3].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Sep 07 '24 14:09 dosubot[bot]

the two endpoint apis have some different, https://github.com/langgenius/dify-docs/blob/main/jp/guides/application-publishing/developing-with-apis.md and https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template.en.mdx

data = {
    "inputs": {"text": 'Hello, how are you?'},
    "response_mode": "streaming",
    "user": "abc-123"
}

parameter text or query?

but both got error

vkiller avatar Sep 07 '24 14:09 vkiller

For the completion-messages API endpoint, the correct parameter to use in the inputs field is text. Here is the correct usage:

{
  "inputs": {
    "text": "Hello, world!"
  },
  "response_mode": "streaming",
  "user": "abc-123"
}

If you are encountering errors with both text and query, ensure that you are using the correct endpoint and that your request body adheres to the required structure. The query parameter is used for the chat-messages endpoint, not completion-messages [1][2][3].

For the chat-messages endpoint, the correct parameter is query:

{
  "inputs": {},
  "query": "Hello, how are you?",
  "response_mode": "streaming",
  "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  "user": "abc-123"
}

Ensure you are using the correct endpoint and corresponding parameters to avoid errors.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Sep 07 '24 14:09 dosubot[bot]

As your guide above,Im sure got error

{
  "inputs": {
    "text": "Hello, world!"
  },
  "response_mode": "streaming",
  "user": "abc-123"
}

response

{
    "code": "app_unavailable",
    "message": "App unavailable, please check your app configurations.",
    "status": 400
}

Should be a bug. And also the doc should be clarified about query and text

vkiller avatar Sep 07 '24 22:09 vkiller

This error AppUnavailableError is raised 4 times in our code repo.

image
if app_model.mode != "completion":
    raise AppUnavailableError()

# And this one
except services.errors.app_model_config.AppModelConfigBrokenError:
            logging.exception("App model config broken.")
            raise AppUnavailableError()

So either you have chosen the wrong type of application, or the configuration is broken.

crazywoola avatar Sep 08 '24 05:09 crazywoola

This error AppUnavailableError is raised 4 times in our code repo.

image ``` if app_model.mode != "completion": raise AppUnavailableError()

And this one

except services.errors.app_model_config.AppModelConfigBrokenError: logging.exception("App model config broken.") raise AppUnavailableError()


So either you have chosen the wrong type of application, or the configuration is broken.

I use officail https://cloud.dify.ai/ service,form postman test it,what do you mean wrong type of application?also the configuration is working,because the chat api goes well

vkiller avatar Sep 08 '24 08:09 vkiller