Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配置Azure Openai时,只能使用GPT模型,不能使用embedding模型 #3827

Closed
mydreamworldpolly opened this issue Apr 21, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mydreamworldpolly
Copy link

问题描述 / Problem Description
配置Azure Openai时,只能使用GPT模型,不能使用embedding模型。只有OpenAI原版embedding模型的配置,没有Azure Openai的。

复现问题的步骤 / Steps to Reproduce

  1. 进入配置文件,notepad model_config.py,添加Azure Openai key, EMBEDDING_MODEL = "text-embedding-ada-002"
    "text-embedding-ada-002": Azure Openai key
  2. 执行 python init_database.py --recreate-vs
  3. 问题出现 / Problem occurs
    2024-04-21 17:02:41,700 - _base_client.py[line:986] - INFO: Retrying request to /embeddings in 0.989405 seconds
    2024-04-21 17:03:24,783 - _base_client.py[line:986] - INFO: Retrying request to /embeddings in 1.698303 seconds
    2024-04-21 17:04:08,597 - embeddings_api.py[line:39] - ERROR: Request timed out.
    AttributeError: 'NoneType' object has no attribute 'conjugate'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\polly\Langchain-Chatchat\init_database.py", line 107, in
folder2db(kb_names=args.kb_name, mode="recreate_vs", embed_model=args.embed_model)
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\migrate.py", line 121, in folder2db
kb.create_kb()
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 81, in create_kb
self.do_create_kb()
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_service\faiss_kb_service.py", line 51, in do_create_kb
self.load_vector_store()
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_service\faiss_kb_service.py", line 28, in load_vector_store
return kb_faiss_pool.load_vector_store(kb_name=self.kb_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_cache\faiss_cache.py", line 102, in load_vector_store
vector_store = self.new_vector_store(embed_model=embed_model, embed_device=embed_device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_cache\faiss_cache.py", line 60, in new_vector_store
vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True,distance_strategy="METRIC_INNER_PRODUCT")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly.pyenv\pyenv-win\versions\3.11.9\Lib\site-packages\langchain_core\vectorstores.py", line 508, in from_documents
return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly.pyenv\pyenv-win\versions\3.11.9\Lib\site-packages\langchain_community\vectorstores\faiss.py", line 959, in from_texts
embeddings = embedding.embed_documents(texts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 439, in embed_documents
return normalize(embeddings).tolist()
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly\Langchain-Chatchat\server\knowledge_base\kb_service\base.py", line 37, in normalize
norm = np.linalg.norm(embeddings, axis=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\polly.pyenv\pyenv-win\versions\3.11.9\Lib\site-packages\numpy\linalg\linalg.py", line 2582, in norm
s = (x.conj() * x).real
^^^^^^^^
TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable conjugate method

环境信息 / Environment Information

  • langchain-ChatGLM 版本/commit 号:(例如:v2.0.1 或 commit 123456) / langchain-ChatGLM version/commit number: (e.g., v2.0.1 or commit 123456)
  • 是否使用 Docker 部署(是/否):是 / Is Docker deployment used (yes/no): yes
  • 使用的模型(ChatGLM2-6B / Qwen-7B 等):ChatGLM-6B / Model used (ChatGLM2-6B / Qwen-7B, etc.): ChatGLM2-6B
  • 使用的 Embedding 模型(moka-ai/m3e-base 等):moka-ai/m3e-base / Embedding model used (moka-ai/m3e-base, etc.): moka-ai/m3e-base
  • 使用的向量库类型 (faiss / milvus / pg_vector 等): faiss / Vector library used (faiss, milvus, pg_vector, etc.): faiss
  • 操作系统及版本 / Operating system and version:
  • Python 版本 / Python version:
  • 其他相关环境信息 / Other relevant environment information:

附加信息 / Additional Information
添加与问题相关的任何其他信息 / Add any other information related to the issue.

@mydreamworldpolly mydreamworldpolly added the bug Something isn't working label Apr 21, 2024
Copy link

dosubot bot commented Apr 21, 2024

您遇到的问题可能是因为Azure OpenAI可能不直接支持"text-embedding-ada-002"模型,或者在配置和使用嵌入模型时存在问题。这里有一些步骤和建议可能帮助您解决这个问题:

  1. 检查模型支持:首先,确认Azure OpenAI是否支持"text-embedding-ada-002"模型。您可以通过Azure OpenAI的文档或API来列出可用的嵌入模型。

  2. 正确配置模型:确保您的配置文件正确设置了Azure OpenAI的密钥和模型名称。这可能涉及查看Azure OpenAI的SDK或API文档来了解如何正确配置模型。

  3. 实现嵌入功能:如果"text-embedding-ada-002"模型是支持的,您需要实现一个函数,该函数能够将文本发送到模型并接收嵌入。这通常涉及使用Azure OpenAI的API或SDK来进行网络请求。

  4. 错误处理和调试:添加适当的错误处理逻辑,以便在调用模型时能够捕获并处理错误。这可以帮助您诊断问题所在,例如API调用失败或返回的数据不是预期格式。

如果在尝试上述步骤后仍然遇到问题,可能需要联系Azure支持以获取更具体的帮助,或者检查是否有关于如何在Azure OpenAI平台上使用嵌入模型的最新指南或文档更新。

希望这些建议能帮助您解决问题。如果您有任何其他问题或需要更多帮助,请随时提问。

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@mydreamworldpolly
Copy link
Author

@dosu 实际上,Azure Openai支持这个模型,而且我在别的程序中使用很正常。但我没有在配置文件中发现输入模型名称、endpoint的地方。

Copy link

dosubot bot commented Apr 21, 2024

To address the issue with configuring the "text-embedding-ada-002" model in Azure OpenAI within your project, follow these refined steps:

  1. Azure API Configuration: Ensure you've correctly set up the Azure API settings in your project's configuration. This includes specifying deployment_name, resource_name, api_version, and api_key in the ONLINE_LLM_MODEL dictionary. The api_key is your Azure OpenAI API key, and resource_name is part of your endpoint URL that identifies your Azure resource.

  2. Model Configuration: The EMBEDDING_MODEL setting should correctly point to "text-embedding-ada-002". For Azure integration, ensure this model is supported and correctly referenced in your Azure API settings, not as a direct API key configuration.

  3. Network and Timeout Settings: If encountering timeouts, verify your network configuration and ensure your application can reach Azure services. Consider adjusting your application's timeout settings or the Azure API's timeout limit if possible.

  4. Error Handling: The TypeError you're experiencing might be due to incorrect data types in your configuration or code. Ensure all parameters (deployment_name, resource_name, api_version, api_key) are correctly typed as strings and that any data sent to the Azure API matches the expected format.

  5. Debugging: Enable detailed logging for both your application and Azure API requests. This can help pinpoint the exact cause of the TypeError and any timeout issues.

Make sure all changes are saved and test your setup again. For further guidance, you might want to refer to the example configuration file in the Langchain-Chatchat repository, specifically the model_config.py.example file, to ensure your configuration aligns with expected standards.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@zRzRzRzRzRzRzR zRzRzRzRzRzRzR self-assigned this May 5, 2024
@zRzRzRzRzRzRzR
Copy link
Collaborator

是的,因为没有这个API的接入

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants