80
80
CONFIG_VECTOR_SEARCH_ENABLED ,
81
81
)
82
82
from core .authentication import AuthenticationHelper
83
+ from core .sessionhelper import create_session_id
83
84
from decorators import authenticated , authenticated_path
84
85
from error import error_dict , error_response
85
86
from prepdocs import (
@@ -219,10 +220,15 @@ async def chat(auth_claims: Dict[str, Any]):
219
220
else :
220
221
approach = cast (Approach , current_app .config [CONFIG_CHAT_APPROACH ])
221
222
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 ])
222
228
result = await approach .run (
223
229
request_json ["messages" ],
224
230
context = context ,
225
- session_state = request_json . get ( " session_state" ) ,
231
+ session_state = session_state ,
226
232
)
227
233
return jsonify (result )
228
234
except Exception as error :
@@ -245,10 +251,15 @@ async def chat_stream(auth_claims: Dict[str, Any]):
245
251
else :
246
252
approach = cast (Approach , current_app .config [CONFIG_CHAT_APPROACH ])
247
253
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 ])
248
259
result = await approach .run_stream (
249
260
request_json ["messages" ],
250
261
context = context ,
251
- session_state = request_json . get ( " session_state" ) ,
262
+ session_state = session_state ,
252
263
)
253
264
response = await make_response (format_as_ndjson (result ))
254
265
response .timeout = None # type: ignore
0 commit comments