azure-ai.ts
1 // Copyright (c) 2026 VPL Solutions. All rights reserved. 2 // Licensed under the MIT License. See LICENSE for details. 3 4 import { api } from './client'; 5 import type { 6 AzureAIResponse, 7 SentimentResult, 8 EntityResult, 9 VisionResult, 10 OcrResult, 11 SpeechTranscriptResult, 12 DocumentAnalysisResult, 13 } from './types'; 14 15 export const azureAiApi = { 16 // Language 17 sentiment: (text: string, language = 'en') => 18 api.post<AzureAIResponse<SentimentResult>>('/azure-ai/language/sentiment', { text, language }), 19 20 entities: (text: string, language = 'en') => 21 api.post<AzureAIResponse<EntityResult>>('/azure-ai/language/entities', { text, language }), 22 23 keyPhrases: (text: string, language = 'en') => 24 api.post<AzureAIResponse>('/azure-ai/language/key-phrases', { text, language }), 25 26 detectLanguage: (text: string) => 27 api.post<AzureAIResponse>('/azure-ai/language/detect', { text }), 28 29 // Vision 30 analyzeImage: (file: File) => { 31 const formData = new FormData(); 32 formData.append('file', file); 33 return api.postForm<AzureAIResponse<VisionResult>>('/azure-ai/vision/analyze', formData); 34 }, 35 36 ocr: (file: File) => { 37 const formData = new FormData(); 38 formData.append('file', file); 39 return api.postForm<AzureAIResponse<OcrResult>>('/azure-ai/vision/ocr', formData); 40 }, 41 42 // Speech 43 transcribe: (file: File) => { 44 const formData = new FormData(); 45 formData.append('file', file); 46 return api.postForm<AzureAIResponse<SpeechTranscriptResult>>('/azure-ai/speech/transcribe', formData); 47 }, 48 49 textToSpeech: (text: string, voice = 'en-US-JennyNeural') => 50 api.postForBlob('/azure-ai/speech/synthesize', { text, voice }), 51 52 // Document Intelligence 53 analyzeDocument: (file: File, modelId = 'prebuilt-read') => { 54 const formData = new FormData(); 55 formData.append('file', file); 56 formData.append('model_id', modelId); 57 return api.postForm<DocumentAnalysisResult>('/azure-ai/document/analyze', formData); 58 }, 59 };