Skip to content

Commit

Permalink
chore: use ai endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Jun 20, 2023
1 parent f1be88b commit c342772
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 41 deletions.
3 changes: 1 addition & 2 deletions apps/web/src/components/Composer/NewPublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
import collectModuleParams from '@lib/collectModuleParams';
import errorToast from '@lib/errorToast';
import getTextNftUrl from '@lib/getTextNftUrl';
import getUserLocale from '@lib/getUserLocale';
import { Leafwatch } from '@lib/leafwatch';
import uploadToArweave from '@lib/uploadToArweave';
import { t } from '@lingui/macro';
Expand Down Expand Up @@ -783,7 +782,7 @@ const NewPublication: FC<NewPublicationProps> = ({ publication }) => {
contentWarning: null,
attributes,
media: attachmentsInput,
locale: getUserLocale(),
locale: null,
appId: APP_NAME
};

Expand Down
12 changes: 0 additions & 12 deletions apps/web/src/lib/getUserLocale.ts

This file was deleted.

6 changes: 2 additions & 4 deletions packages/ai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def tagger():
data = request.get_json()
text = data["text"]

# Check if text has more than 5 words
if len(text.split()) > 5:
if len(text.split()) > 4:
topic_scores = predictTopic(text)
return jsonify({"topics": topic_scores})
else:
Expand All @@ -76,8 +75,7 @@ def locale():
data = request.get_json()
text = data["text"]

# Check if text has more than 5 words
if len(text.split()) > 5:
if len(text.split()) > 4:
locale_scores = predictLocale(text)
return jsonify({"locale": locale_scores})
else:
Expand Down
37 changes: 14 additions & 23 deletions packages/workers/metadata/src/handlers/postMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,23 @@ export default async (request: IRequest, env: Env) => {
try {
const payload: PublicationMetadataV2Input = await request.json();
const signer = new EthereumSigner(env.BUNDLR_PRIVATE_KEY);
const aiUrl = 'https://ai.lenster.xyz';
const fetchPayload = {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ text: payload.content })
};

// Generate tags using HuggingFace API
const taggerResponse = await fetch(
'https://r35q1d9vdewm7xr4.us-east-1.aws.endpoints.huggingface.cloud',
{
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: `Bearer ${env.HUGGINGFACE_API_KEY}`
},
body: JSON.stringify({
inputs: payload.content,
parameters: { top_k: 2 }
})
}
);
const responses = await Promise.all([
fetch(`${aiUrl}/tagger`, fetchPayload),
fetch(`${aiUrl}/locale`, fetchPayload)
]);

const taggerResponseJson: any = await taggerResponse.json();
let labels;
if ('error' in taggerResponseJson) {
labels = null;
} else {
labels = taggerResponseJson.slice(0, 2).map((item: any) => item.label);
}
const taggerResponseJson: any = await responses[0].json();
payload.tags = taggerResponseJson.topics;

payload.tags = labels;
const localeResponse: any = await responses[1].json();
payload.locale = localeResponse.locale;

const tx = createData(JSON.stringify(payload), signer, {
tags: [
Expand Down

0 comments on commit c342772

Please sign in to comment.