This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ApiResponse<string>> ChatWithChatGPTAsync(string context, string myQuestion) | |
{ | |
var result = new ApiResponse<string>(); | |
try | |
{ | |
var url = _configuration.GetValue<string>("AzureOpenAiApi:Endpoint"); | |
var key = _configuration.GetValue<string>("AzureOpenAiApi:SubscriptionKey"); | |
var openAIClient = new AzureOpenAIClient(new Uri(url), new AzureKeyCredential(key)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LCI.Services.Abstract; | |
using LCI.Services.Core.DtoModels; | |
using LCI.Services.Core.Services; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ChatToolGenerator | |
{ | |
public static ChatTool CreateCrimeContextTool() | |
{ | |
var crimeContextTool = ChatTool.CreateFunctionTool( | |
functionName: "CrimeAtLocationForPostcode", | |
functionDescription: "Produce crime context for a given postcode", | |
functionParameters: BinaryData.FromString(""" | |
{ | |
"type": "object", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res = app.app_state.collection.add( | |
documents=[document], | |
embeddings=[app.app_state.get_text_embedding(document)], | |
metadatas=[metadata], | |
ids=[ids] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
documents = app.app_state.collection.get(include=["metadatas"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if metadata: | |
res = app.app_state.collection.query( | |
query_embeddings=query_embeddings, | |
n_results=results, | |
where={"Metadata": metadata}, | |
include=["documents", "metadatas", "distances", "embeddings"] | |
) | |
else: | |
res = app.app_state.collection.query( | |
query_embeddings=query_embeddings, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ChromaDbResult> QueryByTextAsync(string queryText) | |
{ | |
try | |
{ | |
var payload = new { parameters = new { query_text = queryText, n_results = 2 } }; | |
string jsonPayload = JsonConvert.SerializeObject(payload); | |
var requestContent = new StringContent(jsonPayload, System.Text.Encoding.UTF8, "application/json"); | |
var response = await _client.PostAsync("query", requestContent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = _configuration.GetValue<string>("AzureOpenAiApi:Endpoint"); | |
var key = _configuration.GetValue<string>("AzureOpenAiApi:SubscriptionKey"); | |
var openAIClient = new OpenAIClient(new Uri(url), new AzureKeyCredential(key)); | |
Response<ChatCompletions> responseWithoutStream = | |
await openAIClient.GetChatCompletionsAsync( | |
new ChatCompletionsOptions() | |
{ | |
Messages = | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://youropenaiinstance.openai.azure.com/ | |
//c# | |
// Note: The Azure OpenAI client library for .NET is in preview. | |
// Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5 | |
using Azure; | |
using Azure.AI.OpenAI; | |
OpenAIClient client = new OpenAIClient( | |
new Uri("https://youropenaiinstance.openai.azure.com/"), | |
new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Deployment | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: chromadb | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: chromadb |
NewerOlder