From 73e00a7a9489d81cdd19f7da08acdcffdbe0fdfa Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 24 Jul 2024 14:15:50 +0200 Subject: [PATCH] #820 - Update endpoints --- src/constants/Links.ts | 8 +++- src/services/SponsorAI.ts | 84 +++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/constants/Links.ts b/src/constants/Links.ts index a28d7ec3..04d4007e 100644 --- a/src/constants/Links.ts +++ b/src/constants/Links.ts @@ -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: { diff --git a/src/services/SponsorAI.ts b/src/services/SponsorAI.ts index fe459b5f..9d5df6ef 100644 --- a/src/services/SponsorAI.ts +++ b/src/services/SponsorAI.ts @@ -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 @@ -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(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(SETTING_SEO_TITLE_LENGTH) || 60 + }), + signal: signal as any + } + ); clearTimeout(timeout); const data: string[] = await response.json(); @@ -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(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(SETTING_SEO_DESCRIPTION_LENGTH) || 160 + }), + signal: signal as any + } + ); clearTimeout(timeout); const data: string = await response.text(); @@ -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) {