diffshare / chatgpt-electron-app

0 stars 0 forks source link

入力された質問のトークン数を表示したい #25

Closed diffshare closed 1 year ago

diffshare commented 1 year ago

[人間] ChatGPTのtokenの仕組みを調査。

以下のトークナイザーを用いていることがわかった。

https://github.com/openai/tiktoken star 3.3k

他のトークナイザーに比べて高速らしい。 これのnodeの移植版が2つくらい見つかった。

starが多い dpbd/tiktoken を利用する方法を検討する。

diffshare commented 1 year ago

dpbd/tiktoken を利用するが、下記エラーが発生

Uncaught TypeError: wasm.__wbindgen_add_to_stack_pointer is not a function
    at encoding_for_model (tiktoken_bg.js:197:1)
    at ./src/App.tsx (App.tsx:76:1)
    at options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/index.tsx (App.tsx:378:1)
    at options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at startup:7:1
    at startup:7:1
diffshare commented 1 year ago

https://github.com/diffshare/chatgpt-electron-app/issues/25#issuecomment-1493189439 のエラーは https://github.com/dqbd/tiktoken/tree/main/js#create-react-app の対応を行うことで解決

diffshare commented 1 year ago

[gpt-4] 次のコードのようにuserInputのトークン数を表示する変更を行いました。この変更のpull requestの内容をテンプレートに従って出力してください。 ...

Pull Requestの内容

概要

変更点

動作確認方法

  1. アプリを起動します。
  2. 入力欄に文字を入力すると、文字数とトークン数が表示されます。