Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

chat methods defined, also test file for library testing

Daniel Avila641dcfad7338
diff --git a/app/chatgpt.js b/app/chatgpt.js
index 8e1dbcf450..48f7e7165c 100644
--- a/app/chatgpt.js
+++ b/app/chatgpt.js
@@ -1,10 +1,12 @@
require('dotenv').config();
-(async () => {
- const { ChatGPTAPI } = await import('chatgpt');
+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 };
\ No newline at end of file
diff --git a/app/test.js b/app/test.js
new file mode 100644
index 0000000000..abcefb8657
--- /dev/null
+++ b/app/test.js
@@ -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)
+*/
\ No newline at end of file