Closed4

ChatGPT Code Interpreterクローンを試す(SlashGPT編)

kun432kun432

インストール

Ubuntu-22.02+pyenv/pyenv-virtualenv環境で。python-3.10.11。

$ pyenv virtualenv 3.10.11 SlashGPT
$ git clone https://github.com/snakajima/SlashGPT && cd SlashGPT
$ pyenv local SlashGPT
$ pip install -r requirements.txt

でpip installでコケる。 pyobjc-framework-CoreDataのところ。

Collecting pyobjc-framework-CoreData==9.2
(snip)
      FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/sw_vers'
      [end of output]

pyobjc-framework-CoreDataってmacOS用のライブラリなのな

Wrappers for the framework CoreData on macOS

https://pypi.org/project/pyobjc-framework-CoreData/

macで動かしてもいいんだけど、できればLinux上で動かしたい。で、このPR。

https://github.com/snakajima/SlashGPT/pull/12

Windowsに対応するためのPRだけど、Mac依存になってるのを外してるだけのように見えるので、Linux上でも動きそう。requirements.txtだけ書き換えた。ほかは問題なさそうなので。

pyobjc; sys_platform == 'darwin' 
$ pip install -r requirements.txt

.envをセット

OPENAI_API_KEY=XXXXX

起動

$ ./SlashGPT.py
playsound is relying on another python subprocess. Please use `pip install pygobject` if you want playsound to run more efficiently.
System Slashes: /root, /bye, /new, /prompt, /sample, /help, ...
Activating: Main Dispatcher
Dispatcher: I am a dispatcher agent. I will find the right agent for your question, and let it answer.
You(dispatcher):

とりま/help

You(dispatcher): /help

/root:      Start from the scratch (going back to dispatcher)
/bye:       Terminate the app
/new:       Start a new chat session
/prompt:    Display the current prompt
/history:   Display the chat history
/sample:    Make the sample request
/gpt3:      Switch the model to gpt-3.5-turbo-0613
/gpt31:     Switch the model to gpt-3.5-turbo-16k-0613
/gpt4:      Switch the model to gpt-4-0613
/palm:      Switch the model to Google PaLM
/llama2:    Switch the model to LlaMA2 7b
/llama270:  Switch the model to LlaMA2 70b
/vicuna:    Switch the model to Vicuna 16b
/verbose:   Toggle verbose switch
/roles1:    Switch the manifest set to ones in prompts (original)
/roles2:    Switch the manifest set to ones in roles2

Agents:
/aiagents     AI Agents
/browser      Internet Browser
/cal          Calendar
/cook         Home Cooking System
/currency     Currency Converter
/definitive   Definitive Facts
/dispatcher   Main Dispatcher
/dot          DOT language expert
/drone2       Drone Pilot
/home2        Home Automation
/jupyter      Jupyter Notebook with GPT3.5
/jupyter2     Jupyter Notebook with Llamma2
/jupyter_map  Jupyter Notebook with GPT3.5
/jupyter_vicu Jupyter Notebook with Vicuna 16b
/jupyterp     Jupyter Notebook with Palm
/kayak        Kayak (not accessible yet)
/names        名前判別
/news2        News News
/noteable     WIP: Noteable
/weather      Open Weather
/webpilot     Web Pilot AI
/wolfram      Wolfram
/worldnews    World News

普通に会話するならこんな感じで。

You(dispatcher): こんにちは
Dispatcher: こんにちは!ご質問やお困りごとがありましたら、どうぞお気軽にお聞きください。

/jupyterで。

