Skip to content

Commit

Permalink
Ingest call for posts (#42)
Browse files Browse the repository at this point in the history
* include infor about call for posts callout
basic processing of the posts
@wip

* filter out unpublished callouts
cleanup

* bring back tagsets

* cleanup
  • Loading branch information
valeksiev authored Jul 5, 2024
1 parent 978eff4 commit e52333a
Show file tree
Hide file tree
Showing 8 changed files with 524 additions and 368 deletions.
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
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;
};
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 e52333a

Please sign in to comment.