多智能体协作之 AutoGen Studio

news2024/9/20 22:57:24

目录

一、AutoGen Studio 安装

二、AutoGen Studio 使用

2.1 Skills

2.1.1 generate_and_save_images

2.1.2 generate_and_save_pdf

2.2 Models

2.3 Agents

2.4 Workflows

 2.5 Playground


本文主要对 AutoGen Studio 进行介绍。

一、AutoGen Studio 安装

通过 pip 进行安装,默认会安装 AutoGen。

pip install autogenstudio

如果无法通过 pip 安装,可以下载 autogenstudio 安装包,手动安装(点击下载安装包)。

pip install autogenstudio-0.1.4-py3-none-any.whl

指定端口,运行 AutoGen Studio。 

autogenstudio ui --port 8081 --host 0.0.0.0

运行界面如下所示,目前是 Beta 版,有些 bug。

 运行参数说明。

--host <host> :指定主机地址,默认是本机地址(localhost);
--appdir <appdir> : 指定存储应用程序文件(例如:数据库和生成的用户文件)的目录。默认情况下,设置为用户主目录中的 .autogenstudio 目录;
--port <port> : 指定端口号。默认情况下为 8080;
--reload :用于在代码发生更改时启用服务器的自动重新加载。默认情况下,它设置为 False;
--database-uri :指定数据库 URI,示例值包括 SQLite 的 sqlite:///database.sqlite 和 PostgreSQL 的 postgresql+psycopg://user:password@localhost/dbname。如果未指定,数据库 URIL 默认为 --appdir 目录中的 database.sqlite 文件。

二、AutoGen Studio 使用

下面对 AutoGen Studio 具体使用进行说明。

2.1 Skills

这个部分是定义 Agent 能够调用的 python 函数。

默认定义了两个函数,一个是根据问题生成图片,一个是根据问题生成 pdf 报告。

2.1.1 generate_and_save_images

左侧是具体代码,右侧是函数名称和描述等。

上图左侧代码部分。 


from typing import List
import uuid
import requests  # to perform HTTP requests
from pathlib import Path

from openai import OpenAI


def generate_and_save_images(query: str, image_size: str = "1024x1024") -> List[str]:
    """
    Function to paint, draw or illustrate images based on the users query or request. Generates images from a given query using OpenAI's DALL-E model and saves them to disk.  Use the code below anytime there is a request to create an image.

    :param query: A natural language description of the image to be generated.
    :param image_size: The size of the image to be generated. (default is "1024x1024")
    :return: A list of filenames for the saved images.
    """

    client = OpenAI()  # Initialize the OpenAI client
    response = client.images.generate(model="dall-e-3", prompt=query, n=1, size=image_size)  # Generate images

    # List to store the file names of saved images
    saved_files = []

    # Check if the response is successful
    if response.data:
        for image_data in response.data:
            # Generate a random UUID as the file name
            file_name = str(uuid.uuid4()) + ".png"  # Assuming the image is a PNG
            file_path = Path(file_name)

            img_url = image_data.url
            img_response = requests.get(img_url)
            if img_response.status_code == 200:
                # Write the binary content to a file
                with open(file_path, "wb") as img_file:
                    img_file.write(img_response.content)
                    print(f"Image saved to {file_path}")
                    saved_files.append(str(file_path))
            else:
                print(f"Failed to download the image from {img_url}")
    else:
        print("No image data found in the response!")

    # Return the list of saved files
    return saved_files


# Example usage of the function:
# generate_and_save_images("A cute baby sea otter")

2.1.2 generate_and_save_pdf

左侧是具体代码,右侧是函数名称和描述等。

上图左侧代码部分。

import uuid
import requests
from fpdf import FPDF
from typing import List, Dict, Optional
from pathlib import Path
from PIL import Image, ImageDraw, ImageOps
from io import BytesIO

