Skip to content

Commit

Permalink
Merge pull request #17 from alkem-io/release/v0.4.0
Browse files Browse the repository at this point in the history
Release v0.4.0
  • Loading branch information
valeksiev authored Jun 5, 2024
2 parents 34a5398 + dbbc440 commit 0a3e0a1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/space-ingest",
"version": "0.3.3",
"version": "0.4.0",
"description": "",
"author": "Alkemio Foundation",
"private": true,
Expand Down Expand Up @@ -40,7 +40,7 @@
"typescript": "^4.1.2"
},
"dependencies": {
"@alkemio/client-lib": "^0.30.2",
"@alkemio/client-lib": "^0.30.3",
"@azure/openai": "^1.0.0-beta.12",
"@dotenvx/dotenvx": "^0.35.1",
"@langchain/community": "^0.2.4",
Expand Down
81 changes: 51 additions & 30 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Document } from 'langchain/document';
import {
AlkemioClient,
Callout,
Space,
createConfigUsingEnvVars,
} from '@alkemio/client-lib';

Expand All @@ -12,6 +13,51 @@ import ingest, { SpaceIngestionPurpose } from './ingest';
import generateDocument from './generate.document';
import { handleCallout } from './callout.handlers';

const handleSubspaces = async (
subspaces: Partial<Space>[],
alkemioClient: AlkemioClient
) => {
const documents: Document[] = [];
for (let i = 0; i < subspaces.length; i++) {
const subspace = subspaces[i];
const { documentId, source, pageContent, type, title } =
generateDocument(subspace);
documents.push(
new Document({
pageContent,
metadata: {
documentId,
source,
type,
title,
},
})
);

for (let j = 0; j < (subspace.collaboration?.callouts || []).length; j++) {
const callout = (subspace.collaboration?.callouts || [])[j];
if (callout) {
const document = await handleCallout(
callout as Partial<Callout>,
alkemioClient
);
// empty doc - nothing to do here
if (document) {
documents.push(...document);
}
}
}

const subspacesDocs = await handleSubspaces(
(subspace.subspaces || []) as Partial<Space>[],
alkemioClient
);
documents.push(...subspacesDocs);
}

return documents;
};

export const main = async (spaceId: string, purpose: SpaceIngestionPurpose) => {
logger.info(`Ingest invoked for space ${spaceId}`);
const config = createConfigUsingEnvVars();
Expand Down Expand Up @@ -42,36 +88,11 @@ export const main = async (spaceId: string, purpose: SpaceIngestionPurpose) => {
})
);

for (let i = 0; i < (space.subspaces || []).length; i++) {
const challenge = (space.subspaces || [])[i];
const { documentId, source, pageContent, type, title } =
generateDocument(challenge);
documents.push(
new Document({
pageContent,
metadata: {
documentId,
source,
type,
title,
},
})
);

for (let j = 0; j < (challenge.collaboration?.callouts || []).length; j++) {
const callout = (challenge.collaboration?.callouts || [])[j];
if (callout) {
const document = await handleCallout(
callout as Partial<Callout>,
alkemioClient
);
// empty doc - nothing to do here
if (document) {
documents.push(...document);
}
}
}
}
const subspacesDocs = await handleSubspaces(
(space.subspaces || []) as Partial<Space>[],
alkemioClient
);
documents.push(...subspacesDocs);

// UUID -> nameID
const ingestionResult = await ingest(space.nameID, documents, purpose);
Expand Down

0 comments on commit 0a3e0a1

Please sign in to comment.