Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Nov 17, 2024
1 parent c69f19f commit b3974d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
18 changes: 9 additions & 9 deletions api/src/controllers/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const search = async (req, res, next) => {

export const completions = async (req, res, next) => {
const definition = req.app.get("runtimeDefinition");
const { messages, sources } = req.body;
const { messages, sources, timeFilter } = req.body;

try {
const didService = new DIDService(definition);
Expand All @@ -55,6 +55,7 @@ export const completions = async (req, res, next) => {
}, ...messages],
indexIds: reqIndexIds,
stream: true,
timeFilter,
});

// Stream the response
Expand Down Expand Up @@ -86,14 +87,13 @@ export const updates = async (req, res, next) => {

await pubSubClient.subscribe(reqIndexChannels, async (payload, channel) => {
const indexId = channel.replace(`indexStream:`, "");
res.write(
`data: ${JSON.stringify({
indexId,
data: {
node: JSON.parse(payload),
},
})}\n\n`,
);
const message = {
indexId,
data: {
node: JSON.parse(payload),
},
};
res.write(`data: ${JSON.stringify(message)}\n\n`);
});

// Cleanup on client disconnect
Expand Down
5 changes: 3 additions & 2 deletions api/src/language/completions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ const formatChatHistory = (messages) => {
return messages.map(m => `${m.role}: ${m.content}`).join('\n');
};

export const handleCompletions = async ({ messages, indexIds, maxDocs=500, stream, schema }) => {
export const handleCompletions = async ({ messages, indexIds, maxDocs=500, stream, schema, timeFilter }) => {

// TODO indexIds is optional because of chat summary.

// Fetch relevant documents
const docs = await searchItems({
indexIds,
query: formatChatHistory(messages),
limit: maxDocs
limit: maxDocs,
timeFilter
});


Expand Down
4 changes: 4 additions & 0 deletions api/src/packages/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ app.post(
Joi.object({
messages: Joi.array().items(Joi.any()).min(1).required(),
sources: Joi.array().items(Joi.string()).min(1).required(),
timeFilter: Joi.object({
from: Joi.date().iso().optional(),
to: Joi.date().iso().optional()
}).optional()
})
),
discoveryController.completions,
Expand Down

0 comments on commit b3974d1

Please sign in to comment.