/
Python Plugin

Python Plugin

什麼是 Python Plugin?

Python Plugin 是在 browser 中使用 Pyodide 執行 python code 的 plugin 執行方式

您可以:

  1. 使用 open() function 打開對話中對應的 DVCx

  2. 使用 matplotlib 繪製圖表

  3. 使用 pyfetch 送出 HTTP request

  4. 使用內建的 function chat() 和 DaVinci 本身 Model 對話

使用方法

  1. 準備你的 python code

  2. 儲存 id, names, descriptions 以及對應的 python code 放到 plugin.json 中

    { "id": "HelloWorld", "schema_version": "v1", "name_for_human": "HelloWorld", "name_for_model": "HelloWorld", "description_for_human": "HelloWorld", "description_for_model": "Say hello", "auth": { "type": "none" }, "api": { "type": "python", "python": { "source": "print('Hello World')" } } }

內建 global variable

global variable

用途

使用範例

global variable

用途

使用範例

PLUGIN_USER_COOKIE

用來辨識使用者身分

image-20240204-164357.png

 

CURRENT_CONVERSATION

單一對話中的所有訊息

image-20240204-164738.png

 

SELECTED_MODEL_TOKEN_LIMIT

當下 Model 的對應 token limit

可和 count_token function 一併使用,確保對話過程不會超出 Model 限制

 

SELECTED_FILES

對話中所選取的對應 DVCx 檔資訊

SELETED_FILES 包含以下參數:

  1. "title": 檔案名稱

  2. "type": 檔案的副檔名

  3. "subject": 檔案路徑

假如需要讀取檔案內容,您可以透過以下實作取得:

with open(SELECTED_FILES[i]['subject']) as f: print(f.read())
  • 請注意:這裡的 index i 代表的是在Plugin 使用者的達哥中,所有勾選檔案中排序的第一個,您可以以此類推至其他 index

CUSTOMIZED_PARAMS

如果你是從 assistants-api + plugin-api 使用 python plugin 的話,可以使用這參數讀取 plugin-api 傳進來的客製化參數

{ "id": "HelloWorld", "schema_version": "v1", "name_for_human": "HelloWorld", "name_for_model": "HelloWorld", "description_for_human": "HelloWorld", "description_for_model": "Say hello", "auth": { "type": "none" }, "api": { "type": "python", "python": { "source": "import json\nprint(f'Hello developer, here is your param: {CUSTOMIZED_PARAMS}')" } } }

內建 Function

Function name

用途

使用範例

Function name

用途

使用範例

chat

使用 DaVinci 內建的 Model 送出 prompt

 

count_token

計算文字會使用多少 token

可和 SELECTED_MODEL_TOKEN_LIMIT 一併使用,確保對話過程不會超出 Model 限制

emb

使用 DaVinci 內建的 embedding 功能針對文字進行 embedding 操作

 

 

 

 

Related content

DaVinci Plugin 介紹
DaVinci Plugin 介紹
More like this
Plugin Example Code
Plugin Example Code
More like this
Davinci Python Plugin Quickstart
Davinci Python Plugin Quickstart
More like this
範例 - Multiple Functions
範例 - Multiple Functions
More like this
Developer Manual
🛠️
Developer Manual
More like this
範例 - Embedding
範例 - Embedding
More like this