Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3cfe054
relevant changes
Mar 7, 2024
f3cb413
working changes
Mar 7, 2024
4f172c6
updating project and changelog
Mar 7, 2024
19b46fe
updating sample
Mar 7, 2024
3973ace
updating project
Mar 7, 2024
1846473
merging
Mar 7, 2024
2eb2b05
fixing build
Mar 7, 2024
5c65651
trying to have this not be flakey
Mar 7, 2024
5a7bd78
adding another sleep statement
Mar 7, 2024
34b44af
fixing warnings
Mar 7, 2024
3087680
fixing null refs
Mar 7, 2024
b3c0358
initial changes
Mar 8, 2024
78ddcf3
changes
Mar 8, 2024
880abf4
changing the project since it was giving a weird error before
Mar 8, 2024
e8f4a59
forgot to include model
Mar 8, 2024
ba0bb35
merging in
Mar 8, 2024
b56ac32
changes still not working
Mar 11, 2024
cd38280
got ingest email working
Mar 12, 2024
2a0ba9f
changes working for other function but still not working with new worker
Mar 12, 2024
93ef739
merging in changes from main
Mar 22, 2024
521c737
fixing sln file
Mar 22, 2024
50c2a40
changing some things back
Mar 23, 2024
8b751df
latest changes to get it compiling
Mar 25, 2024
378cb98
cleaning up project
Mar 26, 2024
5a68022
merge conflict
Mar 26, 2024
a744bcb
changes
Mar 26, 2024
3fdd375
adding localsettingsjson
Mar 26, 2024
cc197d1
fixing small mistake
Mar 26, 2024
edff897
comments
Mar 28, 2024
624f739
fixing alphabetic order
Mar 28, 2024
668fca2
Update CHANGELOG.md
aishwaryabh Mar 28, 2024
9368d69
changes to input and output binding
Mar 28, 2024
424c708
Merge branch 'aibhandari/rag-semantic-support' of https://github.com/…
Mar 28, 2024
9edc60d
finally works after so long
Mar 28, 2024
daf11d0
trying out pipeline change
Mar 28, 2024
3aa1dea
trying another pipeline change
Mar 28, 2024
a6a7a57
build still not working
Mar 28, 2024
43b4359
change
Mar 29, 2024
7cc13c7
updating small thing
Mar 29, 2024
d0625da
trying out new package
Mar 29, 2024
1aa8076
changing condition
Mar 29, 2024
39c947e
trying again
Apr 1, 2024
32627f3
forgot to remove quote
Apr 1, 2024
678c247
another change in yaml file
Apr 1, 2024
899d4bf
adding config file
Apr 1, 2024
9c18d20
figuring out which directory we're in
Apr 1, 2024
8c75c19
forgot root ref
Apr 1, 2024
1a6c738
just tryna get to etc directory
Apr 1, 2024
ffcf634
change
Apr 1, 2024
1b8ff00
trying again
Apr 1, 2024
75d7d99
trying again
Apr 1, 2024
2b12e9a
this already exists
Apr 1, 2024
b546402
tryign user level
Apr 1, 2024
da8c996
lol trying again
Apr 1, 2024
8fc712d
trying diff path
Apr 1, 2024
5b76e68
found nuget path fr
Apr 1, 2024
eb02739
trying again
Apr 1, 2024
71c4d66
getting rid of extra dependency package
Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Starting v0.1.0 for Microsoft.Azure.WebJobs.Extensions.OpenAI.AzureAISearch, it

- Added dotnet-isolated support for Embeddings
- Added support for multiple search providers.
- Added dotnet-isolated support for Kusto and Azure AI Search RAG scenarios.

### Breaking changes

