mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
More improvements for component config (#4799)
* More improvements for component config * clean output * working dir * fix fstring * key error * remove mv
This commit is contained in:
@@ -20,9 +20,34 @@
|
||||
"\n",
|
||||
"## Usage\n",
|
||||
"\n",
|
||||
"If you have a component in Python ad want to get the config for it, simply call {py:meth}`~autogen_core.ComponentConfig.dump_component` on it. The resulting object can be passed back into {py:meth}`~autogen_core.ComponentLoader.load_component` to get the component back.\n",
|
||||
"If you have a component in Python and want to get the config for it, simply call {py:meth}`~autogen_core.ComponentConfig.dump_component` on it. The resulting object can be passed back into {py:meth}`~autogen_core.ComponentLoader.load_component` to get the component back.\n",
|
||||
"\n",
|
||||
"## Creating a component\n",
|
||||
"### Loading a component from a config\n",
|
||||
"\n",
|
||||
"To load a component from a config object, you can use the {py:meth}`~autogen_core.ComponentLoader.load_component` method. This method will take a config object and return a component object. It is best to call this method on the interface you want. For example to load a model client:\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from autogen_core.models import ChatCompletionClient\n",
|
||||
"\n",
|
||||
"config = {\n",
|
||||
" \"provider\": \"openai_model_client\",\n",
|
||||
" \"config\": {\"model\": \"gpt-4o\"},\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"client = ChatCompletionClient.load_component(config)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Creating a component class\n",
|
||||
"\n",
|
||||
"To add component functionality to a given class:\n",
|
||||
"\n",
|
||||
@@ -38,8 +63,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from __future__ import annotations\n",
|
||||
"\n",
|
||||
"from autogen_core import Component\n",
|
||||
"from pydantic import BaseModel\n",
|
||||
"\n",
|
||||
@@ -59,7 +82,7 @@
|
||||
" return Config(value=self.value)\n",
|
||||
"\n",
|
||||
" @classmethod\n",
|
||||
" def _from_config(cls, config: Config) -> MyComponent:\n",
|
||||
" def _from_config(cls, config: Config) -> \"MyComponent\":\n",
|
||||
" return cls(value=config.value)"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -40,9 +40,10 @@ def _type_to_provider_str(t: type) -> str:
|
||||
|
||||
|
||||
WELL_KNOWN_PROVIDERS = {
|
||||
"azure_client": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
|
||||
"azure_model_client": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
|
||||
"azure_openai_model_client": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
|
||||
"AzureOpenAIChatCompletionClient": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
|
||||
"openai_model_client": "autogen_ext.models.openai.OpenAIChatCompletionClient",
|
||||
"OpenAIChatCompletionClient": "autogen_ext.models.openai.OpenAIChatCompletionClient",
|
||||
}
|
||||
|
||||
|
||||
@@ -280,14 +281,16 @@ class Component(ComponentConfigImpl[ConfigT], ComponentLoader, Generic[ConfigT])
|
||||
if not hasattr(self, "component_type"):
|
||||
raise AttributeError("component_type not defined")
|
||||
|
||||
obj_config = self._to_config().model_dump()
|
||||
return ComponentModel(
|
||||
obj_config = self._to_config().model_dump(exclude_none=True)
|
||||
model = ComponentModel(
|
||||
provider=provider,
|
||||
component_type=self.component_type,
|
||||
version=self.component_version,
|
||||
component_version=self.component_version,
|
||||
description=None,
|
||||
config=obj_config,
|
||||
)
|
||||
return model
|
||||
|
||||
@classmethod
|
||||
def _from_config_past_version(cls, config: Dict[str, Any], version: int) -> Self:
|
||||
|
||||
Reference in New Issue
Block a user