-
I am pretty new to SK and LLMs in general. The use case I want to try is craft a prompt to search through a large JSON data that comes from API response. Initially I thought I can send it in the prompt itself as context, but then learnt that there are going to be too many tokens in that case and also it might exceed the token limit. So I am now exploring one of these two options:
What is the better approach to follow, or is there any other different approach? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
Hi @rajyraman ! |
Beta Was this translation helpful? Give feedback.
-
I'm using Azure AI Search with SK. It's working perfectly. The only issue is that Azure AI Search/SK only supports one index. |
Beta Was this translation helpful? Give feedback.
-
@rajyraman - Our implementation of The current version of SK is based on V1 SDK's and we have a major update just around the corner where we've migrated to the V2 SDK's. This update impacts the memory connectors and the assistant-agents. As part of this, we've made In the meantime, I've re-written this sample to use the V1 // Copyright (c) Microsoft. All rights reserved.
using System.Text;
using Azure;
using Azure.AI.OpenAI.Assistants;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.OpenAI;
using Microsoft.SemanticKernel.ChatCompletion;
using Resources;
namespace Agents;
/// <summary>
/// Demonstrate using code-interpreter to manipulate and generate csv files with <see cref="OpenAIAssistantAgent"/> .
/// </summary>
public class OpenAIAssistant_FileManipulation(ITestOutputHelper output) : BaseTest(output)
{
/// <summary>
/// Target OpenAI services.
/// </summary>
protected override bool ForceOpenAI => false;
[Fact]
public async Task AnalyzeCSVFileUsingOpenAIAssistantAgentAsync()
{
AssistantsClient client = new(new Uri(TestConfiguration.AzureOpenAI.Endpoint), new AzureKeyCredential(TestConfiguration.AzureOpenAI.ApiKey));
await using Stream stream = EmbeddedResource.ReadStream("sales.csv")!;
OpenAIFile fileInfo = await client.UploadFileAsync(stream, OpenAIFilePurpose.Assistants);
Console.WriteLine(this.ApiKey);
// Define the agent
OpenAIAssistantAgent agent =
await OpenAIAssistantAgent.CreateAsync(
kernel: new(),
config: new(this.ApiKey, this.Endpoint),
new()
{
EnableCodeInterpreter = true, // Enable code-interpreter
ModelId = this.Model,
FileIds = [fileInfo.Id] // Associate uploaded file
});
// Create a chat for agent interaction.
AgentGroupChat chat = new();
// Respond to user input
try
{
await InvokeAgentAsync("Which segment had the most sales?");
await InvokeAgentAsync("List the top 5 countries that generated the most profit.");
await InvokeAgentAsync("Create a tab delimited file report of profit by each country per month.");
}
finally
{
await agent.DeleteAsync();
await client.DeleteFileAsync(fileInfo.Id);
}
// Local function to invoke agent and display the conversation messages.
async Task InvokeAgentAsync(string input)
{
chat.AddChatMessage(new ChatMessageContent(AuthorRole.User, input));
Console.WriteLine($"# {AuthorRole.User}: '{input}'");
await foreach (ChatMessageContent content in chat.InvokeAsync(agent))
{
Console.WriteLine($"# {content.Role} - {content.AuthorName ?? "*"}: '{content.Content}'");
foreach (AnnotationContent annotation in content.Items.OfType<AnnotationContent>())
{
Console.WriteLine($"\n* '{annotation.Quote}' => {annotation.FileId}");
BinaryData fileContent = await client.GetFileContentAsync(annotation.FileId!);
Console.WriteLine(Encoding.Default.GetString(fileContent.ToArray()));
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
@rajyraman - Our implementation of
OpenAIFileService
does appear to struggle with Azure endpoint for certain interactions; although, it was designed to support targeting both OpenAI and Azure Open AI services.The current version of SK is based on V1 SDK's and we have a major update just around the corner where we've migrated to the V2 SDK's. This update impacts the memory connectors and the assistant-agents. As part of this, we've made
obsolete
theOpenAIFileService
in favor of direclty using theFileClient
from the V2 SDK. This sample has been updated to include this change in a feature-branch and is expected to be merged to main in the very near future!!!In the meantime, I've re-writt…