Skip to content

Commit

Permalink
Merge pull request #44 from alkem-io/release/v0.8.0
Browse files Browse the repository at this point in the history
Release version 0.8.0
  • Loading branch information
hero101 authored Jul 5, 2024
2 parents b0d291d + da9701d commit 46bc07b
Show file tree
Hide file tree
Showing 13 changed files with 572 additions and 399 deletions.
2 changes: 2 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ VECTOR_DB_PORT=8000

CHUNK_SIZE=1000
CHUNK_OVERLAP=100

BATCH_SIZE=20
21 changes: 21 additions & 0 deletions graphql/fragments/profile.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
fragment ProfileFields on Profile {
id
description
displayName
tagline
url
type
tagset {
tags
}
references {
description
name
uri
}
visuals {
uri
name
}
}

42 changes: 13 additions & 29 deletions graphql/fragments/space-ingest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fragment SpaceIngest on Space {
id
nameID
type
visibility
comments {
messagesCount
messages {
Expand All @@ -58,43 +59,26 @@ fragment SpaceIngest on Space {
}
}
framing {
id
profile {
description
displayName
tagline
url
tagset {
tags
}
references {
description
name
uri
}
visuals {
uri
name
}
...ProfileFields
}
}
contributions {
post {
id
nameID
profile {
...ProfileFields
}
}
link {
id
uri
profile {
description
displayName
url
type
references {
description
name
uri
}
visuals {
uri
name
}
...ProfileFields
}

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/space-ingest",
"version": "0.7.0",
"version": "0.8.0",
"description": "",
"author": "Alkemio Foundation",
"private": true,
Expand Down
46 changes: 30 additions & 16 deletions src/callout.handlers/base.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import { Callout } from '../generated/graphql';
import { Callout, CalloutContribution } from '../generated/graphql';
import { Document } from 'langchain/document';
import generateDocument from '../generate.document';

export const baseHandler = async (
callout: Partial<Callout>
): Promise<Document[]> => {
const { id: documentId, type } = callout;

const generated = generateDocument(callout.framing);
const { title, source } = generated;
let pageContent = generated.pageContent;

// extra loop but will do for now
const contributions = callout.contributions
?.filter((article: any) => !!article.link)
.map((contribution: any) => {
const { pageContent: contribArticle } = generateDocument(
contribution.link
);
return contribArticle;
})
.join('\n');

if (contributions)
pageContent = `${pageContent}\nContributions:\n${contributions}`;

const messages = callout.comments?.messages || [];
const processedMessages: string[] = [];
for (let i = 0; i < messages.length; i++) {
Expand All @@ -44,7 +31,7 @@ export const baseHandler = async (
if (processedMessages.length)
pageContent = `${pageContent}\nMessages:\n${processedMessages.join('\n')}`;

return [
const result: Document[] = [
new Document({
pageContent,
metadata: {
Expand All @@ -55,4 +42,31 @@ export const baseHandler = async (
},
}),
];

// extra loop but will do for now
callout.contributions
?.map((contribution: Partial<CalloutContribution>) => {
let docLike;
if (!!contribution.link) {
docLike = contribution.link;
} else if (!!contribution.post) {
docLike = contribution.post;
}
const { pageContent, documentId, source, type, title } =
generateDocument(docLike);
result.push(
new Document({
pageContent,
metadata: {
documentId,
source,
type,
title,
},
})
);
})
.join('\n');

return result;
};
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CHUNK_SIZE = parseInt(process.env.CHUNK_SIZE || '1000');
export const CHUNK_OVERLAP = parseInt(process.env.CHUNK_OVERLAP || '100');
export const BATCH_SIZE = parseInt(process.env.BATCH_SIZE || '20');
10 changes: 7 additions & 3 deletions src/generate.document.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Reference, Visual } from './generated/graphql';
import { DocumentType, mapType } from './document.type';

interface GeneratedDocument {
Expand All @@ -8,6 +9,7 @@ interface GeneratedDocument {
title: string;
}

//TODO type this pls
export default (docLike: any): GeneratedDocument => {
const {
id: documentId,
Expand All @@ -21,9 +23,11 @@ export default (docLike: any): GeneratedDocument => {
displayName,
location,
visuals,
type: profileType,
},
context,
} = docLike;

const { vision, impact, who } = context || {};
const { city, country, postalCode } = location || {};

Expand All @@ -37,7 +41,7 @@ export default (docLike: any): GeneratedDocument => {
if (who) pageContent = `${pageContent}\nWho: ${who}`;

const processedVisuals = visuals
.map((visual: any) => `\t${visual.name}: ${visual.uri}`)
.map((visual: Visual) => `\t${visual.name}: ${visual.uri}`)
.join('\n');
if (processedVisuals)
pageContent = `${pageContent}\nVisuals: ${processedVisuals}`;
Expand All @@ -46,7 +50,7 @@ export default (docLike: any): GeneratedDocument => {
pageContent = `${pageContent}\nLocation: ${postalCode} ${city} ${country}`;

const processedRefs = references.map(
({ description, name, uri }: any) =>
({ description, name, uri }: Reference) =>
`\tReference name: ${name}\n\tReference description: ${description}\n\tUri: ${uri}\n`
);
if (processedRefs)
Expand All @@ -56,7 +60,7 @@ export default (docLike: any): GeneratedDocument => {
return {
documentId,
source,
type: mapType(type),
type: mapType(type ?? profileType),
pageContent,
title: displayName,
};
Expand Down
Loading

0 comments on commit 46bc07b

Please sign in to comment.