@@ -9,6 +9,10 @@ namespace sample.demo
99{
1010 public class Chat
1111 {
12+ // Location to store chat history
13+ const string DefaultChatStorageConnectionSetting = "OpenAiStorageConnection" ;
14+ const string DefaultCollectionName = "ChatState" ;
15+
1216 private readonly ILogger < Chat > _logger ;
1317
1418 public Chat ( ILogger < Chat > logger )
@@ -33,7 +37,11 @@ string assistantId
3337 return new CreateChatBotOutput
3438 {
3539 HttpResponse = new OkObjectResult ( responseJson ) ,
36- ChatBotCreateRequest = new AssistantCreateRequest ( assistantId , instructions ) ,
40+ ChatBotCreateRequest = new AssistantCreateRequest ( assistantId , instructions )
41+ {
42+ ChatStorageConnectionSetting = DefaultChatStorageConnectionSetting ,
43+ CollectionName = DefaultCollectionName
44+ } ,
3745 } ;
3846 }
3947
@@ -52,13 +60,15 @@ public static PostResponseOutput ChatQuery(
5260 [ AssistantPostInput (
5361 "{assistantId}" ,
5462 "{prompt}" ,
55- Model = "%AZURE_OPENAI_CHATGPT_DEPLOYMENT%"
63+ Model = "%AZURE_OPENAI_CHATGPT_DEPLOYMENT%" ,
64+ ChatStorageConnectionSetting = DefaultChatStorageConnectionSetting ,
65+ CollectionName = DefaultCollectionName
5666 ) ]
5767 AssistantState state
5868 )
5969 {
6070 // Send response to client in expected format, including assistantId
61- var _answer = new answer (
71+ var _answer = new AnswerResponse (
6272 new string [ ] { } ,
6373 state . RecentMessages . LastOrDefault ( ) ? . Content ?? "No response returned." ,
6474 ""
@@ -72,12 +82,12 @@ public static IActionResult GetChatState(
7282 [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , Route = "chat/{assistantId}" ) ]
7383 HttpRequestData req ,
7484 string assistantId ,
75- [ AssistantQueryInput ( "{assistantId}" , TimestampUtc = "{Query.timestampUTC}" ) ]
85+ [ AssistantQueryInput ( "{assistantId}" , TimestampUtc = "{Query.timestampUTC}" , ChatStorageConnectionSetting = DefaultChatStorageConnectionSetting , CollectionName = DefaultCollectionName ) ]
7686 AssistantState state
7787 )
7888 {
7989 // Returns the last message from the history table which will be the latest answer to the last question
80- var _answer = new answer (
90+ var _answer = new AnswerResponse (
8191 new string [ ] { } ,
8292 state . RecentMessages . LastOrDefault ( ) ? . Content ?? "No response returned." ,
8393 ""
@@ -95,7 +105,7 @@ public class CreateChatBotOutput
95105 public IActionResult ? HttpResponse { get ; set ; }
96106 }
97107
98- public record answer (
108+ public record AnswerResponse (
99109 [ property: JsonPropertyName ( "data_points" ) ] string [ ] DataPoints ,
100110 [ property: JsonPropertyName ( "answer" ) ] string Answer ,
101111 [ property: JsonPropertyName ( "thoughts" ) ] string thoughts
0 commit comments