常见问题#
问:如何指定文件(例如数据库)的存储目录?#
答:您可以通过在运行应用程序时设置--appdir参数来指定文件存储目录。例如,autogenstudio ui --appdir /path/to/folder。这会将数据库(默认)和其他文件存储在指定的目录中,例如/path/to/folder/database.sqlite。
问:我可以在 AutoGen Studio 中使用其他模型吗?#
可以。AutoGen 采用 OpenAI 模型 API 格式标准化,您可以使用任何提供符合 OpenAI 规范的端点的 API 服务器。
AutoGen Studio 基于声明性规范,这也适用于模型。代理可以包含一个 model_client 字段,该字段指定模型端点详细信息,包括 model、api_key、base_url、model type。请注意,您可以在 Python 中定义您的模型客户端,并将其转储为 JSON 文件以供 AutoGen Studio 使用。
在以下示例中,我们将定义一个 OpenAI、一个 AzureOpenAI 和一个本地模型客户端,并将它们转储到 JSON 文件中。
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from autogen_ext.models.anthropic import AnthropicChatCompletionClient
from autogen_core.models import ModelInfo
model_client=OpenAIChatCompletionClient(
model="gpt-4o-mini",
)
print(model_client.dump_component().model_dump_json())
az_model_client = AzureOpenAIChatCompletionClient(
azure_deployment="{your-azure-deployment}",
model="gpt-4o",
api_version="2024-06-01",
azure_endpoint="https://{your-custom-endpoint}.openai.azure.com/",
api_key="sk-...",
)
print(az_model_client.dump_component().model_dump_json())
anthropic_client = AnthropicChatCompletionClient(
model="claude-3-sonnet-20240229",
api_key="your-api-key", # Optional if ANTHROPIC_API_KEY is set in environment
)
print(anthropic_client.dump_component().model_dump_json())
mistral_vllm_model = OpenAIChatCompletionClient(
model="TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
base_url="https://:1234/v1",
model_info=ModelInfo(vision=False, function_calling=True, json_output=False, family="unknown", structured_output=True),
)
print(mistral_vllm_model.dump_component().model_dump_json())
OpenAI
{
"provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
"component_type": "model",
"version": 1,
"component_version": 1,
"description": "Chat completion client for OpenAI hosted models.",
"label": "OpenAIChatCompletionClient",
"config": { "model": "gpt-4o-mini" }
}
Azure OpenAI
{
"provider": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
"component_type": "model",
"version": 1,
"component_version": 1,
"description": "Chat completion client for Azure OpenAI hosted models.",
"label": "AzureOpenAIChatCompletionClient",
"config": {
"model": "gpt-4o",
"api_key": "sk-...",
"azure_endpoint": "https://{your-custom-endpoint}.openai.azure.com/",
"azure_deployment": "{your-azure-deployment}",
"api_version": "2024-06-01"
}
}
Anthropic
{
"provider": "autogen_ext.models.anthropic.AnthropicChatCompletionClient",
"component_type": "model",
"version": 1,
"component_version": 1,
"description": "Chat completion client for Anthropic's Claude models.",
"label": "AnthropicChatCompletionClient",
"config": {
"model": "claude-3-sonnet-20240229",
"max_tokens": 4096,
"temperature": 1.0,
"api_key": "your-api-key"
}
}
有像 Ollama、vLLM 或 LMStudio 这样提供符合 OpenAI 规范的端点的本地模型服务器吗?您也可以使用它。
{
"provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
"component_type": "model",
"version": 1,
"component_version": 1,
"description": "Chat completion client for OpenAI hosted models.",
"label": "OpenAIChatCompletionClient",
"config": {
"model": "TheBloke/Mistral-7B-Instruct-v0.2-GGUF",
"model_info": {
"vision": false,
"function_calling": true,
"json_output": false,
"family": "unknown",
"structured_output": true
},
"base_url": "https://:1234/v1"
}
}
注意
重要的是,您需要为自定义模型的模型客户端规范添加 model_info 字段。框架会使用此字段正确实例化和使用模型。此外,AssistantAgent 和 AgentChat 中的许多其他代理都要求模型具有 function_calling 能力。
问:服务器启动了,但我无法访问 UI#
答:如果您在远程机器上运行服务器(或本地机器无法正确解析 localhost),您可能需要指定主机地址。默认情况下,主机地址设置为localhost。您可以使用--host <host>参数指定主机地址。例如,要在端口 8081 和本地地址上启动服务器,以便网络上的其他机器可以访问,您可以运行以下命令:
autogenstudio ui --port 8081 --host 0.0.0.0
问:如何在 AutoGen Studio 中使用不同的数据库?#
答:默认情况下,AutoGen Studio 使用 SQLite 作为数据库。但是,它使用 SQLModel 库,该库支持多种数据库后端。您可以使用 SQLModel 支持的任何数据库,例如 PostgreSQL 或 MySQL。要使用不同的数据库,您需要在运行应用程序时使用 --database-uri 参数指定数据库的连接字符串。示例连接字符串包括:
SQLite:
sqlite:///database.sqlitePostgreSQL:
postgresql+psycopg://user:password@localhost/dbnameMySQL:
mysql+pymysql://user:password@localhost/dbnameAzureSQL:
mssql+pyodbc:///?odbc_connect=DRIVER%3D%7BODBC+Driver+17+for+SQL+Server%7D%3BSERVER%3Dtcp%3Aservername.database.windows.net%2C1433%3BDATABASE%3Ddatabasename%3BUID%3Dusername%3BPWD%3Dpassword123%3BEncrypt%3Dyes%3BTrustServerCertificate%3Dno%3BConnection+Timeout%3D30%3B
然后,您可以使用指定的数据库 URI 运行应用程序。例如,要使用 PostgreSQL,您可以运行以下命令:
autogenstudio ui --database-uri postgresql+psycopg://user:password@localhost/dbname
注意:请确保为您选择的数据库安装相应的数据库驱动程序。
PostgreSQL:
pip install psycopg2或pip install psycopg2-binaryMySQL:
pip install pymysqlSQL Server/Azure SQL:
pip install pyodbcOracle:
pip install cx_oracle
问:我可以将我的代理工作流导出到 Python 应用程序中使用吗?#
可以。在团队构建器视图中,您可以选择一个团队并下载其规范。此文件可以使用 TeamManager 类导入到 Python 应用程序中。例如:
from autogenstudio.teammanager import TeamManager
tm = TeamManager()
result_stream = tm.run(task="What is the weather in New York?", team_config="team.json") # or wm.run_stream(..)
您还可以使用 load_component 方法将团队规范加载为 AgentChat 对象。
import json
from autogen_agentchat.teams import BaseGroupChat
team_config = json.load(open("team.json"))
team = BaseGroupChat.load_component(team_config)
问:我可以在 Docker 容器中运行 AutoGen Studio 吗?#
答:是的,您可以在 Docker 容器中运行 AutoGen Studio。您可以使用提供的 Dockerfile 构建 Docker 镜像,并使用以下命令运行容器:
FROM python:3.10-slim
WORKDIR /code
RUN pip install -U gunicorn autogenstudio
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
AUTOGENSTUDIO_APPDIR=/home/user/app
WORKDIR $HOME/app
COPY --chown=user . $HOME/app
CMD gunicorn -w $((2 * $(getconf _NPROCESSORS_ONLN) + 1)) --timeout 12600 -k uvicorn.workers.UvicornWorker autogenstudio.web.app:app --bind "0.0.0.0:8081"
建议使用 Gunicorn 作为应用程序服务器以提高性能。要使用 Gunicorn 运行 AutoGen Studio,您可以使用以下命令:
gunicorn -w $((2 * $(getconf _NPROCESSORS_ONLN) + 1)) --timeout 12600 -k uvicorn.workers.UvicornWorker autogenstudio.web.app:app --bind