Skip to content

Commit

Permalink
🐛 fix(chatgptoot.js): fix incorrect property access in getStatus func…
Browse files Browse the repository at this point in the history
…tion

🐛 fix(chatgptoot.js): fix incorrect property access in getStatus function
🐛 fix(chatgptoot.js): fix incorrect property access in handleNewsCommand function
🐛 fix(chatgptoot.js): fix incorrect property access in handleNewsCommand function
🐛 fix(chatgptoot.js): fix incorrect property access in handleRegularMention function
🐛 fix(chatgptoot.js): fix incorrect property access in handleRegularMention function
🐛 fix(chatgptoot.js): fix incorrect property access in handleRegularMention function
🐛 fix(chatgptoot.js): fix incorrect property access in handleRegularMention function
🐛 fix(chatgptoot.js): fix incorrect property access in generateImagePrompt function
🐛 fix(chatgptoot.js): fix incorrect property access in generateImagePrompt function
🐛 fix(chatgptoot.js): fix incorrect property access in generateToot function
🐛 fix(chatgptoot.js): fix incorrect property access in generateToot function
  • Loading branch information
skullzarmy committed Oct 31, 2023
1 parent b7c1d0b commit 275ecaf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/chatgptoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async function getStatus() {
});

let openAIStatus = "not working";
if (response.data.choices[0].text) {
if (response.choices[0].text) {
openAIStatus = "working as expected";
}

Expand All @@ -261,7 +261,7 @@ async function getStatus() {
.format(
"YYYY-MM-DD HH:mm:ss"
)} in UTC. Currently ${countfeedback} logged feedback message(s). The connection to OpenAI is ${openAIStatus}. Test response: ${
response.data.choices[0].text ? response.data.choices[0].text : "Test failed"
response.choices[0].text ? response.choices[0].text : "Test failed"
}`;

return status;
Expand Down Expand Up @@ -632,11 +632,11 @@ async function handleNewsCommand(mention) {
content:
"Please summarize the latest news article in one or two sentences. You can also add your own thoughts or opinions.",
});
const response = await openai.createChatCompletion({
const response = await openai.chat.completions.create({
model: config.gpt_model,
messages: msg,
});
summaries.push(`${item.title}\n${response.data.choices[0].message.content}\n${item.link}`);
summaries.push(`${item.title}\n${response.choices[0].message.content}\n${item.link}`);
}

const reply = `@${mention.account.acct} ${summaries.join("\n\n")}`;
Expand Down Expand Up @@ -758,12 +758,12 @@ async function handleRegularMention(mention) {

conversation = await addContext(conversation);

const response = await openai.createChatCompletion({
const response = await openai.chat.completions.create({
model: config.gpt_model,
messages: conversation,
});

let reply = response.data.choices[0].message.content;
let reply = response.choices[0].message.content;
const tootVis = mention ? mention.status.visibility : false || "public";
if (tootVis == "direct") {
reply = `@${mention.account.acct} ${reply}`;
Expand All @@ -776,7 +776,7 @@ async function handleRegularMention(mention) {
.reverse()
.find((message) => message.role === "user");
if (lastUserMessage) {
const tokens = response.data.choices[0].tokens;
const tokens = response.choices[0].tokens;
logUsage(mention.account.acct, mention.status.id, lastUserMessage.content, tokens, "chat");
}
} catch (error) {
Expand Down Expand Up @@ -1009,12 +1009,12 @@ async function generateImagePrompt(prompt = false) {
content: prompt,
});

const response = await openai.createChatCompletion({
const response = await openai.chat.completions.create({
model: config.gpt_model,
messages: msg,
});

const final_prompt = response.data.choices[0].message.content;
const final_prompt = response.choices[0].message.content;
return final_prompt;
} catch (error) {
console.error(`OpenAI Error: ${error}`);
Expand Down Expand Up @@ -1085,15 +1085,15 @@ async function generateToot(prompt = false, rss = false) {
);
}

const response = await openai.createChatCompletion({
const response = await openai.chat.completions.create({
model: config.gpt_model,
messages: msg,
});

const tokens = response.data.choices[0].message.tokens;
const tokens = response.choices[0].message.tokens;
logUsage("mrroboto", null, "generate toot", tokens, "chat");

const toot = response.data.choices[0].message.content;
const toot = response.choices[0].message.content;
if (toot.trim() === "") {
throw new Error("Generated toot is empty");
} else {
Expand Down

0 comments on commit 275ecaf

Please sign in to comment.