You(jupyter): pythonで簡単なグラフを書いてください。
{
  "name": "run_python_code",
  "arguments": {
    "code": [
      "import matplotlib.pyplot as plt\n",
      "\n",
      "x = [1, 2, 3, 4, 5]\n",
      "y = [2, 4, 6, 8, 10]\n",
      "\n",
      "plt.plot(x, y)\n",
      "plt.xlabel('X-axis')\n",
      "plt.ylabel('Y-axis')\n",
      "plt.title('Simple Graph')\n",
      "plt.show()"
    ],
    "query": "Simple graph"
  }
}
You(jupyter): グラフの描画はplotlyを使うようにしてください
{
  "name": "run_python_code",
  "arguments": {
    "code": [
      "import plotly.graph_objects as go",
      "",
      "x = [1, 2, 3, 4, 5]",
      "y = [2, 4, 6, 8, 10]",
      "",
      "fig = go.Figure(data=go.Scatter(x=x, y=y))",
      "fig.update_layout(title='Simple Graph', xaxis_title='X-axis', yaxis_title='Y-axis')",
      "fig.show()"
    ],
    "query": "Plot a simple graph using Plotly"
  }
}
function(run_python_code): ---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File <ipython-input-1-1e8f2813b45d>:1
----> 1 import plotly.graph_objects as go
      3 x = [1, 2, 3, 4, 5]
      4 y = [2, 4, 6, 8, 10]

ModuleNotFoundError: No module named 'plotly'

Jupyter: 申し訳ありませんが、現在の環境ではPlotlyがインストールされていないため、使用することができません。Matplotlibを使用してグラフを描画する方法を提供します。以下のコードをお試しください。

```Python
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Graph')
plt.show()
```
You(jupyter): plotlyをインストールしてください
Function python: Failed to load arguments as json
{
  "name": "python",
  "arguments": "!pip install plotly"
}
python function was called
function(python): Collecting plotly
  Using cached plotly-5.15.0-py2.py3-none-any.whl (15.5 MB)
Requirement already satisfied: packaging in /home/kun432/.pyenv/versions/3.10.11/envs/SlashGPT/lib/python3.10/site-packages (from plotly) (23.1)
Collecting tenacity>=6.2.0
  Using cached tenacity-8.2.2-py3-none-any.whl (24 kB)
Installing collected packages: tenacity, plotly
Successfully installed plotly-5.15.0 tenacity-8.2.2

[notice] A new release of pip is available: 23.0.1 -> 23.2.1
[notice] To update, run: python3.10 -m pip install --upgrade pip

Jupyter: Plotlyがインストールされましたので、以下のコードでグラフを描画できます。

```Python
import plotly.graph_objects as go

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

fig = go.Figure(data=go.Scatter(x=x, y=y))
fig.update_layout(title='Simple Graph', xaxis_title='X-axis', yaxis_title='Y-axis')
fig.show()
```
You(jupyter): では再度グラフの描画はplotlyを使うようにしてください
Function python: Failed to load arguments as json
{
  "name": "python",
  "arguments": "import plotly.graph_objects as go\n\nx = [1, 2, 3, 4, 5]\ny = [2, 4, 6, 8, 10]\n\nfig = go.Figure(data=go.Scatter(x=x, y=y))\nfig.update_layout(title='Simple Graph', xaxis_title='X-axis', yaxis_title='Y-axis')\nfig.show()"
}
python function was called

outputを見てみるとこんな感じでnotebookが出力されている。

実行するとちゃんと表示される。

他にも。/aiagentsを試してみる。

You(jupyter): /aiagents
Activating: AI Agents
You(aiagents): 明日の天気は
{
  "name": "aiagent",
  "arguments": {
    "goal": "\u660e\u65e5\u306e\u5929\u6c17\u3092\u6559\u3048\u3066\u304f\u3060\u3055\u3044"
  }
}
Got 500:<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
 from https://ai-agents-plugin.vercel.app/aiagent?goal=%E6%98%8E%E6%97%A5%E3%81%AE%E5%A4%A9%E6%B0%97%E3%82%92%E6%95%99%E3%81%88%E3%81%A6%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84
