mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
chat methods defined, also test file for library testing
This commit is contained in:
parent
7c4e7ab07a
commit
641dcfad73
2 changed files with 35 additions and 6 deletions
|
|
@ -1,10 +1,12 @@
|
|||
require('dotenv').config();
|
||||
(async () => {
|
||||
|
||||
const ask = async (question) => {
|
||||
const { ChatGPTAPI } = await import('chatgpt');
|
||||
|
||||
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_KEY });
|
||||
const res = await api.sendMessage(question, {
|
||||
onProgress: (partialRes) => console.log(partialRes.text)
|
||||
});
|
||||
return res;
|
||||
};
|
||||
|
||||
// send a message and wait for the response
|
||||
let res = await api.sendMessage('What is OpenAI?');
|
||||
console.log(res);
|
||||
})();
|
||||
module.exports = { ask };
|
||||
27
app/test.js
Normal file
27
app/test.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
require('dotenv').config();
|
||||
// docs https://github.com/transitive-bullshit/chatgpt-api
|
||||
|
||||
(async () => {
|
||||
const { ChatGPTAPI } = await import('chatgpt');
|
||||
|
||||
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_KEY });
|
||||
|
||||
// send a message and wait for the response
|
||||
let res = await api.sendMessage('What is OpenAI?');
|
||||
console.log(res);
|
||||
})();
|
||||
|
||||
// If you want to track the conversation, you'll need to pass the parentMessageid and conversationid:
|
||||
// See example in models/Message.js
|
||||
|
||||
/*
|
||||
// You can add streaming via the onProgress handler:
|
||||
// timeout after 2 minutes (which will also abort the underlying HTTP request)
|
||||
const res = await api.sendMessage('Write a 500 word essay on frogs.', {
|
||||
// print the partial response as the AI is "typing"
|
||||
onProgress: (partialResponse) => console.log(partialResponse.text)
|
||||
})
|
||||
|
||||
// print the full text at the end
|
||||
console.log(res.text)
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue