5959    CONFIG_AUTH_CLIENT ,
6060    CONFIG_BLOB_CONTAINER_CLIENT ,
6161    CONFIG_CHAT_APPROACH ,
62+     CONFIG_CHAT_HISTORY_BROWSER_ENABLED ,
6263    CONFIG_CHAT_VISION_APPROACH ,
6364    CONFIG_CREDENTIAL ,
6465    CONFIG_GPT4V_DEPLOYED ,
7980    CONFIG_VECTOR_SEARCH_ENABLED ,
8081)
8182from  core .authentication  import  AuthenticationHelper 
83+ from  core .sessionhelper  import  create_session_id 
8284from  decorators  import  authenticated , authenticated_path 
8385from  error  import  error_dict , error_response 
8486from  prepdocs  import  (
@@ -218,10 +220,15 @@ async def chat(auth_claims: Dict[str, Any]):
218220        else :
219221            approach  =  cast (Approach , current_app .config [CONFIG_CHAT_APPROACH ])
220222
223+         # If session state is provided, persists the session state, 
224+         # else creates a new session_id depending on the chat history options enabled. 
225+         session_state  =  request_json .get ("session_state" )
226+         if  session_state  is  None :
227+             session_state  =  create_session_id (current_app .config [CONFIG_CHAT_HISTORY_BROWSER_ENABLED ])
221228        result  =  await  approach .run (
222229            request_json ["messages" ],
223230            context = context ,
224-             session_state = request_json . get ( " session_state" ) ,
231+             session_state = session_state ,
225232        )
226233        return  jsonify (result )
227234    except  Exception  as  error :
@@ -244,10 +251,15 @@ async def chat_stream(auth_claims: Dict[str, Any]):
244251        else :
245252            approach  =  cast (Approach , current_app .config [CONFIG_CHAT_APPROACH ])
246253
254+         # If session state is provided, persists the session state, 
255+         # else creates a new session_id depending on the chat history options enabled. 
256+         session_state  =  request_json .get ("session_state" )
257+         if  session_state  is  None :
258+             session_state  =  create_session_id (current_app .config [CONFIG_CHAT_HISTORY_BROWSER_ENABLED ])
247259        result  =  await  approach .run_stream (
248260            request_json ["messages" ],
249261            context = context ,
250-             session_state = request_json . get ( " session_state" ) ,
262+             session_state = session_state ,
251263        )
252264        response  =  await  make_response (format_as_ndjson (result ))
253265        response .timeout  =  None   # type: ignore 
@@ -276,6 +288,7 @@ def config():
276288            "showSpeechInput" : current_app .config [CONFIG_SPEECH_INPUT_ENABLED ],
277289            "showSpeechOutputBrowser" : current_app .config [CONFIG_SPEECH_OUTPUT_BROWSER_ENABLED ],
278290            "showSpeechOutputAzure" : current_app .config [CONFIG_SPEECH_OUTPUT_AZURE_ENABLED ],
291+             "showChatHistoryBrowser" : current_app .config [CONFIG_CHAT_HISTORY_BROWSER_ENABLED ],
279292        }
280293    )
281294
@@ -439,6 +452,7 @@ async def setup_clients():
439452    USE_SPEECH_INPUT_BROWSER  =  os .getenv ("USE_SPEECH_INPUT_BROWSER" , "" ).lower () ==  "true" 
440453    USE_SPEECH_OUTPUT_BROWSER  =  os .getenv ("USE_SPEECH_OUTPUT_BROWSER" , "" ).lower () ==  "true" 
441454    USE_SPEECH_OUTPUT_AZURE  =  os .getenv ("USE_SPEECH_OUTPUT_AZURE" , "" ).lower () ==  "true" 
455+     USE_CHAT_HISTORY_BROWSER  =  os .getenv ("USE_CHAT_HISTORY_BROWSER" , "" ).lower () ==  "true" 
442456
443457    # WEBSITE_HOSTNAME is always set by App Service, RUNNING_IN_PRODUCTION is set in main.bicep 
444458    RUNNING_ON_AZURE  =  os .getenv ("WEBSITE_HOSTNAME" ) is  not None  or  os .getenv ("RUNNING_IN_PRODUCTION" ) is  not None 
@@ -609,6 +623,7 @@ async def setup_clients():
609623    current_app .config [CONFIG_SPEECH_INPUT_ENABLED ] =  USE_SPEECH_INPUT_BROWSER 
610624    current_app .config [CONFIG_SPEECH_OUTPUT_BROWSER_ENABLED ] =  USE_SPEECH_OUTPUT_BROWSER 
611625    current_app .config [CONFIG_SPEECH_OUTPUT_AZURE_ENABLED ] =  USE_SPEECH_OUTPUT_AZURE 
626+     current_app .config [CONFIG_CHAT_HISTORY_BROWSER_ENABLED ] =  USE_CHAT_HISTORY_BROWSER 
612627
613628    # Various approaches to integrate GPT and external knowledge, most applications will use a single one of these patterns 
614629    # or some derivative, here we include several for exploration purposes 
0 commit comments