··

在终端中使用LLM

Tip

本文将介绍Open Interpreter - 一个可以在终端调用GPT-4或本地的Code-llama的python库。

> 点击此处查看官方中文文档。

👇官方宣传视频👇

1. 为什么选择 Open Interpreter?

前段时间,OpenAI 发布了Code Interpreter,旨在给GPT提供一个有生命周期的notebook与一定的储存、运算资源与一个和用户传输文件的方式。它的问世在极大程度上便利了我的日常代码生活。我曾让它在不知道.pt模型结构的情况下,让它自行搭建模型以读取预训练好的checkpoint,也让他帮我统计过excel报表。可以说它是一个非常强大的工具。

但,随着使用的深入,问题也逐渐暴露。

先是我的excel中有部分敏感信息,这使我不得不在本地先进行脱敏处理,再上传给GPT统计报表,极大的影响了效率。
再是,传输大文件极其依赖网络环境,如果我有一个2.5GB的文件要给Code Interpreter分析,我不得不等待很久。
此外,OpenAI对其运行时长、内存、存储等资源都有一定的限制,这使得我无法在Code Interpreter上进行一些复杂的操作。
最后,Code Interpreter依赖于预装好的一系列python库,并且不能联网,这极大的限制了它的使用场景。

因此我选择了Open Interpreter,它可以在本地运行,可以联网,可以使用本地的所有python库,可以使用本地的所有资源,可以使用本地的所有文件,可以使用本地的所有命令行工具。

一言以蔽之,你能在终端执行什么操作,Open Interpreter就能在终端执行什么操作,GPT能完成什么操作,它也能一样完成。并且,它可以调用本地或者Azure上的LLM模型以保证隐私。 202309131624221

2. 安装与运行

Tip

推荐将其装在虚拟环境中,如果你打算长期使用,可以将此虚拟环境作为默认环境。

我在一个常用的conda虚拟环境中进行安装,这个环境是我最常使用的环境。

Terminal window
conda activate your_env
pip install interpreter

安装完成后,你可以在终端中通过interpreter命令方便的调用它。

Tip

第一次运行可能需要使用interpreter -y以提供权限。

3. Open Interpreter可以做什么?

正如它所说,它能进行文件管理、数据处理、网页抓取、系统操作、编码、自动化等等。

点击查看原文
Terminal window
> what can you do?
As an Open Interpreter, I can execute a wide range of tasks by running code on
your machine. Here are some examples of what I can do:
1 File Management: I can create, read, update, and delete files on your system.
I can also move files around and organize them into directories.
2 Data Processing: I can read and process data from various sources such as
databases, APIs, and files. I can perform operations like filtering, sorting,
aggregating, and transforming this data.
3 Web Scraping: I can fetch data from websites by parsing HTML and extracting
the information you need.
4 System Operations: I can execute system commands, install software, and
manage system processes.
5 Coding: I can write and execute code in various languages like Python,
JavaScript, Shell, AppleScript, and HTML.
6 Automation: I can automate repetitive tasks on your computer.
Please note that any code I run is executed on your machine with your full and
complete permission. I'm here to help, so let me know what you need!

下面我将放一个我亲身经历的几个例子:

将一个目录下所有.mobi文件转化为pdf

我举一个简单的例子:我想将一个目录下所有.mobi文件转化为pdf
让我们看看Open Interpreter的表现。

Terminal window
> 将/Users/haleyc/Downloads/FIRE\ PUNCH\ 炎拳 中的mobi转化为pdf
Sure, I can help with that. We will use a tool called Calibre, which is a
powerful and easy to use e-book manager. It can convert from a huge number of
formats to a huge number of formats, including from MOBI to PDF.
Here is the plan:
1 Check if Calibre is installed on your system.
2 If not, install Calibre.
3 Use Calibre's command-line tools to convert the MOBI file to PDF.
Let's start with the first step, checking if Calibre is installed.
calibre --version
Would you like to run this code? (y/n)

首先,它会告诉你它的解决方案,然后询问你是否同意。

它计划先确定是系统否安装了Calibre,如果没有,通过homebrew安装,这之后再进行转码。

202309131647182

在实际执行过程中,由于网络中断,我只能通过输入继续按照最初计划让它继续执行。

由于Calibre需要手动配置,我不得不手动配置完毕后再次执行。在配置完后,一切就变得十分顺利。

点击查看效果图

202309131657746 202309131706989

4. 进阶用法

  • 使用Azureinterpreter --use-azure
  • 使用本地LLMinterpreter --local
  • 使用GPT-3.5-turbointerpreter --fast

此外,你也可以在python中以库的形式调用它。在此我不做介绍。