Created
November 26, 2024 10:51
-
-
Save pavlovmilen/78845eac4d428b3a3a18a172131a335a to your computer and use it in GitHub Desktop.
Extract data and pass to LLM
This file contains hidden or 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
// extract data as a string: | |
private string GetStringContentFromCrimeDataAIModel(List<CrimesAtLocationResponse> results, string postcode) | |
{ | |
if(results == null || !results.Any()) | |
{ | |
return "No data found"; | |
} | |
results = results.OrderBy(x => x.month).ToList(); | |
var stringBuilder = new StringBuilder(); | |
stringBuilder.AppendLine($"Crime data for {postcode} {results[0]?.location?.street?.name ?? ""},columns:CrimeCategory,CrimeOutcome,ForDate;\nData:"); | |
foreach (var result in results) | |
{ | |
foreach (var crimeData in results) | |
{ | |
stringBuilder.Append($",{crimeData.category},{crimeData.outcome_status?.category ?? "no outcome"},{crimeData.month}"); | |
} | |
} | |
return stringBuilder.ToString(); | |
} | |
// LLM prompt using the string from the previous method: | |
// Add the crimeContext as a new input message | |
var inputMessages = new List<ChatMessage>(); | |
inputMessages.Add(new SystemChatMessage(Consts.CrimeSummaryFunctionCalling)); //this is my system prompt | |
inputMessages.Add(new UserChatMessage($"Crime data for {arguments.postcode} is: {crimeContext}")); | |
// Now, make a final call with the updated input messages | |
ChatCompletion finalCompletion = await chatClient.CompleteChatAsync(inputMessages, chatCompletionOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment