Skip to content

Commit

Permalink
#820 - Update endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jul 24, 2024
1 parent adb5418 commit 73e00a7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 41 deletions.
8 changes: 6 additions & 2 deletions src/constants/Links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export const WEBSITE_LINKS = {
api: {
baseUrl: 'https://fontmatter-fncs.azurewebsites.net',
endpoints: {
ai: '/api/ai',
ai: {
description: '/api/ai/description',
taxonomy: '/api/ai/taxonomy',
title: '/api/ai/title'
},
chat: {
init: '/api/ai-init',
message: '/api/ai-chat',
feedback: '/api/ai-feedback'
},
backers: '/api/backers'
backers: '/api/v2/backers'
}
},
docs: {
Expand Down
84 changes: 45 additions & 39 deletions src/services/SponsorAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { TaxonomyType } from '../models';
import * as l10n from '@vscode/l10n';
import { LocalizationKey } from '../localization';

const AI_URL = `${WEBSITE_LINKS.api.baseUrl}${WEBSITE_LINKS.api.endpoints.ai}`;
// const AI_URL = 'http://localhost:3000/api/ai';

export class SponsorAi {
/**
* Get title suggestions from the AI
Expand All @@ -28,19 +25,22 @@ export class SponsorAi {
}, 10000);
const signal = controller.signal;

const response = await fetch(`${AI_URL}/title`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify({
title: title,
token: token,
nrOfCharacters: Settings.get<number>(SETTING_SEO_TITLE_LENGTH) || 60
}),
signal: signal as any
});
const response = await fetch(
`${WEBSITE_LINKS.api.baseUrl}${WEBSITE_LINKS.api.endpoints.ai.title}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify({
title: title,
token: token,
nrOfCharacters: Settings.get<number>(SETTING_SEO_TITLE_LENGTH) || 60
}),
signal: signal as any
}
);
clearTimeout(timeout);

const data: string[] = await response.json();
Expand All @@ -66,20 +66,23 @@ export class SponsorAi {
articleContent = articleContent.substring(0, 2000);
}

const response = await fetch(`${AI_URL}/description`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify({
title: title,
content: articleContent,
token: token,
nrOfCharacters: Settings.get<number>(SETTING_SEO_DESCRIPTION_LENGTH) || 160
}),
signal: signal as any
});
const response = await fetch(
`${WEBSITE_LINKS.api.baseUrl}${WEBSITE_LINKS.api.endpoints.ai.description}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify({
title: title,
content: articleContent,
token: token,
nrOfCharacters: Settings.get<number>(SETTING_SEO_DESCRIPTION_LENGTH) || 160
}),
signal: signal as any
}
);
clearTimeout(timeout);

const data: string = await response.text();
Expand Down Expand Up @@ -129,15 +132,18 @@ export class SponsorAi {
taxonomy: optionsString
});

const response = await fetch(`${AI_URL}/taxonomy`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body,
signal: signal as any
});
const response = await fetch(
`${WEBSITE_LINKS.api.baseUrl}${WEBSITE_LINKS.api.endpoints.ai.taxonomy}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body,
signal: signal as any
}
);
clearTimeout(timeout);

if (!response.ok) {
Expand Down

0 comments on commit 73e00a7

Please sign in to comment.