OpenAI API で text-chat-davinci-002-20230126 を使用しようとすると、404 エラーが返されるようになりました。誰かがすでに新しいモデル名を見つけましたが、現時点では共有したくありません。新しいモデルを見つけたら、このリポジトリを更新します。リードがある場合は、問題またはプルリクエストを開いてください。
それまでの間、ドロップインの代替品として使用できるtext-davinci-003のようなモデルのサポートを追加しました。text-davinci-003 は
text-chat-davinci-002 (RHLF を介してトレーニングされ、会話型 AI になるように微調整されています) ほど良くはありませんが、結果はまだ非常に良好であることに注意してください。
text-davinci-003 を使用するとクレジット ($) がかかることに注意してください。
不和ユーザー@pig#8932が作業モデルを見つけました。このモデルを使用するようにライブラリを更新しました。
text-chat-davinci-002
text-chat-davinci-002-20221122
OpenAIのAPIを介した公式のChatGPTモデルを使用したChatGPTの実装。
これは、公式のChatGPT生モデルを使用したChatGPTの実装です。このモデル名は、ChatGPTの公式Webサイトから行われたネットワークリクエストを調べているときに簡単にリークされ、OpenAI APIで動作することを発見しました。現在、このモデルの使用はクレジットを消費しません。
text-chat-davinci-002
text-chat-davinci-002-20230126
私の知る限り、私はこれを最初に発見した人であり、それ以来、モデルの使用はacheong08 / ChatGPTのようなライブラリに実装されています。
推移的なでたらめ/ chatgpt-apiを使用したこのライブラリの以前のバージョンは、アーカイブ/古いバージョンのブランチ
で引き続き利用できます。
モデル自体には会話のサポートがないため、このライブラリはキャッシュを使用して会話を格納し、コンテキストとしてモデルに渡します。これにより、公式ウェブサイトとほぼ同じ方法でChatGPTと永続的な会話を行うことができます。
text-chat-davinci-002-20221122
ChatGPTClient
keyv-file
settings.example.js
npm i @waylaidwanderer/chatgpt-api
import ChatGPTClient from '@waylaidwanderer/chatgpt-api';
const clientOptions = {
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
// The model is set to text-chat-davinci-002-20221122 by default, but you can override
// it and any other parameters here
model: 'text-chat-davinci-002-20221122',
},
// (Optional) Set custom instructions instead of "You are ChatGPT...".
// promptPrefix: 'You are Bob, a cowboy in Western times...',
// (Optional) Set a custom name for the user
// userLabel: 'User',
// (Optional) Set a custom name for ChatGPT
// chatGptLabel: 'ChatGPT',
// (Optional) Set to true to enable `console.debug()` logging
debug: false,
};
const cacheOptions = {
// Options for the Keyv cache, see https://www.npmjs.com/package/keyv
// This is used for storing conversations, and supports additional drivers (conversations are stored in memory by default)
// For example, to use a JSON file (`npm i keyv-file`) as a database:
// store: new KeyvFile({ filename: 'cache.json' }),
};
const chatGptClient = new ChatGPTClient('OPENAI_API_KEY', clientOptions, cacheOptions);
const response = await chatGptClient.sendMessage('Hello!');
console.log(response); // { response: 'Hi! How can I help you today?', conversationId: '...', messageId: '...' }
const response2 = await chatGptClient.sendMessage('Write a poem about cats.', { conversationId: response.conversationId, parentMessageId: response.messageId });
console.log(response2.response); // Cats are the best pets in the world.
const response3 = await chatGptClient.sendMessage('Now write it in French.', { conversationId: response2.conversationId, parentMessageId: response2.messageId });
console.log(response3.response); // Les chats sont les meilleurs animaux de compagnie du monde.
を使用してパッケージをインストールできます
npm i -g @waylaidwanderer/chatgpt-api
次に、を使用して実行します。
これは省略可能なパラメーターを取るか、設定されていない場合は現在のディレクトリで次の内容で検索します。
chatgpt-api
--settings=<path_to_settings.js>
settings.js
module.exports = {
// Your OpenAI API key
openaiApiKey: process.env.OPENAI_API_KEY || '',
chatGptClient: {
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
// The model is set to text-chat-davinci-002-20221122 by default, but you can override
// it and any other parameters here
model: 'text-chat-davinci-002-20221122',
},
// (Optional) Set custom instructions instead of "You are ChatGPT...".
// promptPrefix: 'You are Bob, a cowboy in Western times...',
// (Optional) Set a custom name for the user
// userLabel: 'User',
// (Optional) Set a custom name for ChatGPT
// chatGptLabel: 'ChatGPT',
// (Optional) Set to true to enable `console.debug()` logging
debug: false,
},
// Options for the Keyv cache, see https://www.npmjs.com/package/keyv
// This is used for storing conversations, and supports additional drivers (conversations are stored in memory by default)
cacheOptions: {},
// Options for the API server
apiOptions: {
port: process.env.API_PORT || 3000,
host: process.env.API_HOST || 'localhost',
// (Optional) Set to true to enable `console.debug()` logging
debug: false,
},
// If set, ChatGPTClient will use `keyv-file` to store conversations to this JSON file instead of in memory.
// However, `cacheOptions.store` will override this if set
storageFilePath: process.env.STORAGE_FILE_PATH || './cache.json',
};
または、パッケージを直接インストールして実行することもできます。
git clone https://github.com/waylaidwanderer/node-chatgpt-api
npm install
settings.example.js
settings.js
npm start
npm run server
docker-compose up
ChatGPT との会話を開始するには、次の形式の JSON 本文を使用して、サーバーのエンドポイントに POST 要求を送信します。
/conversation
{
"message": "Hello, how are you today?",
"conversationId": "your-conversation-id (optional)",
"parentMessageId": "your-parent-message-id (optional)"
}
サーバーは、ChatGPT の応答を含む JSON オブジェクトを返します。
{
"response": "I'm doing well, thank you! How are you?",
"conversationId": "your-conversation-id",
"messageId": "response-message-id"
}
要求が失敗した場合、サーバーはエラー メッセージと状態コード 503 を含む JSON オブジェクトを返します。
ChatGPT へのメッセージの送信中にエラーがあった場合:
{
"error": "There was an error communicating with ChatGPT."
}
API サーバーと同じ手順を使用してパッケージをインストールします。
グローバルにインストールされている場合:
chatgpt-cli
ローカルにインストールされている場合:
npm run cli
ChatGPTの応答は自動的にクリップボードにコピーされるため、他のアプリケーションに貼り付けることができます。
ChatGPTの生のモデルなので、ChatGPTの公式ウェブサイトがそれを使用する方法を再現するために最善を尽くさなければなりませんでした。広範なテストと回答の比較の結果、ChatGPTで使用されるモデルにはさらに微調整が加えられていると思います。
これは、私の実装または生のモデルがいくつかの点でまったく同じように動作しない可能性があることを意味します。
text-chat-davinci-002-20221122
会話はどのユーザー ID にも関連付けられていないため、それが重要な場合は、独自のユーザー ID システムを実装する必要があります。
ChatGPTのモデルパラメータ(温度、周波数ペナルティなど)は不明であるため、妥当だと思われるデフォルトをいくつか設定しました。
会話は約最後の 3000 トークンに制限されているため、長い会話では以前のメッセージを忘れる可能性があります。
微調整の一環として、ChatGPTに次の前文があることはよく知られています。
「あなたはOpenAIによって訓練された大規模な言語モデルであるChatGPTです。各応答に対してできるだけ簡潔に回答します(たとえば、冗長にしないでください)。できるだけ簡潔に答えることがとても重要ですので、覚えておいてください。リストを生成する場合は、アイテムが多すぎないようにしてください。アイテムの数は短くしてください。
知識のカットオフ:2021-09
現在の日付:2023-01-31"
OpenAIがChatGPTを更新すると、このプリアンブルも変更される可能性があります。私の実装のデフォルトのプロンプトプレフィックスは、現在のChatGPTモデルと同様の動作を再現しようとします。
このプロジェクトに貢献したい場合は、変更の詳細な説明を含むプルリクエストを作成してください。
このプロジェクトはMITライセンスの下でライセンスされています。