You(aiagents): 明日の天気は
{
  "name": "aiagent",
  "arguments": {
    "goal": "\u660e\u65e5\u306e\u5929\u6c17\u3092\u6559\u3048\u3066\u304f\u3060\u3055\u3044"
  }
}
function(aiagent): {"instructions":"READ the REQUEST and the RESPONSE. Perform the instructions specified in the RESPONSE based on the REQUEST given. Show the RESPONSE as well to the user.","request":"GOAL: \u660e\u65e5\u306e\u5929\u6c17\u3092\u6559\u3048\u3066\u304f\u3060\u3055\u3044","response":"1. \u5929\u6c17\u4e88\u5831\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b\u3001\u5929\u6c17\u4e88\u5831\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u307e\u305f\u306f\u30a2\u30d7\u30ea\u3092\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002\n2. \u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u307e\u305f\u306f\u30a2\u30d7\u30ea\u306e\u691c\u7d22\u30d0\u30fc\u306b\u3001\u660e\u65e5\u306e\u5929\u6c17\u3092\u8abf\u3079\u305f\u3044\u90fd\u5e02\u540d\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n3. \u691c\u7d22\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u3001\u660e\u65e5\u306e\u5929\u6c17\u4e88\u5831\u3092\u30af\u30ea\u30c3\u30af\u307e\u305f\u306f\u30bf\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n4. \u5929\u6c17\u4e88\u5831\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u3001\u4ee5\u4e0b\u306e\u60c5\u5831\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\uff1a\n   - \u660e\u65e5\u306e\u5929\u6c17\u306e\u6982\u8981\uff08\u6674\u308c\u3001\u66c7\u308a\u3001\u96e8\u306a\u3069\uff09\n   - \u660e\u65e5\u306e\u6700\u9ad8\u6c17\u6e29\u3068\u6700\u4f4e\u6c17\u6e29\n   - \u660e\u65e5\u306e\u964d\u6c34\u78ba\u7387\n   - \u660e\u65e5\u306e\u98a8\u901f\u3068\u98a8\u5411\u304d\n5. \u4e0a\u8a18\u306e\u60c5\u5831\u3092\u30e1\u30e2\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n6. \u3082\u3057\u53ef\u80fd\u3067\u3042\u308c\u3070\u3001\u660e\u65e5\u306e\u5929\u6c17\u306b\u95a2\u9023\u3059\u308b\u305d\u306e\u4ed6\u306e\u60c5\u5831\uff08\u6e7f\u5ea6\u3001\u65e5\u306e\u51fa\u30fb\u65e5\u306e\u5165\u308a\u306e\u6642\u9593\u306a\u3069\uff09\u3082\u78ba\u8a8d\u3057\u3066\u30e1\u30e2\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n7. \u5fc5\u8981\u306a\u60c5\u5831\u3092\u3059\u3079\u3066\u30e1\u30e2\u3057\u305f\u3089\u3001\u305d\u308c\u3092\u79c1\u306b\u4f1d\u3048\u3066\u304f\u3060\u3055\u3044\u3002"}

GPT: 明日の天気を知りたい場合は、以下の手順を実行してください。

1. 天気予報の情報を取得するために、天気予報のウェブサイトまたはアプリを開いてください。
2. ウェブサイトまたはアプリの検索バーに、明日の天気を調べたい都市名を入力してください。
3. 検索結果が表示されたら、明日の天気予報をクリックまたはタップしてください。
4. 天気予報ページが表示されたら、以下の情報を確認してください:
   - 明日の天気の概要(晴れ、曇り、雨など)
   - 明日の最高気温と最低気温
   - 明日の降水確率
   - 明日の風速と風向き
5. 上記の情報をメモしてください。
6. もし可能であれば、明日の天気に関連する他の情報(湿度、日の出・日の入りの時間など)もメモしてください。
7. 必要な情報をまとめたら、それを私に伝えてください。

以上の手順を実行することで、明日の天気を確認することができます。
kun432kun432

一応Mac上でも動かしてみた。多分そこまでMacに依存しないんじゃなかろうかとは思ってるけども、細かいところまでは追ってない。Agentっぽい動きが見えたのは良い。