def generate_and_save_pdf(
    sections: List[Dict[str, Optional[str]]], 
    output_file: str = "report.pdf", 
    report_title: str = "PDF Report"
) -> None:
    """
    Function to generate a beautiful PDF report in A4 paper format. 

    :param sections: A list of sections where each section is represented by a dictionary containing:
                     - title: The title of the section.
                     - level: The heading level (e.g., "title", "h1", "h2").
                     - content: The content or body text of the section.
                     - image: (Optional) The URL or local path to the image.
    :param output_file: The name of the output PDF file. (default is "report.pdf")
    :param report_title: The title of the report. (default is "PDF Report")
    :return: None
    """

    def get_image(image_url_or_path):
        if image_url_or_path.startswith("http://") or image_url_or_path.startswith("https://"):
            response = requests.get(image_url_or_path)
            if response.status_code == 200:
                return BytesIO(response.content)
        elif Path(image_url_or_path).is_file():
            return open(image_url_or_path, 'rb')
        return None

    def add_rounded_corners(img, radius=6):
        mask = Image.new('L', img.size, 0)
        draw = ImageDraw.Draw(mask)
        draw.rounded_rectangle([(0, 0), img.size], radius, fill=255)
        img = ImageOps.fit(img, mask.size, centering=(0.5, 0.5))
        img.putalpha(mask)
        return img

    class PDF(FPDF):
        def header(self):
            self.set_font("Arial", "B", 12)
            self.cell(0, 10, report_title, 0, 1, "C")
            
        def chapter_title(self, txt): 
            self.set_font("Arial", "B", 12)
            self.cell(0, 10, txt, 0, 1, "L")
            self.ln(2)
        
        def chapter_body(self, body):
            self.set_font("Arial", "", 12)
            self.multi_cell(0, 10, body)
            self.ln()

        def add_image(self, img_data):
            img = Image.open(img_data)
            img = add_rounded_corners(img)
            img_path = Path(f"temp_{uuid.uuid4().hex}.png")
            img.save(img_path, format="PNG")
            self.image(str(img_path), x=None, y=None, w=190 if img.width > 190 else img.width)
            self.ln(10)
            img_path.unlink()

    pdf = PDF()
    pdf.add_page()
    font_size = {"title": 16, "h1": 14, "h2": 12, "body": 12}

    for section in sections:
        title, level, content, image = section.get("title", ""), section.get("level", "h1"), section.get("content", ""), section.get("image")
        pdf.set_font("Arial", "B" if level in font_size else "", font_size.get(level, font_size["body"]))
        pdf.chapter_title(title)

        if content: pdf.chapter_body(content)
        if image:
            img_data = get_image(image)
            if img_data:
                pdf.add_image(img_data)
                if isinstance(img_data, BytesIO):
                    img_data.close()

    pdf.output(output_file)
    print(f"PDF report saved as {output_file}")

# # Example usage
# sections = [
#     {
#         "title": "Introduction - Early Life",
#         "level": "h1",
#         "image": "https://picsum.photos/536/354",
#         "content": ("Marie Curie was born on 7 November 1867 in Warsaw, Poland. "
#                     "She was the youngest of five children. Both of her parents were teachers. "
#                     "Her father was a math and physics instructor, and her mother was the head of a private school. "
#                     "Marie's curiosity and brilliance were evident from an early age."),
#     },
#     {
#         "title": "Academic Accomplishments",
#         "level": "h2",
#         "content": ("Despite many obstacles, Marie Curie earned degrees in physics and mathematics from the University of Paris. "
#                     "She conducted groundbreaking research on radioactivity, becoming the first woman to win a Nobel Prize. "
#                     "Her achievements paved the way for future generations of scientists, particularly women in STEM fields."),
#     },
#     {
#         "title": "Major Discoveries",
#         "level": "h2",
#         "image": "https://picsum.photos/536/354",
#         "content": ("One of Marie Curie's most notable discoveries was that of radium and polonium, two radioactive elements. "
#                     "Her meticulous work not only advanced scientific understanding but also had practical applications in medicine and industry."),
#     },
#     {
#         "title": "Conclusion - Legacy",
#         "level": "h1",
#         "content": ("Marie Curie's legacy lives on through her contributions to science, her role as a trailblazer for women in STEM, "
#                     "and the ongoing impact of her discoveries on modern medicine and technology. "
#                     "Her life and work remain an inspiration to many, demonstrating the power of perseverance and intellectual curiosity."),
#     },
# ]

# generate_and_save_pdf_report(sections, "my_report.pdf", "The Life of Marie Curie")

2.2 Models

创建可以在代理和工作流中重复使用的模型配置,默认提供了四个模型的配置例子,如下所示。

模型配置参数包括模型名称、URL、 API Key 等,如下所示。

2.3 Agents

配置可以在 Agent 工作流程中重复使用的 Agent,可以创建一个 Agent 组(群聊),可以有多个 Agent。

