langchain AzureSearch矢量存储不支持访问令牌认证,建议修复,

uinbv5nw  于 3个月前  发布在  其他
关注(0)|答案(2)|浏览(45)

检查其他资源

  • 为这个问题添加了一个非常描述性的标题。
  • 使用集成搜索在LangChain文档中进行了搜索。
  • 使用GitHub搜索查找类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此错误。

示例代码

错误信息和堆栈跟踪(如有适用)

描述

AzureOpenAIEmbeddings和AzureChatOpenAI类接受一个azure_ad_token参数,而不是api_key。然而,AzureSearch在langchan社区库中不支持它。我通过从langchain社区复制粘贴AzureSearch并进行一些修改来解决这个问题:
BearerTokenCredential.py

from azure.core.credentials import TokenCredential
from azure.core.credentials import AccessToken
import time

In AzureSearch.py

class BearerTokenCredential(TokenCredential):
def init(self, token):
self._token = token

def get_token(self, *scopes, **kwargs):
    # The AccessToken expects the token and its expiry time in seconds.
    # Here we set the expiry to an hour from now.
    expiry = int(time.time()) + 3600
    return AccessToken(self._token, expiry)

是否有可能在langchain社区的下一个版本中包含它?

系统信息

7eumitmz

7eumitmz1#

我们也需要这个功能来完成一个项目。

igsr9ssn

igsr9ssn2#

在项目中遇到同样的问题,如果有这个功能会很好!

相关问题