Skip to content

Latest commit

 

History

History
136 lines (102 loc) · 5.38 KB

README.md

File metadata and controls

136 lines (102 loc) · 5.38 KB

CodeActAgent-Gradio

利用 Gradio 使 CodeActAgent-Mistral-7b 成为一个可交互运行的 Code-LLM 教学代理机器人 🤖

In English

简要引述

背景

Executable Code Actions Elicit Better LLM Agents是一个使用可执行代码的工程, 将LLM代理的行动整合到代码执行程序(CodeAct)中,其与 Python 解释器集成。
CodeAct 可以执行代码操作并动态修改先前的操作或根据新的观察发出新的操作(例如,代码教学、代码纠错、运行代码得到执行结果),可实现与用户的动态交互和程序执行。

Girl in a jacket

原始工程,使用Huggingface ChatUi并且具有相对复杂的前后端结构。
本项目旨在简化原有项目结构,仅使用Llama-cpp和gradio,从量化模型出发,以相对简单的结构实现了CodeActAgent作为可运行、可交互的Code LLM教学代理功能使用。

安装和运行结果

安装

pip install -r requirements.txt

推荐安装llama-cpp-python GPU版本以获得更好体验。

运行

启动名为 "code_act_agent_gradio_demo.ipynb" 的jupyter notebook,运行所有单元格。
在浏览器访问 http://127.0.0.1:7860 或者 gradio 提供的开放分享接口。
下面通过几个视频介绍如何与本工程的例子进行交互。

运行结果

简单代码教学

  • 1 除法函数:
Give me a python function give the divide of number it self 10 times.
div_512.mp4

聊天上下文中的 "Observation:" 表明由LLM定义的函数在Python解析器中的运行结果。 这表明本工程具有代码可运行和可交互式运行的能力。

  • 2 numpy 教学:
teach me how to use numpy.
div_vec.mp4

特殊目的函数定义

  • 1 pollinations.ai 提供的图像下载函数: (可以根据提示词,下载 stable diffusion 图像)
Write a python code about, download image to local from url, the format as :
            url = f'https://image.pollinations.ai/prompt/{prompt}'
            where prompt as the input of download function.
bee.mp4

在本例中,用户可以借助LLM定义 download_image 函数,并将蜜蜂图像下载到本地。
我们可以看到,LLM有能力自行纠正输出的错误。
当agent保存没有扩展名的图像时,用户可以使用自然语言命令程序修改本地文件的扩展名, 这表明LLM具有可执行的代理能力而不仅仅是教学助手。

统计函数和作图

  • 1 简单箱形图
Plot box plot with pandas and save it to local.
boxplot.mp4
  • 2 线性回归原理和数据作图
Draw a picture teach me what linear regression is.
reg.mp4
  • 3 金融波动数据模拟
Write a piece of Python code to simulate the financial transaction process and draw a financial images chart by lineplot of Poisson process.
possion.mp4

注意

  • 1 由于随机性,每次运行的结果可能会有所不同,这鼓励积极探索更多方式与LLM灵活交互,这也更有趣。
  • 2 gradio页面中的示例提供了一些方便的指令以方便与模型交互,例如
    Give me the function defination. 💡
    Correct it. ☹️
    Save the output as image 🖼️ to local. ⏬
    Good Job 😊
    你可以在上面的视频中发现它们的用处。
  • 3 聊天上下文的最长长度在notebook中设定为3060,如果你需要更长的聊天轮数,请尝试手动增加,这依赖于你的显存大小。
  • 4 我建议您在 GPU 上运行演示(10GB GPU 内存就足够了,所有示例都在单个 GTX 1080Ti 或 GTX 3060 上进行了测试)

使用的模型

模型名称 模型类型 HuggingFace 模型链接
xingyaoww/CodeActAgent-Mistral-7b-v0.1 Mistral-7b 8bit quantization https://huggingface.co/xingyaoww/CodeActAgent-Mistral-7b-v0.1



Python运行时框架替代品

https://github.com/e2b-dev/code-interpreter

Contact

svjack - https://huggingface.co/svjack - [email protected] - [email protected]

Project Link:https://github.com/svjack/CodeActAgent-Gradio

Acknowledgements