Agent 配置参数。 

2.4 Workflows

工作流其实是一种编排,默认有两个工作流,一个是默认工作流(两个Agent),一个是旅行计划工作流(一个用户代理Agent,一个群聊Agent)。

 当然,可以自行设计工作流。

 2.5 Playground

创建 Session,选择工作流,如下所示。

参考链接:

[1] https://github.com/microsoft/autogen

[2] User Guide | AutoGen

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1990772.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

PCIe 物理尺寸和形状

PCIe 物理尺寸和形状 1. PCIe Riser (PCIe 插槽)2. Riser 卡与 PCIe 卡2.1. PCIe 卡尺寸 3. Form factors (规格&#xff0c;物理尺寸和形状)4. Peripheral Component Interconnect Express (PCI Express, PCIe or PCI-e)5. HHHL and FHHL5.1. HHHL DPU Layout and Interface I…

TM1652段码屏芯片全解析——概况,性能,MCU连接,样例代码

首先&#xff0c;作为四年前就有的LED段码控制芯片&#xff0c;相关的资料及样例程序少的可怜。硬件驱动 作为固定使用的 软件资源&#xff0c;其共享性远低于软件领域的驱动库。人的才智不应浪费在这种不具创造性的重复实验上。 要点总结&#xff1a; TM1652概述&#xff1a…

k-means算法原理

1 算法简介 k-means&#xff08;k均值&#xff09;算法由不同学者于20世纪50-60年代在不同领域提出的一种聚类算法。随后该算法不断得到了改进&#xff0c;成为了一种非常广泛应用的聚类算法。k-means算法是将样本按距离划分为k个簇的一种聚类算法。 2 算法的基本原理 2.1 相…

TypeError: Cannot read property ‘xxx‘ of undefined

1.首先贴出控制台的报错信息 2.从报错信息看的一脸疑惑&#xff0c;xxx属性或方法确实定义了&#xff0c;引入后怎么就报错了&#xff0c;一开始还怀疑是小程序缓存导致的&#xff0c;清理缓存重新编译还是报错&#xff0c;然后怀疑是分包导致的&#xff0c;后来看到我的代码是…

一、stm32在cubemx配置硬件crc与rng测试演示

一、crc配置 1、配置crc界面 2、crc主要调用的函数 这两个都可以生成crc&#xff0c;存在一些区别&#xff0c;但都可以生成crc其结果都是一样的。 二、rng配置 1、rng配置的界面 2、rng生成函数 这三个函数都可以生成随机数&#xff0c;其中开启中断后可调用回调函数&am…

在Linux中宏观的看待线程

线程一旦被创建&#xff0c;几乎所有的资源都是被所有的线程共享的。线程也一定要有自己私有的资源&#xff0c;什么样的资源应该是线程私有的&#xff1f; 1.PCB属性私有 2.要有一定的私有上下文结构 3.每个线程都要有独立的栈结构 ps -aL ##1. Linux线程概念 ###什么是线程…

深度学习每周学习总结N6:使用Word2vec实现文本分类

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 | 接辅导、项目定制 目录 0. 总结&#xff1a;1.加载数据2. 构建词典3. 生成数据批次和迭代器4.模型搭建及初始化5. 定义训练与评估函数6. 拆分数据集并运行模…

界面控件(无ui文件)

目录 菜单栏 工具栏 状态栏 停靠部件和核心部件 菜单栏 MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {// 菜单栏&#xff0c;获取当前窗口的菜单栏&#xff0c;没有会自动创建一个QMenuBar *mb this->menuBar();// 添加菜单QMenu *menuFile mb-&g…

【ML】Pre-trained Language Models及其各种微调模型的实现细节和特点

Pre-trained Language Models及其各种微调模型的实现细节和特点 1. Pre-trained Language Models2. semi-supervised Learning3. zero-shot4. Parameter-Efficient Fine-Tuning4.1 含义&#xff1a;4.2 实现方式&#xff1a; 5. LoRA5.1 LoRA 的主要特点&#xff1a;5.2 LoRA 的…

【QT 5 QT 6 构建工具qmake-cmake-和-软件编译器MSVCxxxvs MinGWxxx说明】

【QT 5报错&#xff1a;/xxx/: error: ‘class Ui::frmMain’ has no member named ‘xxx’-和-软件编译器MSVCxxxvs MinGWxxx说明】 1、前言2 、qt 中 Qmake CMake 和 QBS1-qmake2-Cmake3-QBS4-官网一些说法5-各自特点 3、软件编译套件1-Desktop Qt 6.7.2 llvm-mingw 64-bit2-…

SpringBoot排除默认日志框架

默认用的logback application.properties中的配置无需改变,自动装配会根据条件(哪个日志的.class是否存在) 进行切换 只要切换日志配置文件就好 比如原来使用的logback-spring.xml换成log4j2-spring.xml 日志文件网上找找

Flink-DataWorks第三部分:数据集成(第59天)

系列文章目录 2.4 任务配置方式 2.4.1 DataStudio侧离线同步 2.4.1.1 开发流程概览 2.4.1.2 步骤一&#xff1a;新建离线同步节点 2.4.1.3 步骤二&#xff1a;配置同步网络链接 2.4.1.4 步骤三&#xff1a;配置数据来源与去向 2.4.1.5 步骤四&#xff1a;配置字段映射关系 2.4…

C:野指针介绍(定义、危害、规避)以及野指针与空指针的区分

目录 1、野指针 1.1 野指针的成因 1.指针未初始化 2.指针越界访问 3.指针指向的空间释放 1.2 野指针的危害 1.3 如何规避野指针 1. 指针初始化 2. 小心指针越界 3.指针变量不使用就及时赋上NULL 4. 指针使用前检查是否是空指针 5. 避免返回局部变量的地址 1.4 区…

微信小程序【五】摇骰子

摇骰子 一、dice.js二、dice.json三、dice.wxml四、dice.wxss 效果简述&#xff1a;点击设置“骰子个数”&#xff0c;喝一杯前&#xff0c;先摇一摇。 骰子图片命名示例&#xff1a; 1.png、2.png 一、dice.js Page({data: {numDice: 1, // 初始化骰子数diceImages: [],dic…

【iOS多线程(二)】GCD其他方法详解

GCD其他方法 dispatch_semaphore &#xff08;信号量&#xff09;什么是dispatch_semaphore(信号量)?dispatch_semaphore主要的三个方法dispatch_semaphore主要作用线程安全线程同步 dispatch_afterdispatch_time_t 两种形式 GCD 一次性代码&#xff08;只执行一次&#xff09…

电脑维修店的主题源码 简洁wordpress企业主题模版下载

简洁wordpress企业主题&#xff0c;一个简洁的电脑维修店的主题 源码下载&#xff1a;https://download.csdn.net/download/m0_66047725/89612932 更多资源下载&#xff1a;关注我。

【深度学习】TTS,CosyVoice,推理部署的代码原理讲解分享

文章目录 demo代码加载配置文件speech_tokenizer_v1.onnx(只在zero_shot的时候使用)campplus.onnx(只为了提取说话人音色embedding)`campplus_model` 的作用代码解析具体过程解析总结示意图CosyVoiceFrontEndCosyVoiceModel推理过程总体推理过程推理速度很慢: https://git…

OpenNebula-6.9.80使用介绍

目录 准备&#xff1a;给宿主机添加一块网卡 1. 创建群组 2. 创建用户 3. 创建集群 4. 创建主机 5. 安全组 6. 网络模板 7. 虚拟网络 8. 导入镜像 9. 创建虚拟机模板 10. 实例化虚拟机 11. 卸载磁盘 12. 再次实例化 13. 添加新节点 14. 虚拟机迁移 准备&…

面壁的智能开源 MiniCPM-V 2.6 边缘人工智能多模态功能与 GPT-4V 不相上下

"MiniCPM-V2.6 "是一个边缘多模态人工智能模型&#xff0c;仅拥有 80 亿个参数&#xff0c;却在单图像、多图像和视频理解任务中取得了低于 200 亿个参数的三项 SOTA&#xff08;艺术境界&#xff09;成绩&#xff0c;显著增强了边缘多模态能力&#xff0c;并与 GPT-…

python.tkinter设计标记语言(转译2-html)

TOC 前言 本文只作为笔记记录。 前文我们已经通过TinText渲染器部分和TinML获得了test.tin解释后的标记内容列表。本文&#xff0c;我们将根据这个解释结果将Tin标记转为html文件。 转为html的好处 第一&#xff0c;Tin标记语言作为一个小小小小小项目&#xff0c;光把编写…