Skip to content

Commit ec86455

Browse files
authored
Merge pull request #21 from eamonoreilly/main
Updating to new Azure Functions OpenAI extension version
2 parents 80f112a + 8074c61 commit ec86455

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

app/backend/ask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ SemanticSearchContext result
3232
{
3333
_logger.LogInformation("Ask function called...");
3434

35-
var _answer = new answer(new string[] { }, result.Response, "");
35+
var _answer = new AnswerResponse(new string[] { }, result.Response, "");
3636

3737
return new OkObjectResult(_answer);
3838
}
3939

40-
public record answer(
40+
public record AnswerResponse(
4141
[property: JsonPropertyName("data_points")] string[] DataPoints,
4242
[property: JsonPropertyName("answer")] string Answer,
4343
[property: JsonPropertyName("thoughts")] string Thoughts

app/backend/backend.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="HttpMultipartParser" Version="8.4.0" />
1616
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.4.0" />
1717
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
18-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenAI" Version="0.15.0-alpha" />
18+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenAI" Version="0.18.0-alpha" />
1919
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenAI.AzureAISearch" Version="0.3.0-alpha" />
2020
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
2121
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />

app/backend/chat.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/backend/host.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"isSemanticSearchEnabled": true,
2020
"useSemanticCaptions": false,
2121
"vectorSearchDimensions": 1536
22-
},
23-
"storageConnectionName": "OpenAiStorageConnection"
22+
}
2423
},
2524
"serviceBus": {
2625
"maxConcurrentCalls": 1

0 commit comments

Comments
 (0)