An error occurred during credentials validation: Session.request() got an unexpected keyword argument 'options' #5585

Closed
opened 2026-02-21 18:11:45 -05:00 by yindo · 2 comments
Owner

Originally created by @wmcde on GitHub (Sep 12, 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).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.8.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I encountered the following error message when deploying a Text Embedding model using ollama: An error occurred during credentials validation: Session. request() got an unexpected keyword argument 'options'. The previous version has been normal, but this issue occurred when I upgraded to the latest 0.8.0.
屏幕截图 2024-09-13 093643

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @wmcde on GitHub (Sep 12, 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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.8.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I encountered the following error message when deploying a Text Embedding model using ollama: An error occurred during credentials validation: Session. request() got an unexpected keyword argument 'options'. The previous version has been normal, but this issue occurred when I upgraded to the latest 0.8.0. ![屏幕截图 2024-09-13 093643](https://github.com/user-attachments/assets/baddfb48-d617-4e9e-b32b-6b6f3194a131) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 18:11:45 -05:00
yindo closed this issue 2026-02-21 18:11:45 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 12, 2024):

To resolve the error "Session.request() got an unexpected keyword argument 'options'" that occurs during credentials validation when deploying a Text Embedding model using Ollama in Dify version 0.8.0, you need to remove the 'options' keyword argument from the payload in the _invoke method.

Here is the corrected code snippet:

def _invoke(
    self, model: str, credentials: dict, texts: list[str], user: Optional[str] = None
) -> TextEmbeddingResult:
    """
    Invoke text embedding model

    :param model: model name
    :param credentials: model credentials
    :param texts: texts to embed
    :param user: unique user id
    :return: embeddings result
    """

    # Prepare headers and payload for the request
    headers = {"Content-Type": "application/json"}

    endpoint_url = credentials.get("base_url")
    if not endpoint_url.endswith("/"):
        endpoint_url += "/"

    endpoint_url = urljoin(endpoint_url, "api/embed")

    # get model properties
    context_size = self._get_context_size(model, credentials)

    inputs = []
    used_tokens = 0

    for text in texts:
        # Here token count is only an approximation based on the GPT2 tokenizer
        num_tokens = self._get_num_tokens_by_gpt2(text)

        if num_tokens >= context_size:
            cutoff = int(np.floor(len(text) * (context_size / num_tokens)))
            # if num tokens is larger than context length, only use the start
            inputs.append(text[0:cutoff])
        else:
            inputs.append(text)

    # Prepare the payload for the request
    payload = {"input": inputs, "model": model}

    # Make the request to the Ollama API
    response = requests.post(endpoint_url, headers=headers, data=json.dumps(payload), timeout=(10, 300))

    response.raise_for_status()  # Raise an exception for HTTP errors
    response_data = response.json()

    # Extract embeddings and used tokens from the response
    embeddings = response_data["embeddings"]
    embedding_used_tokens = self.get_num_tokens(model, credentials, inputs)
    used_tokens += embedding_used_tokens

    # calc usage
    usage = self._calc_response_usage(model=model, credentials=credentials, tokens=used_tokens)

    return TextEmbeddingResult(embeddings=embeddings, usage=usage, model=model)

By removing the "options": {"use_mmap": True} from the payload, the error should be resolved [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 12, 2024): <!-- Answer --> To resolve the error "Session.request() got an unexpected keyword argument 'options'" that occurs during credentials validation when deploying a Text Embedding model using Ollama in Dify version 0.8.0, you need to remove the 'options' keyword argument from the payload in the `_invoke` method. Here is the corrected code snippet: ```python def _invoke( self, model: str, credentials: dict, texts: list[str], user: Optional[str] = None ) -> TextEmbeddingResult: """ Invoke text embedding model :param model: model name :param credentials: model credentials :param texts: texts to embed :param user: unique user id :return: embeddings result """ # Prepare headers and payload for the request headers = {"Content-Type": "application/json"} endpoint_url = credentials.get("base_url") if not endpoint_url.endswith("/"): endpoint_url += "/" endpoint_url = urljoin(endpoint_url, "api/embed") # get model properties context_size = self._get_context_size(model, credentials) inputs = [] used_tokens = 0 for text in texts: # Here token count is only an approximation based on the GPT2 tokenizer num_tokens = self._get_num_tokens_by_gpt2(text) if num_tokens >= context_size: cutoff = int(np.floor(len(text) * (context_size / num_tokens))) # if num tokens is larger than context length, only use the start inputs.append(text[0:cutoff]) else: inputs.append(text) # Prepare the payload for the request payload = {"input": inputs, "model": model} # Make the request to the Ollama API response = requests.post(endpoint_url, headers=headers, data=json.dumps(payload), timeout=(10, 300)) response.raise_for_status() # Raise an exception for HTTP errors response_data = response.json() # Extract embeddings and used tokens from the response embeddings = response_data["embeddings"] embedding_used_tokens = self.get_num_tokens(model, credentials, inputs) used_tokens += embedding_used_tokens # calc usage usage = self._calc_response_usage(model=model, credentials=credentials, tokens=used_tokens) return TextEmbeddingResult(embeddings=embeddings, usage=usage, model=model) ``` By removing the `"options": {"use_mmap": True}` from the payload, the error should be resolved <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/ollama/text_embedding/text_embedding.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 12, 2024):

Please upgrade to v0.8.1 see https://github.com/langgenius/dify/pull/8252 for more details.

@crazywoola commented on GitHub (Sep 12, 2024): Please upgrade to v0.8.1 see https://github.com/langgenius/dify/pull/8252 for more details.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5585