Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
flakeed committed Apr 10, 2023
1 parent 7ce042a commit 6942271
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions imports/openai/request-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ let serialOperations = [];
type: 'insert',
objects: [
{
data: [{ id: chatgptMessageLinkId }],
type_id: messageTypeLinkId,
string: { data: { value: response.data.choices[0].message.content } },
in: {
Expand All @@ -140,13 +139,22 @@ let serialOperations = [];
],
});

const serialResult = await deep.serial({
operations: serialOperations
})

const chatGPTMessageId = serialResult[0]?.id;

if (!chatGPTMessageId) {
throw new Error('Failed to create ChatGPT message.');
}
serialOperations.push({
table: 'links',//replyToMessageLinkId
type: 'insert',
objects: [
{
type_id: replyTypeLinkId,
from_id: chatgptMessageLinkId,
from_id: chatGPTMessageId,
to_id: replyLink.from_id,
in: {
data: {
Expand All @@ -158,14 +166,14 @@ let serialOperations = [];
],
});

const serialResult = await deep.serial({
operations: serialOperations
})
await deep.serial({
operations: serialOperations,
});

async function getMessages({ messageLinks }) {
return Promise.all(
messageLinks.map(async (link) => ({
role: await getMessageRole({ messageLink: link }),
role: await getMessageRole({ messageLinks: link }),
content: link.value.value,
}))
);
Expand Down Expand Up @@ -236,7 +244,7 @@ let serialOperations = [];


async function getMessageRole({ messageLink }) {
const authorLink = messageLinks.filter((link) => link.author && link.author.length > 0);
const authorLink = messageLink.filter((link) => link.author && link.author.length > 0);
if (!authorLink) {
throw new Error(`Author link not found for message ##${messageLink.id}`);
}
Expand Down

0 comments on commit 6942271

Please sign in to comment.