文章目录
-
- [ChatGPT Code Interpreter应用场景和技术原理动手实践](#ChatGPT Code Interpreter应用场景和技术原理动手实践)
-
- [1 Code Interpreter 应用场景解析](#1 Code Interpreter 应用场景解析)
-
- [Code Interpreter 是什么?](#Code Interpreter 是什么?)
- [Code Interpreter 如何使用?](#Code Interpreter 如何使用?)
- [Code Interpreter 应用场景](#Code Interpreter 应用场景)
- [为什么需要Code Interpreter](#为什么需要Code Interpreter)
- [2 Code Interpreter 技术架构深度剖析](#2 Code Interpreter 技术架构深度剖析)
-
- [Code Interpreter 技术架构](#Code Interpreter 技术架构)
- [LLM Lightweight AI Agent 技术架构](#LLM Lightweight AI Agent 技术架构)
- [System Prompt VS 沙盒环境](#System Prompt VS 沙盒环境)
- [3 基于 LangChain 实现一个 Code Interpreter](#3 基于 LangChain 实现一个 Code Interpreter)
-
- [Code Interpreter API](#Code Interpreter API)
- [Code Interpreter API 案例](#Code Interpreter API 案例)
- [Code Interpreter API 技术架构](#Code Interpreter API 技术架构)
- [Code Interperter API Deep In 技术原理](#Code Interperter API Deep In 技术原理)
- [ReAct(Reasoning + Actioning)](#ReAct(Reasoning + Actioning))
- [4 Interpreter 架构实践中的难点及解决方案](#4 Interpreter 架构实践中的难点及解决方案)
ChatGPT Code Interpreter应用场景和技术原理动手实践
1 Code Interpreter 应用场景解析
Code Interpreter 是什么?
- 2023年7月9日,OpenAI 开放了 Plus 会员 Code Interpreter 体验资格,它被认为是 GPT-4.5 一次新的重大升级。
- Code Interpreter 是"一个实验性的 ChatGPT 模型",它将 Python 代码写入 Jupyter Notebook,并在沙箱中执行,在该沙箱中:
- 其他用户以及互联网隔离,无法上网(出于安全考虑)
- 支持最多 100MB 文件上传/下载(仅支持100MB的目的主要还是出于商业考虑,技术上是可以支持更大文件上传下载的)
- 预装了 343 个库(暂不支持其它预装库)
- 持久会话(上下文支持10次)
- Code Interpreter 新在哪里?
- 新模型
- gpt-4-code-interpreter
- 代码执行沙箱
- sandbox
- 新模型

Code Interpreter 如何使用?
- 在设置中打开 Code Interpreter 的选项,然后在聊天窗口中选择 Code Interpreter 进行体验。
- 用户可以上传最多 100MB 的文件
- 对文件进行提问 和多轮对话

举个🌰
- 用户:上传一个pdf,然后让GPT针对这篇文件做一个总结
- GPT:写一段代码,然后去执行(Action),最后生成结果

Code Interpreter 应用场景
- 视频处理
- 图片处理
- 数据分析
- PDF处理
- 其它

为什么需要Code Interpreter
- 低代码完成数据分析
- Code Interpreter 允许 AI 编写 Python 代码来解决大语音模型在数学和语言方面的固有弱点


- Code Interpreter 可以对文件进行处理,通过代码运行,降低了幻觉和迷惑的概率
- Code Interpreter 让 AI 的用途更加广泛
- 用户不必"编程",因为 Code Interpreter 可以代替大部分/所有的工作
2 Code Interpreter 技术架构深度剖析
Code Interpreter 技术架构
- LLM 大语言模型技术架构

- Code Interpreter 技术架构
- 表面:LLM + Python + Jupyter Notebook
- 真相:AI Agent
- LLM Agent
- 大脑 + 四肢
- 策略 + 行动
- LLM Agent

技术浪潮

LLM Lightweight AI Agent 技术架构
- LLM 是无状态化的文本生成器

System Prompt VS 沙盒环境
- System Prompt:就是关于 Code Interpreter 的一个说明书
- 完整的包列表参考文档:https://github.com/petergpt/code-interpreter-packages/blob/main/packages_with_descriptions_Vfinal.md

3 基于 LangChain 实现一个 Code Interpreter
Code Interpreter API
- LangChain 官方也推出了Code Interpreter的开源方案,命名为 Code Interpreter API

Code Interpreter API 案例
- 当询问"绘制2023年的比特币图表"时,它会使用雅虎财经下载实时数据,然后将其以图像形式展示给用户。

Code Interpreter API 技术架构
- Code Interperter API 底层利用 LangChain 的 Agent 工具,帮助大模型使用 Code Interpreter,有 2 个核心组成:
- 使用 LangChain 的最新的 OpenAIFunctionsAgent
- Python 代码执行器采用的由 CodeBox 或者 本地提供的 Python 运行环境

Code Interperter API 底层利用 LangChain 的 Agent 工具,帮助大模型使用 Code Interpreter,有 2 个核心组成:
- Tools初始化
- 支持 ipython 运行环境
- 输入 Code,输出执行结果
- Agent初始化
- 接受LLM,支持 ChatGPT、Azure等LLM
- 传入 tools
- 支持memory
- 传入 System Prompt

Code Interperter API Deep In 技术原理

ReAct(Reasoning + Actioning)
- 由 Paper 提出,支持 Though-Action-Observation 进行 Prompt 工程
- 该框架扩展 Chain-Of-Thought 到 Chain-Of-Thought-Action-Observation( 额外 intermediate Action 和 observation 步骤)
举个🌰

代码实现

4 Interpreter 架构实践中的难点及解决方案
如何保证数据安全
- 采用私有化部署的 Azure 或者自己训练的 LLM
- 采用自己搭建的运行环境
如何提升效果
- 修改完善 System Prompt
- 改用自己代码 Fine-tune 模型
- 根据不同的数据报表类型,预定义一些分析思路