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

Python: Does not support timeout in httpx. #6338

Closed
yuichiromukaiyama opened this issue May 20, 2024 · 5 comments
Closed

Python: Does not support timeout in httpx. #6338

yuichiromukaiyama opened this issue May 20, 2024 · 5 comments
Assignees
Labels
python Pull requests for the Python Semantic Kernel

Comments

@yuichiromukaiyama
Copy link
Contributor

Describe the bug
The following issue arises from using httpx as the HTTP client: it is not possible to change this parameter. The problem is that the default timeout duration is set to 5 seconds, which is relatively short. For instance, when an agent calls another agent or a RAG database, if it takes some time, the connection is quickly terminated. While a 5-second response time might be sufficient for general APIs, for generative AI, a longer timeout duration is often desirable.

AsIs:

response = await client.request(
    method=operation.method,
    url=url,
    headers=merged_headers,
    json=json.loads(payload) if payload else None,
)

To Reproduce
Steps to reproduce the behavior:

# Calling another agent. The response will take 5-10 seconds.
await kernel.add_plugin_from_openai(
    plugin_name="Example",
    plugin_url="http://localhost:3001/.well-known/ai-plugin.json",
)

settings.tool_choice = "auto"
settings.function_call_behavior = FunctionCallBehavior.AutoInvokeKernelFunctions()

history = ChatHistory()
history.add_user_message("please get current todos. user name is john.")

response = await service.get_chat_message_contents(
    chat_history=history,
    settings=settings,
    kernel=kernel,
    arguments=KernelArguments(settings=settings),
)

content = response[0]
print(content)

Expected behavior
To be able to set an appropriate timeout duration.

Screenshots
none

Platform

  • OS: Mac OS X
  • IDE: VS Code
  • Language: Python
  • Source: pip 23.2.1, Python 3.11.7, semantic kernel 1.0.0rc1

Additional context
ToBe: It would be beneficial to be able to pass arguments flexibly as shown below, or to have a sufficiently long timeout setting, or to be able to specify it through environment variables.

response = await client.request(
    method=operation.method,
    url=url,
    headers=merged_headers,
    json=json.loads(payload) if payload else None,
   **kwargs,
)
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel triage labels May 20, 2024
@moonbox3
Copy link
Contributor

@yuichiromukaiyama let me have a look today. It is possible to pass in a custom httpx.AsyncClient. Would that help your use case?

@moonbox3 moonbox3 self-assigned this May 20, 2024
@moonbox3 moonbox3 removed the triage label May 20, 2024
@yuichiromukaiyama
Copy link
Contributor Author

@moonbox3

Thank you! Yes, it would be helpful if we could change settings like timeout. In our use case, we are developing an agent that calls multiple RAGs and LLMs from the semantic kernel. When calling LLMs, especially through plugins, it can take a long time to get the initial response. These plugins can have slightly longer wait times, so being able to set timeouts ourselves would be extremely beneficial. Additionally, we are implementing a use case similar to Autogen, where one Agent (Semantic Kernel) calls another Agent (Semantic Kernel). In such cases, having a longer timeout would be beneficial as well.

@moonbox3
Copy link
Contributor

@yuichiromukaiyama please go ahead and configure your custom httpx.AsyncClient as part of the OpenAPIFunctionExecutionParameters. That will give you the flexability to set the timeout and any other properties on the client. That client is passed all the way to the run_operation's fetch method.

@moonbox3
Copy link
Contributor

Closing this as a custom httpx.AsyncClient can be configured and passed through to the fetch method.

@yuichiromukaiyama
Copy link
Contributor Author

Sorry. I didn't realize the feature existed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
Archived in project
Development

No branches or pull requests

3 participants