CoolFace
Apppublic

Saelrynn/portfolio_client

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
http.ts30 linesDownload Raw Back to src
1import type { ChatPayload, ChatResponse } from '@/types'2 3const apiUrl: string = import.meta.env.VITE_API_BASE_URL4const apiChatEndpoint: string = import.meta.env.VITE_API_CHAT_ENDPOINT5const apiInitializeChatEndpoint: string = import.meta.env.VITE_API_INITIALIZE_CHAT_ENDPOINT6 7export const chatRequest = async (payload: ChatPayload): Promise<ChatResponse> => {8    const url: string = `${apiUrl}/${apiChatEndpoint}`9    const response = await fetch(url, {10        method: 'POST',11        headers: { 'Content-Type': 'application/json' },12        body: JSON.stringify(payload),13    })14 15    if (!response.ok) throw new Error(`Request failed with status ${response.status}`)16    else return await response.json() as ChatResponse17}18 19export const initializeChatMessageRequest = async (): Promise<ChatResponse> => {20    const url: string = `${apiUrl}/${apiInitializeChatEndpoint}`21    const response = await fetch(url, {22        method: 'GET',23        headers: { 'Content-Type': 'application/json' }24    })25 26    if (!response.ok) throw new Error(`Request failed with status ${response.status}`)27    else return await response.json() as ChatResponse28}29 30