FAQ#
问:如何指定存储文件(例如数据库)的目录?#
答:您可以通过在运行应用程序时设置 --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 中使用。
在以下示例中,我们将在 python 中定义 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="http://localhost: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": "http://localhost: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.sqlite
PostgreSQL:
postgresql+psycopg://user:password@localhost/dbname
MySQL:
mysql+pymysql://user:password@localhost/dbname
AzureSQL:
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-binary
MySQL:
pip install pymysql
SQL Server/Azure SQL:
pip install pyodbc
Oracle:
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