llama_index [Bug]:在OpenAIAgent中使用Azure Open AI时返回500模型错误,

zpgglvta  于 2个月前  发布在  其他
关注(0)|答案(4)|浏览(44)

Bug 描述

我正在使用Azure上的Open AI部署,当在OpenAIAgent聊天引擎中运行时,它几乎每次都返回HTTP/1.1 500 model_error
一些观察:

  1. 如果直接访问OpenAI,我的代理可以成功运行。
  2. 如果使用AzureOpenAI查询我的rag,它可以正常工作。
  3. 如果直接从Postman访问我的Azure部署,它可以成功运行。
  4. 我在使用llama_index 0.10.560.10.55时也遇到了同样的问题。
  5. 错误是不稳定的,5%的调用是成功的,但大多数都是失败的。

版本

0.10.55

重现步骤

这是我的设置:

llm = AzureOpenAI(model=model, deployment=AZURE_DEPLOYMENT_NAME, api_key=API_KEY, azure_endpoint=AZURE_OPENAI_ENDPOINT, api_version=OPENAI_API_VERSION)
    tool_service_context = ServiceContext.from_defaults(
        llm=llm,
        embed_model=embedding_model,
        node_parser=node_parser
    )

.
.
.
llm used in query engines for tools
.
.
.

    top_level_sub_tools = [
        QueryEngineTool(
            query_engine=engine1,
            metadata=ToolMetadata(
                name="engine1",
                description="""some description""".strip())
        ),
        QueryEngineTool(
            query_engine=engine2,
            metadata=ToolMetadata(
                name="engine2",
                description="""\some description here""".strip())
        )
    ]

chat_engine = AzureOpenAI(model=model, deployment=AZURE_DEPLOYMENT_NAME, api_key=API_KEY, azure_endpoint=AZURE_OPENAI_ENDPOINT, api_version=OPENAI_API_VERSION)

    tools = top_level_sub_tools + some_function_call_tools

chat_engine = OpenAIAgent.from_tools(
        tools=tools,
        llm=chat_llm,
        chat_history=chat_history,
        verbose=True,
        system_prompt=SYSTEM_MESSAGE_GENERIC.format(curr_date=curr_date)
    )

相关日志/回溯

2024-07-23 01:42:33,006 - INFO - HTTP Request: POST https://.....openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview "HTTP/1.1 500 model_error"
2024-07-23 01:42:33,007 - INFO - Retrying request to /chat/completions in 0.980118 seconds
2024-07-23 01:42:53,728 - INFO - HTTP Request: POST https://......openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview "HTTP/1.1 500 model_error"
2024-07-23 01:42:53,729 - INFO - Retrying request to /chat/completions in 1.512375 seconds
2024-07-23 01:43:15,511 - INFO - HTTP Request: POST https://......openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview "HTTP/1.1 500 model_error"
2024-07-23 01:43:15,512 - INFO - Retrying request to /chat/completions in 3.923435 seconds
2024-07-23 01:43:34,617 - INFO - HTTP Request: POST https://......openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview "HTTP/1.1 500 model_error"
error occurred in /chat endpoint: Error code: 500 - {'error': {'message': 'The server had an error processing your request. Sorry about that! You can retry your request, or contact us through an Azure support request at: https://go.microsoft.com/fwlink/?linkid=2213926 if you keep seeing this error. (Please include the request ID 77c0d6e4-150a-4b70-a132-3dfbec165c8e in your email.)', 'type': 'server_error', 'param': None, 'code': None}}
mfpqipee

mfpqipee1#

在进行了一些更多实验后,我在我的工具中填写了更多的详细信息。我的代理有两个 QueryEngineTool 工具,我发现当代理只包含一个时,一切都能成功运行。这种设置对于其他模型来说效果很好,但只有在 Azure 上才会遇到这个错误。如果我注解掉 top_level_sub_tools 中的任何一个 QueryEngineTool,一切就会按预期工作。这是我的设置:

llm = AzureOpenAI(model=model, deployment=AZURE_DEPLOYMENT_NAME, api_key=API_KEY, azure_endpoint=AZURE_OPENAI_ENDPOINT, api_version=OPENAI_API_VERSION)
    tool_service_context = ServiceContext.from_defaults(
        llm=llm,
        embed_model=embedding_model,
        node_parser=node_parser
    )
.
.
.
# and I'm creating query engine from each vector_index below like:
    filters = None

    if symbol_metadata is not None:
        metadata_filter: dict = {
            "metadata.symbol": symbol_metadata.symbol
        }
        filters = MetadataFilters.from_dict(metadata_filter)

    kwargs = {"similarity_top_k": similarity_top_k, "filters": filters}
    return index.as_query_engine(**kwargs)
