常见问题#

Q: 如何指定文件(例如数据库)存储的目录?#

A: 你可以通过在运行应用程序时设置--appdir参数来指定文件存储的目录。例如,autogenstudio ui --appdir /path/to/folder。这将会将数据库(默认)和其他文件存储在指定的目录中,例如/path/to/folder/database.sqlite

问:我可以在AutoGen Studio中使用其他模型吗?#

是的。AutoGen 标准化了 OpenAI 模型 API 格式,您可以使用任何提供 OpenAI 兼容端点的 API 服务器。

AutoGen Studio基于声明式规范,这也适用于模型。代理可以包含一个model_client字段,该字段指定模型端点详细信息,包括modelapi_keybase_urlmodel type。注意,你可以在Python中定义你的model client并将其转储为JSON文件以在AutoGen Studio中使用。

在以下示例中,我们将定义一个OpenAI、AzureOpenAI和一个本地模型客户端,并使用python将它们转储到json文件中。

from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
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())

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"),
    )
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"
  }
}

有像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"
    },
    "base_url": "http://localhost:1234/v1"
  }
}

注意

在为自定义模型添加模型客户端规范时,重要的是要包含model_info字段。这是框架正确实例化和使用模型所必需的。此外,AssistantAgent以及AgentChat中的许多其他代理都要求模型具备function_calling功能。

问:服务器已启动,但我无法访问用户界面#

A: 如果您在远程机器上运行服务器(或无法正确解析localhost的本地机器),您可能需要指定主机地址。默认情况下,主机地址设置为localhost。您可以使用--host 参数来指定主机地址。例如,要在端口8081和本地地址上启动服务器,以便可以从网络上的其他机器访问它,您可以运行以下命令:

autogenstudio ui --port 8081 --host 0.0.0.0

问:如何将AutoGen Studio与不同的数据库一起使用?#

A: 默认情况下,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 psycopg2pip 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)

Q: 我可以在 Docker 容器中运行 AutoGen Studio 吗?#

A: 是的,您可以在 Docker 容器中运行 AutoGen Studio。您可以使用提供的 Dockerfile 构建 Docker 镜像,并使用以下命令运行容器:

FROM python:3.10

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