dify icon indicating copy to clipboard operation
dify copied to clipboard

Error: argument should be a bytes-like object or ASCII string, not 'list'

Open lem0ke opened this issue 1 year ago • 5 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] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.14

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Deployed using docker and with the .env file properly configured, after updating from 0.6.11 to 0.6.14, both the recall test of the knowledgebase and the test into the previously created app report an error:[openai] Error: argument should be a bytes-like object or ASCII string, not 'list'. After opening debug mode, part of the log for container api-1 is as follows:

Running migrations
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
Preparing database migration...
Start database migration.
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
Database migration successful!
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
 * Serving Flask app 'app.py'
 * Debug mode: on
2024-07-18 15:34:12,233.233 INFO [MainThread] [_internal.py:97] - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5001
 * Running on http://172.25.0.7:5001
2024-07-18 15:34:12,233.233 INFO [MainThread] [_internal.py:97] - [33mPress CTRL+C to quit[0m
2024-07-18 15:34:12,237.237 INFO [MainThread] [_internal.py:97] -  * Restarting with stat
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
2024-07-18 15:34:23,267.267 WARNING [MainThread] [_internal.py:97] -  * Debugger is active!
2024-07-18 15:34:23,267.267 INFO [MainThread] [_internal.py:97] -  * Debugger PIN: 429-943-275
2024-07-18 15:35:52,569.569 INFO [Thread-3 (embedding_search)] [_client.py:1026] - HTTP Request: POST https://api.holdai.top/v1/embeddings "HTTP/1.1 200 OK"
2024-07-18 15:35:52,900.900 ERROR [Thread-2 (process_request_thread)] [hit_testing.py:82] - Hit testing failed.
Traceback (most recent call last):
  File "/app/api/controllers/console/datasets/hit_testing.py", line 56, in post
    response = HitTestingService.retrieve(
  File "/app/api/services/hit_testing_service.py", line 41, in retrieve
    all_documents = RetrievalService.retrieve(retrival_method=retrieval_model['search_method'],
  File "/app/api/core/rag/datasource/retrieval_service.py", line 87, in retrieve
    raise Exception(exception_message)
Exception: [openai] Error: argument should be a bytes-like object or ASCII string, not 'list'
2024-07-18 15:35:52,902.902 ERROR [Thread-2 (process_request_thread)] [app.py:838] - Exception on /console/api/datasets/b648cd21-5e6d-423a-8038-a78c6f8f89d6/hit-testing [POST]
Traceback (most recent call last):
  File "/app/api/controllers/console/datasets/hit_testing.py", line 56, in post
    response = HitTestingService.retrieve(
  File "/app/api/services/hit_testing_service.py", line 41, in retrieve
    all_documents = RetrievalService.retrieve(retrival_method=retrieval_model['search_method'],
  File "/app/api/core/rag/datasource/retrieval_service.py", line 87, in retrieve
    raise Exception(exception_message)
Exception: [openai] Error: argument should be a bytes-like object or ASCII string, not 'list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
  File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/app/api/controllers/console/setup.py", line 74, in decorated
    return view(*args, **kwargs)
  File "/app/api/libs/login.py", line 91, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/app/api/controllers/console/wraps.py", line 21, in decorated
    return view(*args, **kwargs)
  File "/app/api/controllers/console/datasets/hit_testing.py", line 83, in post
    raise InternalServerError(str(e))
werkzeug.exceptions.InternalServerError: 500 Internal Server Error: [openai] Error: argument should be a bytes-like object or ASCII string, not 'list'
2024-07-18 15:35:52,904.904 INFO [Thread-2 (process_request_thread)] [_internal.py:97] - 172.25.0.9 - - [18/Jul/2024 15:35:52] "[35m[1mPOST /console/api/datasets/b648cd21-5e6d-423a-8038-a78c6f8f89d6/hit-testing HTTP/1.1[0m" 500 -

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

lem0ke avatar Jul 18 '24 15:07 lem0ke

Hello @lem0ke! I'm here to help you with any bugs, questions, or contributions you might have.

The error message "[openai] Error: argument should be a bytes-like object or ASCII string, not 'list'" suggests that a list is being passed where a string or bytes-like object is expected. This typically occurs when interacting with the OpenAI API.

To resolve this issue, follow these steps:

  1. Check Environment Variables: Ensure that all environment variables related to the OpenAI API are correctly set and are strings. For example, OPENAI_API_BASE should be a string URL.

  2. Inspect the Code: Look at the part of the code where the OpenAI API is called and ensure that the arguments passed are of the correct type. If a list is being passed, convert it to a string or bytes-like object.

  3. Update Configuration: If there are any new configuration options or changes in the new version (0.6.14), make sure to update your configuration accordingly.

Here is an example of how you might correct the data type issue in Python:

import openai

# Example of incorrect usage
# response = openai.Completion.create(prompt=["This is a list"], ...)

# Correct usage
response = openai.Completion.create(prompt="This is a string", ...)

Ensure that the prompt parameter is a string and not a list.

If the issue persists, you may need to review the specific changes between versions 0.6.11 and 0.6.14 to identify any changes that could affect the data types being passed to the OpenAI API [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jul 18 '24 15:07 dosubot[bot]

Same issue with version 0.6.14, but the issue is only for openai embedding model.

1WorldCapture avatar Jul 19 '24 08:07 1WorldCapture

How do I temporarily restore my app? Right now it hasn't been working properly because of the issue

lem0ke avatar Jul 21 '24 04:07 lem0ke

If you are using a third-party openai service , pls use the open-ai compatible . Because for openai embedding service, we are using base64 as the response type to improve return speed , but the thrid-party doesn't suppport. @lem0ke @1WorldCapture image

JohnJyong avatar Jul 22 '24 08:07 JohnJyong

If you are using a third-party openai service , pls use the open-ai compatible . Because for openai embedding service, we are using base64 as the response type to improve return speed , but the thrid-party doesn't suppport. @lem0ke @1WorldCapture image

But this is available in 0.6.11.The configuration of OpenAI-API-compatible is cumbersome and error-prone, and is not suitable for novice users.

lem0ke avatar Jul 22 '24 10:07 lem0ke

image

I met the same problem. I have done a testing which I found the error occur only when I choose an openai embedding model. hope you guys of dify to fixed it as quickly as possible.

my Dify's version is 0.6.15, the lastest version in recently

rnthking avatar Jul 31 '24 10:07 rnthking

image I met the same problem. I have done a testing which I found the error occur only when I choose an openai embedding model. hope you guys of dify to fixed it as quickly as possible.

my Dify's version is 0.6.15, the lastest version in recently

I have the same error when I use the DIFY.

zcunyi avatar Aug 29 '24 06:08 zcunyi

I've tried using OpenAI compatible entry and still got the same error. Any option to switch off base64 optimization?

Clouder0 avatar Sep 08 '24 19:09 Clouder0

same issue

tonycky avatar Sep 11 '24 17:09 tonycky

Encountered the same issue when using OpenAI compatible API.

jtsang4 avatar Sep 12 '24 21:09 jtsang4