.
.
.
    
   query_engine1_tools = [get_query_engine_tool(
        symbol_metadata=None, 
        index=vector_index1, 
        similarity_top_k=similarity_top_k,
        tool_name="name1",
        tool_description="description.")
    ]
    query_engine2_tools = [get_query_engine_tool(
        symbol_metadata=None, 
        index=vector_index2, 
        similarity_top_k=similarity_top_k,
        tool_name="name2",
        tool_description="description")
    ]

    response_synthesizer = get_custom_response_synth(service_context=tool_service_context, symbols=symbols_list)

   engine1 = SubQuestionQueryEngine.from_defaults(
        query_engine_tools=engine1_tools,
        service_context=tool_service_context,
        response_synthesizer=response_synthesizer,
        verbose=True,
        use_async=True 
    )

    engine2 = SubQuestionQueryEngine.from_defaults(
        query_engine_tools=engine2_tools,
        service_context=tool_service_context,
        response_synthesizer=response_synthesizer,
        verbose=True,
        use_async=True 
    )

    top_level_sub_tools = [
        QueryEngineTool(
            query_engine=engine1,
            metadata=ToolMetadata(
                name="engine1",
                description="""some description""".strip())
        ),
        QueryEngineTool(
            query_engine=engine2,
            metadata=ToolMetadata(
                name="engine2",
                description="""\some description here""".strip())
        )
    ]

chat_engine = AzureOpenAI(model=model, deployment=AZURE_DEPLOYMENT_NAME, api_key=API_KEY, azure_endpoint=AZURE_OPENAI_ENDPOINT, api_version=OPENAI_API_VERSION)

tools = top_level_sub_tools + some_function_call_tools

chat_engine = OpenAIAgent.from_tools(
        tools=tools,
        llm=chat_llm,
        chat_history=chat_history,
        verbose=True,
        system_prompt=SYSTEM_MESSAGE_GENERIC.format(curr_date=curr_date)
    )
pgx2nnw8

pgx2nnw82#

当使用两个 QueryEngineTool 工具时,与 Azure OpenAI 的 500 model_error 可能是由于超过了该工具描述的最大字符限制(1024个字符)。当将多个 QueryEngineTool 工具组合成一个 QueryPlanTool 时,它们的描述会被拼接在一起,这很容易超过这个限制。
要解决这个问题,您可以将工具描述移动到提示符中,而不是将其包含在工具元数据中。这种方法避免了工具描述的1024个字符限制。
以下是将工具描述移动到提示符的相关代码片段:

from llama_index.core.tools.types import ToolMetadata

introductory_tool_description_prefix = """\
This is a query plan tool that takes in a list of tools and executes a \
query plan over these tools to answer a query. The query plan is a DAG of query nodes.

Given a list of tool names and the query plan schema, you \
can choose to generate a query plan to answer a question.

The tool names and descriptions will be given alongside the query.
"""

# Modify metadata to only include the general query plan instructions
new_metadata = ToolMetadata(
    introductory_tool_description_prefix,
    query_plan_tool.metadata.name,
    query_plan_tool.metadata.fn_schema,
)
query_plan_tool.metadata = new_metadata

# Reconstruct concatenated query engine tool descriptions
tools_description = "\n\n".join(
    [
        f"Tool Name: {tool.metadata.name}\n"
        + f"Tool Description: {tool.metadata.description} "
        for tool in query_engine_tools
    ]
)

# Concatenate tool descriptions and query
query_planned_query = f"{tools_description}\n\nQuery: {query}"

response = agent.query(query_planned_query)
response

此解决方案确保工具描述包含在提示符中,避免了字符限制问题 1(https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/agent/openai_agent_lengthy_tools.ipynb)。
如果您需要进一步的帮助,@logan-markewich 可以提供额外的指导。

  • 要继续与 Dosu 交谈,请提及 @dosu。*
jk9hmnmh

jk9hmnmh3#

我认为这与OpenAI目前不稳定有关。对于这种错误,已经内置了重试机制,所以它已经通过了。

rsl1atfo

rsl1atfo4#

@logan-markewich 我也这么认为,或者至少在Azure上遇到了一些问题。但是如果我移除了QueryEngineTool中的任意一个,所有事情都一直正常工作。如果是OpenAI或Azure,我可能会在使用一个查询引擎工具时看到类似的错误,但只有在同时使用这两个工具时才会出现错误。

当我在代理中使用一个QueryEngineTool时,所有11个请求在Azure OpenAI部署中成功。

当我直接使用gpt-3.5与两个工具一起在代理中使用时,所有请求都成功:

2024-07-23 11:31:45,281 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"

非常奇怪的行为,错误仅限于多个查询引擎工具和Azure OpenAI部署。我还会查看dosubot提到的字符限制,并进行回复。
[编辑] 检查了代理中使用的查询引擎工具的描述大小,总字符数为553。

相关问题