Closed tonyaw closed 6 months ago
@jackgerrits @davorrunje
I found a workaround to skip the llm_config = copy.deepcopy(llm_config)
line of code.
import httpx
from autogen.oai.client import OpenAIWrapper
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
client = httpx.Client(verify=False, proxies=None)
mixtral_config_list = [
{
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"base_url": "X",
"api_key": "nopass",
"http_client": client,
"max_tokens": 5*1024,
}
]
#Setting llm_config to False below skips the the copy.deepcopy() line in at #https://github.com/microsoft/autogen/blob/main/autogen/agentchat/conversable_agent.py#L151
assistant = AssistantAgent("assistant", llm_config=False)
assistant.client = OpenAIWrapper(**llm_config)
user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding", "use_docker": False})
user_proxy.initiate_chat(assistant, message="Plot a chart of NVDA and TESLA stock price change YTD.")
Thanks @AbdurNawaz. Do you want to submit a fix for this in the constructor? We can check for the http_client key and avoid doing deep copy for that value.
cc @jackgerrits to take notice of this usage case for the experimental branch.
@ekzhu I'd love to submit a PR - do you think I should add a try/catch around copy.deepcopy
and skip it if it fails or just skip the copy if it has http_client?
@ekzhu @tonyaw I've created the PR #2579 , pease take a look.
@ekzhu @AbdurNawaz I don't think this warrants adding a special case in Autogen. http_client
might as well have some other value which is indeed meant to be cloned.
@tonyaw you can create your own HTTP client class which implements the __copy__
and __deepcopy__
methods, which in this case will just return the client object as is, since it can be shared across threads going by the httpx docs
An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc. It can be shared between threads.
Something like this:
class ShareOnCloneClient(httpx.Client):
def __copy__(self):
return self
def __deepcopy__(self, memo):
return self
I agree with @Gr3atWh173. @AbdurNawaz please ignore my comment above about checking for http_client. I think adding the __copy__
and __deepcopy__
methods should be the proper way to fix the issue.
Yes. ShareOnCloneClient works. The issue can be closed. Thanks for all your great support! :-)
Describe the bug
It is possible to pass a xhttp client to llm_config, like:
In this case, you will get following exception:
Steps to reproduce
Pass a "http_client" to llm_config.
Model Used
Any model that needs to be accessed with additional http_client configuration.
Expected Behavior
No exception is raised when I use llm_config with http_client.
Screenshots and logs
No response
Additional Information
No response