Expand Down
32 changes: 23 additions & 9 deletions OpenAI-Extension.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assistant", "assistant", "{
samples\assistant\demo.http = samples\assistant\demo.http
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "rag", "rag", "{4CD51D81-D334-4FBC-A82B-8E2408913B7D}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "rag-kusto", "rag-kusto", "{4CD51D81-D334-4FBC-A82B-8E2408913B7D}"
ProjectSection(SolutionItems) = preProject
samples\rag\csharp-inproc\demo.http = samples\rag\csharp-inproc\demo.http
samples\rag-kusto\csharp-ooproc\demo.http = samples\rag-kusto\csharp-ooproc\demo.http
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticSearchEmbeddings", "samples\rag\csharp-inproc\SemanticSearchEmbeddings.csproj", "{BD2064F5-6F56-45D4-A2E9-5C276FDAF4B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticSearchEmbeddings", "samples\rag-kusto\csharp-ooproc\SemanticSearchEmbeddings.csproj", "{3E9B9A7F-A98D-4CDD-9528-6D3077CAA4DA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssistantSample", "samples\assistant\csharp-ooproc\AssistantSample\AssistantSample.csproj", "{8573FE76-9920-4A95-9D29-911FD6B0AB25}"
EndProject
Expand All @@ -67,7 +67,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "rag-aisearch", "rag-aisearc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Embeddings", "samples\embeddings\csharp-ooproc\Embeddings\Embeddings.csproj", "{C9CCD98A-B4E5-4E8E-9163-F86AF2DBB645}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticAISearchEmbeddings", "samples\rag-aisearch\csharp-inproc\SemanticAISearchEmbeddings.csproj", "{21EE2832-FDEB-4D5A-BD72-61BDDF86DC2B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticAISearchEmbeddings", "samples\rag-aisearch\csharp-ooproc\SemanticAISearchEmbeddings.csproj", "{21EE2832-FDEB-4D5A-BD72-61BDDF86DC2B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Functions.Worker.Extensions.OpenAI.Kusto", "src\Functions.Worker.Extensions.OpenAI.Kusto\Functions.Worker.Extensions.OpenAI.Kusto.csproj", "{F413D075-38DA-4357-AB60-E6E157018827}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Functions.Worker.Extensions.OpenAI.AzureAISearch", "src\Functions.Worker.Extensions.OpenAI.AzureAISearch\Functions.Worker.Extensions.OpenAI.AzureAISearch.csproj", "{CAB7034D-FBA9-4A7D-B50B-E9029DFD0DEF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -95,10 +99,10 @@ Global
{6701A54D-E00F-46E8-9344-B1547805459E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6701A54D-E00F-46E8-9344-B1547805459E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6701A54D-E00F-46E8-9344-B1547805459E}.Release|Any CPU.Build.0 = Release|Any CPU
{BD2064F5-6F56-45D4-A2E9-5C276FDAF4B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD2064F5-6F56-45D4-A2E9-5C276FDAF4B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD2064F5-6F56-45D4-A2E9-5C276FDAF4B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD2064F5-6F56-45D4-A2E9-5C276FDAF4B1}.Release|Any CPU.Build.0 = Release|Any CPU
{3E9B9A7F-A98D-4CDD-9528-6D3077CAA4DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E9B9A7F-A98D-4CDD-9528-6D3077CAA4DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E9B9A7F-A98D-4CDD-9528-6D3077CAA4DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E9B9A7F-A98D-4CDD-9528-6D3077CAA4DA}.Release|Any CPU.Build.0 = Release|Any CPU
{8573FE76-9920-4A95-9D29-911FD6B0AB25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8573FE76-9920-4A95-9D29-911FD6B0AB25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8573FE76-9920-4A95-9D29-911FD6B0AB25}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -119,6 +123,14 @@ Global
{21EE2832-FDEB-4D5A-BD72-61BDDF86DC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21EE2832-FDEB-4D5A-BD72-61BDDF86DC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21EE2832-FDEB-4D5A-BD72-61BDDF86DC2B}.Release|Any CPU.Build.0 = Release|Any CPU
{F413D075-38DA-4357-AB60-E6E157018827}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F413D075-38DA-4357-AB60-E6E157018827}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F413D075-38DA-4357-AB60-E6E157018827}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F413D075-38DA-4357-AB60-E6E157018827}.Release|Any CPU.Build.0 = Release|Any CPU
{CAB7034D-FBA9-4A7D-B50B-E9029DFD0DEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAB7034D-FBA9-4A7D-B50B-E9029DFD0DEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAB7034D-FBA9-4A7D-B50B-E9029DFD0DEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAB7034D-FBA9-4A7D-B50B-E9029DFD0DEF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -134,13 +146,15 @@ Global
{6701A54D-E00F-46E8-9344-B1547805459E} = {46888A9D-8058-499C-9F2F-07800FF686EB}
{C5578BE5-AAC7-4616-9A35-41CA5903882A} = {865C9FB5-1043-47BE-B650-25A2B42030A3}
{4CD51D81-D334-4FBC-A82B-8E2408913B7D} = {865C9FB5-1043-47BE-B650-25A2B42030A3}
{BD2064F5-6F56-45D4-A2E9-5C276FDAF4B1} = {4CD51D81-D334-4FBC-A82B-8E2408913B7D}
{3E9B9A7F-A98D-4CDD-9528-6D3077CAA4DA} = {4CD51D81-D334-4FBC-A82B-8E2408913B7D}
{8573FE76-9920-4A95-9D29-911FD6B0AB25} = {C5578BE5-AAC7-4616-9A35-41CA5903882A}
{32196912-898F-428E-94EF-4C2333367977} = {7A80B95C-AD57-4057-AED0-48629B75874F}
{346BE57C-341F-4EF4-A81A-BAC9D2F5B938} = {7A80B95C-AD57-4057-AED0-48629B75874F}
{3E836929-3691-4DD1-AB8D-F3E0C3A42B5F} = {865C9FB5-1043-47BE-B650-25A2B42030A3}
{C9CCD98A-B4E5-4E8E-9163-F86AF2DBB645} = {4B55F637-B067-43B4-B6FC-65171654315C}
{21EE2832-FDEB-4D5A-BD72-61BDDF86DC2B} = {3E836929-3691-4DD1-AB8D-F3E0C3A42B5F}
{F413D075-38DA-4357-AB60-E6E157018827} = {7A80B95C-AD57-4057-AED0-48629B75874F}
{CAB7034D-FBA9-4A7D-B50B-E9029DFD0DEF} = {7A80B95C-AD57-4057-AED0-48629B75874F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {05A7A679-3A53-45B5-AE93-4313655E127D}
Expand Down
58 changes: 42 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenA
)<br/>
[![NuGet](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenAI.Kusto.svg?label=microsoft.azure.webjobs.extensions.openai.kusto)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenAI.Kusto)<br/>
[![NuGet](https://img.shields.io/nuget/v/Microsoft.Azure.WebJobs.Extensions.OpenAI.AzureAISearch.svg?label=microsoft.azure.webjobs.extensions.openai.azureaisearch)](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenAI.AzureAISearch)
[![NuGet](https://img.shields.io/nuget/v/Microsoft.Azure.Functions.Worker.Extensions.OpenAI.Kusto.svg?label=microsoft.azure.functions.worker.extensions.openAI.kusto)](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenAI.Kusto)
Comment thread
aishwaryabh marked this conversation as resolved.
[![NuGet](https://img.shields.io/nuget/v/Microsoft.Azure.Functions.Worker.Extensions.OpenAI.AzureAISearch.svg?label=microsoft.azure.functions.worker.extensions.openAI.azureAISearch)](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.OpenAI.AzureAISearch)

## Requirements

Expand Down Expand Up @@ -269,36 +271,60 @@ The semantic search feature allows you to import documents into a vector databas

More may be added over time.

#### [C# document storage example](./samples/rag-aisearch/csharp-inproc/FilePrompt.cs)
#### [C# document storage example](./samples/rag-aisearch/csharp-ooproc/FilePrompt.cs)

This HTTP trigger function takes a path to a local file as input, generates embeddings for the file, and stores the result into an Azure AI Search Index.

```csharp
public record EmbeddingsRequest(string FilePath);
public class EmbeddingsRequest
{
[JsonPropertyName("FilePath")]
public string? FilePath { get; set; }
}

[FunctionName("IngestFile")]
public static async Task<IActionResult> IngestFile(
[HttpTrigger(AuthorizationLevel.Function, "post")] EmbeddingsRequest req,
[Embeddings("{FilePath}", InputType.FilePath, Model = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] EmbeddingsContext embeddings,
[SemanticSearch("AISearchEndpoint", "openai-index", CredentialSettingName = "SearchAPIKey", ChatModel = "%CHAT_MODEL_DEPLOYMENT_NAME%", EmbeddingsModel = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] IAsyncCollector<SearchableDocument> output)
[Function("IngestFile")]
public static async Task<SemanticSearchOutputResponse> IngestFile(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
[EmbeddingsInput("{FilePath}", InputType.FilePath, Model = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] EmbeddingsContext embeddings)
{
string title = Path.GetFileNameWithoutExtension(req.FilePath);
await output.AddAsync(new SearchableDocument(title, embeddings));
return new OkObjectResult(new { status = "success", title, chunks = embeddings.Count });
using StreamReader reader = new(req.Body);
string request = await reader.ReadToEndAsync();

EmbeddingsRequest? requestBody = JsonSerializer.Deserialize<EmbeddingsRequest>(request);

if (requestBody == null)
{
throw new ArgumentException("Invalid request body. Make sure that you pass in {\"filePath\": value } as the request body.");
}

string title = Path.GetFileNameWithoutExtension(requestBody.FilePath);

HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(new { status = "success", title, chunks = embeddings.Count });

return new SemanticSearchOutputResponse
{
HttpResponse = response,
SearchableDocument = new SearchableDocument(title, embeddings)
};
}
```

#### [C# document query example](./samples/rag-aisearch/csharp-inproc/FilePrompt.cs)
#### [C# document query example](./samples/rag-aisearch/csharp-ooproc/FilePrompt.cs)

This HTTP trigger function takes a query prompt as input, pulls in semantically similar document chunks into a prompt, and then sends the combined prompt to OpenAI. The results are then made available to the function, which simply returns that chat response to the caller.

```csharp
public record SemanticSearchRequest(string Prompt);
public class SemanticSearchRequest
{
[JsonPropertyName("Prompt")]
public string? Prompt { get; set; }
}

[FunctionName("PromptFile")]
[Function("PromptFile")]
public static IActionResult PromptFile(
[HttpTrigger(AuthorizationLevel.Function, "post")] SemanticSearchRequest unused,
[SemanticSearch("AISearchEndpoint", "openai-index", CredentialSettingName = "SearchAPIKey", Query = "{Prompt}", ChatModel = "%CHAT_MODEL_DEPLOYMENT_NAME%", EmbeddingsModel = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] SemanticSearchContext result)
[SemanticSearchInput("AISearchEndpoint", "openai-index", CredentialSettingName = "SearchAPIKey", Query = "{Prompt}", ChatModel = "%CHAT_MODEL_DEPLOYMENT_NAME%", EmbeddingsModel = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] SemanticSearchContext result)
{
return new ContentResult { Content = result.Response, ContentType = "text/plain" };
}
Expand Down Expand Up @@ -331,7 +357,7 @@ All samples in this project rely on default model selection, which assumes the m

```csharp
// "gpt-35-turbo" is the name of an Azure OpenAI deployment
[FunctionName(nameof(WhoIs))]
[Function(nameof(WhoIs))]
public static string WhoIs(
[HttpTrigger(AuthorizationLevel.Function, Route = "whois/{name}")] HttpRequest req,
[TextCompletion("Who is {name}?", Model = "gpt-35-turbo")] TextCompletionResponse response)
Expand All @@ -344,7 +370,7 @@ public static string WhoIs(
public record SemanticSearchRequest(string Prompt);

// "my-gpt-4" and "my-ada-2" are the names of Azure OpenAI deployments corresponding to gpt-4 and text-embedding-3-small models, respectively
[FunctionName("PromptEmail")]
[Function("PromptEmail")]
public static IActionResult PromptEmail(
[HttpTrigger(AuthorizationLevel.Function, "post")] SemanticSearchRequest unused,
[SemanticSearch("KustoConnectionString", "Documents", Query = "{Prompt}", ChatModel = "my-gpt-4", EmbeddingsModel = "my-ada-2")] SemanticSearchContext result)
Expand Down
6 changes: 5 additions & 1 deletion build/build-pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ steps:

- script: |
dotnet build $(System.DefaultWorkingDirectory)/src/WebJobs.Extensions.OpenAI/WebJobs.Extensions.OpenAI.csproj --configuration $(config) -p:WebJobsVersion=$(fakeWebJobsPackageVersion) -p:Version=$(fakeWebJobsPackageVersion)
dotnet build $(System.DefaultWorkingDirectory)/src/WebJobs.Extensions.OpenAI.Kusto/WebJobs.Extensions.OpenAI.Kusto.csproj --configuration $(config) -p:Version=$(fakeWebJobsPackageVersion)
dotnet build $(System.DefaultWorkingDirectory)/src/WebJobs.Extensions.OpenAI.AzureAISearch/WebJobs.Extensions.OpenAI.AzureAISearch.csproj --configuration $(config) -p:Version=$(fakeWebJobsPackageVersion)
sudo cp "$(System.DefaultWorkingDirectory)/src/WebJobs.Extensions.OpenAI/bin/Release/Microsoft.Azure.WebJobs.Extensions.OpenAI.$(fakeWebJobsPackageVersion).nupkg" ~/NuGetPackagesLocal
sudo cp "$(System.DefaultWorkingDirectory)/src/WebJobs.Extensions.OpenAI.AzureAISearch/bin/Release/Microsoft.Azure.WebJobs.Extensions.OpenAI.AzureAISearch.$(fakeWebJobsPackageVersion).nupkg" ~/NuGetPackagesLocal
sudo cp "$(System.DefaultWorkingDirectory)/src/WebJobs.Extensions.OpenAI.Kusto/bin/Release/Microsoft.Azure.WebJobs.Extensions.OpenAI.Kusto.$(fakeWebJobsPackageVersion).nupkg" ~/NuGetPackagesLocal

sleep 10s

Expand All @@ -70,7 +74,7 @@ steps:

sleep 10s

dotnet build --configuration $(config) /p:WebJobsVersion=$(fakeWebJobsPackageVersion)
dotnet build --configuration $(config) /p:WebJobsVersion=$(fakeWebJobsPackageVersion) /p:Version=$(fakeWebJobsPackageVersion)
displayName: Create/Copy NuGet Package to local directory and Build

- script: dotnet test --configuration $(config) --no-build --verbosity normal
Expand Down
39 changes: 0 additions & 39 deletions samples/rag-aisearch/csharp-inproc/FilePrompt.cs

This file was deleted.

This file was deleted.

73 changes: 73 additions & 0 deletions samples/rag-aisearch/csharp-ooproc/FilePrompt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.OpenAI.Embeddings;
using Microsoft.Azure.Functions.Worker.Extensions.OpenAI.Search;
using Microsoft.Azure.Functions.Worker.Http;

namespace SemanticAISearchEmbeddings;

public static class FilePrompt
{
public class EmbeddingsRequest
{
[JsonPropertyName("FilePath")]
public string? FilePath { get; set; }
}

public class SemanticSearchRequest
{
[JsonPropertyName("Prompt")]
public string? Prompt { get; set; }
}

// REVIEW: There are several assumptions about how the Embeddings binding and the SemanticSearch bindings
// work together. We should consider creating a higher-level of abstraction for this.
[Function("IngestFile")]
public static async Task<SemanticSearchOutputResponse> IngestFile(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
[EmbeddingsInput("{FilePath}", InputType.FilePath, Model = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] EmbeddingsContext embeddings)
{
using StreamReader reader = new(req.Body);
string request = await reader.ReadToEndAsync();

EmbeddingsRequest? requestBody = JsonSerializer.Deserialize<EmbeddingsRequest>(request);

if (requestBody == null)
{
throw new ArgumentException("Invalid request body. Make sure that you pass in {\"filePath\": value } as the request body.");
}

string title = Path.GetFileNameWithoutExtension(requestBody.FilePath);

HttpResponseData response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(new { status = "success", title, chunks = embeddings.Count });

return new SemanticSearchOutputResponse
{
HttpResponse = response,
SearchableDocument = new SearchableDocument(title, embeddings)
};
}

public class SemanticSearchOutputResponse
{
[SemanticSearchOutput("AISearchEndpoint", "openai-index", CredentialSettingName = "SearchAPIKey", EmbeddingsModel = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")]
public SearchableDocument SearchableDocument { get; set; }

public HttpResponseData? HttpResponse { get; set; }
}

[Function("PromptFile")]
public static IActionResult PromptFile(
[HttpTrigger(AuthorizationLevel.Function, "post")] SemanticSearchRequest unused,
[SemanticSearchInput("AISearchEndpoint", "openai-index", CredentialSettingName = "SearchAPIKey", Query = "{Prompt}", ChatModel = "%CHAT_MODEL_DEPLOYMENT_NAME%", EmbeddingsModel = "%EMBEDDING_MODEL_DEPLOYMENT_NAME%")] SemanticSearchContext result)
{
return new ContentResult { Content = result.Response, ContentType = "text/plain" };
}
}
Loading