11import { chatHistorySampleData } from '../constants/chatHistory'
22
3- import { ChatMessage , Conversation , ConversationRequest , SectionGenerateRequest , CosmosDBHealth , CosmosDBStatus , UserInfo , ChatType } from './models'
3+ import {
4+ ChatMessage ,
5+ Conversation ,
6+ ConversationRequest ,
7+ SectionGenerateRequest ,
8+ CosmosDBHealth ,
9+ CosmosDBStatus ,
10+ UserInfo ,
11+ ChatType
12+ } from './models'
413
5- export async function conversationApi ( options : ConversationRequest , abortSignal : AbortSignal , chatType : ChatType = ChatType . Browse ) : Promise < Response > {
14+ export async function conversationApi (
15+ options : ConversationRequest ,
16+ abortSignal : AbortSignal ,
17+ chatType : ChatType = ChatType . Browse
18+ ) : Promise < Response > {
619 const response = await fetch ( '/conversation' , {
720 method : 'POST' ,
821 headers : {
@@ -116,7 +129,8 @@ export const historyRead = async (convId: string): Promise<ChatMessage[]> => {
116129export const historyGenerate = async (
117130 options : ConversationRequest ,
118131 abortSignal : AbortSignal ,
119- convId ?: string , chatType : ChatType = ChatType . Browse
132+ convId ?: string ,
133+ chatType : ChatType = ChatType . Browse
120134) : Promise < Response > => {
121135 let body
122136 if ( convId ) {
@@ -357,22 +371,20 @@ export const historyMessageFeedback = async (messageId: string, feedback: string
357371 return response
358372}
359373
360- export const sectionGenerate = async (
361- options : SectionGenerateRequest ,
362- ) : Promise < Response > => {
374+ export const sectionGenerate = async ( options : SectionGenerateRequest ) : Promise < Response > => {
363375 // set timeout to 10 seconds
364376 const abortController = new AbortController ( )
365377 const abortSignal = abortController . signal
366378
367379 const timeout = setTimeout ( ( ) => {
368380 abortController . abort ( )
369381 } , 10000 )
370-
382+
371383 let body = JSON . stringify ( {
372384 sectionTitle : options . sectionTitle ,
373- sectionDescription : options . sectionDescription ,
385+ sectionDescription : options . sectionDescription
374386 } )
375-
387+
376388 const response = await fetch ( '/section/generate' , {
377389 method : 'POST' ,
378390 headers : {
@@ -388,9 +400,11 @@ export const sectionGenerate = async (
388400 . catch ( _err => {
389401 clearTimeout ( timeout )
390402 console . error ( 'There was an issue fetching your data.' )
391- return new Response ( )
403+ return new Response (
404+ JSON . stringify ( { section_content : 'There was an issue fetching your data. Please try again.' } )
405+ )
392406 } )
393-
407+
394408 return response
395409}
396410
@@ -399,8 +413,12 @@ export const documentRead = async (docId: string): Promise<Response> => {
399413 method : 'GET' ,
400414 headers : { 'Content-Type' : 'application/json' }
401415 } )
402- . then ( res => { return res } )
403- . catch ( _err => { throw new Error ( 'There was an issue fetching your data.' ) } )
416+ . then ( res => {
417+ return res
418+ } )
419+ . catch ( _err => {
420+ throw new Error ( 'There was an issue fetching your data.' )
421+ } )
404422
405423 return response
406424}
0 commit comments