You(weather): /jupyter
You(jupyter): titanicの回帰分析を行って
{
  "name": "run_python_code",
  "arguments": {
    "code": [
      "import pandas as pd",
      "from sklearn.model_selection import train_test_split",
      "from sklearn.linear_model import LogisticRegression",
      "from sklearn.metrics import accuracy_score",
      "",
      "# Load the Titanic dataset",
      "url = 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv'",
      "df = pd.read_csv(url)",
      "",
      "# Select the features and target variable",
      "X = df[['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked']]",
      "y = df['Survived']",
      "",
      "# Convert categorical variables to numerical",
      "X = pd.get_dummies(X, drop_first=True)",
      "",
      "# Split the data into training and testing sets",
      "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)",
      "",
      "# Create and train the logistic regression model",
      "model = LogisticRegression()",
      "model.fit(X_train, y_train)",
      "",
      "# Make predictions on the test set",
      "y_pred = model.predict(X_test)",
      "",
      "# Calculate the accuracy of the model",
      "accuracy = accuracy_score(y_test, y_pred)",
      "accuracy"
    ],
    "query": "titanic regression analysis"
  }
}
function(run_python_code): ---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File <ipython-input-1-c807f543bfd5>:1
----> 1 import pandas as pd
      2 from sklearn.model_selection import train_test_split
      3 from sklearn.linear_model import LogisticRegression

ModuleNotFoundError: No module named 'pandas'

Jupyter: It seems that the `pandas` library is not installed. Let me fix that for you.
Function python: Failed to load arguments as json
{
  "name": "python",
  "arguments": "!pip install pandas"
}
python function was called
function(python): Collecting pandas
  Using cached pandas-2.0.3-cp310-cp310-macosx_10_9_x86_64.whl (11.8 MB)
(snip)
Successfully installed pandas-2.0.3 pytz-2023.3 tzdata-2023.3

(snip)

Jupyter: Now that `pandas` is installed, let's run the code again.
{
  "name": "run_python_code",
  "arguments": {
    "code": [
      "import pandas as pd",
      "from sklearn.model_selection import train_test_split",
      "from sklearn.linear_model import LogisticRegression",
      "from sklearn.metrics import accuracy_score",
      "",
      "# Load the Titanic dataset",
      "url = 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv'",
      "df = pd.read_csv(url)",
      "",
      "# Select the features and target variable",
      "X = df[['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked']]",
      "y = df['Survived']",
      "",
      "# Convert categorical variables to numerical",
      "X = pd.get_dummies(X, drop_first=True)",
      "",
      "# Split the data into training and testing sets",
      "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)",
      "",
      "# Create and train the logistic regression model",
      "model = LogisticRegression()",
      "model.fit(X_train, y_train)",
      "",
      "# Make predictions on the test set",
      "y_pred = model.predict(X_test)",
      "",
      "# Calculate the accuracy of the model",
      "accuracy = accuracy_score(y_test, y_pred)",
      "accuracy"
    ],
    "query": "titanic regression analysis"
  }
}
function(run_python_code): ---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File <ipython-input-1-c807f543bfd5>:2
      1 import pandas as pd
----> 2 from sklearn.model_selection import train_test_split
      3 from sklearn.linear_model import LogisticRegression
      4 from sklearn.metrics import accuracy_score

ModuleNotFoundError: No module named 'sklearn'

Jupyter: It seems that the `sklearn` library is also not installed. Let me fix that for you.
```Python
!pip install scikit-learn

```
kun432kun432

まとめ

Code Interpreterクローンに共通してるけど、やっぱりjupyter notebook使うのが普通なのだなー。本家Code Interpreterの出力でも!pip installとかでてくるし。

CLIベースなのでグラフとか画面描画するようなものはちょっと見えないので、あとでnotebookを開き直す必要があるけども、いろいろ拡張性とか考えてあるのは面白そう。ただnotebookが残るのは再現性確保の意味でとても良い。

とはいえ非同期にならなくて済むUIがあるのとないのではやっぱり違うなと思った。

このスクラップは2023/08/07にクローズされました