When the OpenAI-API-compatible embeding model is added, the interface body format is incorrect, resulting in failure to pass the test #4650

Closed
opened 2026-02-21 18:07:23 -05:00 by yindo · 3 comments
Owner

Originally created by @JinCheng666 on GitHub (Jul 17, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • 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

This is the test request that is issued when the OpenAI-API-compatible embeding model is added. The input value should be an array ["ping"], not a string "ping".

Wrong body:

{'model': 'm3e', 'input': 'ping'}

Correct body:

{'model': 'm3e', 'input': ['ping']}

image

In the vectorization process of the knowledge base, the body transmitted by the interface is correct, and it is in the format of ["ping"]

✔️ Expected Behavior

Modify the test body for adding the OpenAI-API-compatible embeding model

Correct body:

{'model': 'm3e', 'input': ['ping']}

Actual Behavior

Wrong body:

{'model': 'm3e', 'input': 'ping'}

Originally created by @JinCheng666 on GitHub (Jul 17, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [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 This is the test request that is issued when the OpenAI-API-compatible embeding model is added. The input value should be an array ["ping"], not a string "ping". ### Wrong body: {'model': 'm3e', 'input': 'ping'} ### Correct body: {'model': 'm3e', 'input': ['ping']} ![image](https://github.com/user-attachments/assets/ec54b79c-49cc-4448-b404-99b5ce2bea84) In the vectorization process of the knowledge base, the body transmitted by the interface is correct, and it is in the format of ["ping"] ### ✔️ Expected Behavior Modify the test body for adding the OpenAI-API-compatible embeding model ### Correct body: {'model': 'm3e', 'input': ['ping']} ### ❌ Actual Behavior ### Wrong body: {'model': 'm3e', 'input': 'ping'}
yindo added the 🐞 bug label 2026-02-21 18:07:23 -05:00
yindo closed this issue 2026-02-21 18:07:23 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 17, 2024):

@JinCheng666 Hello there! I'm a bot here to help you with bug reports, answer questions, and assist you in becoming a contributor. If you need any help, feel free to ask!

To address the issue with the incorrect body format in the test for the OpenAI-API-compatible embedding model, you need to modify the test body to use the correct format. Here is the updated test code:

def test_invoke_model():
    model = OAICompatEmbeddingModel()

    result = model.invoke(
        model='m3e',
        credentials={
            'api_key': os.environ.get('OPENAI_API_KEY'),
            'endpoint_url': 'https://api.openai.com/v1/',
            'context_size': 8184
        },
        texts=[
            "ping"
        ],
        user="abc-123"
    )

    assert isinstance(result, TextEmbeddingResult)
    assert len(result.embeddings) == 1
    assert result.usage.total_tokens == 2

This change ensures that the input value is an array ["ping"] instead of a string "ping" [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jul 17, 2024): <!-- Greeting --> @JinCheng666 Hello there! I'm a bot here to help you with bug reports, answer questions, and assist you in becoming a contributor. If you need any help, feel free to ask! <!-- Answer --> To address the issue with the incorrect body format in the test for the OpenAI-API-compatible embedding model, you need to modify the test body to use the correct format. Here is the updated test code: ```python def test_invoke_model(): model = OAICompatEmbeddingModel() result = model.invoke( model='m3e', credentials={ 'api_key': os.environ.get('OPENAI_API_KEY'), 'endpoint_url': 'https://api.openai.com/v1/', 'context_size': 8184 }, texts=[ "ping" ], user="abc-123" ) assert isinstance(result, TextEmbeddingResult) assert len(result.embeddings) == 1 assert result.usage.total_tokens == 2 ``` This change ensures that the `input` value is an array `["ping"]` instead of a string `"ping"` <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/openai_api_compatible/test_text_embedding.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@JinCheng666 commented on GitHub (Jul 17, 2024):

Thank you for providing me with an idea, although the code location you said is not accurate, it is not far from the real location

Need to modify here:
dify/api/core/model_runtime/model_providers/openai_api_compatible/text_embedding/text_embedding.py
Near line 164:
payload = {
'input': ['ping'],
'model': model
}

@JinCheng666 commented on GitHub (Jul 17, 2024): Thank you for providing me with an idea, although the code location you said is not accurate, it is not far from the real location Need to modify here: dify/api/core/model_runtime/model_providers/openai_api_compatible/text_embedding/text_embedding.py Near line 164: payload = { 'input': ['ping'], 'model': model }
Author
Owner

@JinCheng666 commented on GitHub (Jul 17, 2024):

https://platform.openai.com/docs/api-reference/embeddings/create#embeddings-create-input
string and array are both allowed types

so i closed this issue.thx all guys.

@JinCheng666 commented on GitHub (Jul 17, 2024): https://platform.openai.com/docs/api-reference/embeddings/create#embeddings-create-input string and array are both allowed types so i closed this issue.thx all guys.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4650