-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChatGPTの調査 #5
Comments
調査したこと
chatgpt apiでできることhttps://aismiley.co.jp/ai_news/what-is-the-chatgpt-api/
今回は普段使っているような「ユーザーが何か問いかけたらそれに対してchatgptが返答してくれる」ようなchatの機能が使いたいため、問題なくできそうである。 chatgpt apiのAPIキー取得方法https://aismiley.co.jp/ai_news/what-is-the-chatgpt-api/ APIキーを用いたchatgpt apiへのリクエスト方法APIリファレンスがあるので、そちらを参考に進めた。 リクエスト例としてはリファレンスにも記載あるが、下記のようになる const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{"role": "system", "content": "You are a helpful assistant."}, {role: "user", content: "Hello world"}],
});
console.log(completion.data.choices[0].message); そのときのレスポンスが下記のようになる {
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-3.5-turbo-0613",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?",
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
} エラーについて上記を参考に実装すると、 今回は公開はつどい内に閉じるつもりであり、開発合宿が終わって一定期間経ったらAPIキー削除してリクエストが行かないようにしたりなど何らかの対応をすればいいかなと思っているので、とりあえずは上記で対応で良いと思っている。 その他OpenAIのAPI料金の節約方法という記事が参考になりそうなので、もし個人で使ってみたいという方がいたら参考にしてみるといいかも。 |
No description provided.
The text was updated successfully, but these errors were encountered: