mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.Net: FileSearch Tool Sample + API Proposal Updates for MEAI.Abstractions/Azure.AI.Agents (#210)
* Wip, bringing persistent chat client back * Bring back code interpreter resource logic * Add file search samples and proposal for new OpenAIAssistantChatClient and AgentPersistantChatCLient * Update dotnet/samples/GettingStarted/External/MEAI.Abstractions/NewHostedFileSearchTool.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_UsingFileSearchTools.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/samples/GettingStarted/External/Azure.AI.Agents.Persistent/NewPersistentAgentsChatClient.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update MEAI abstractions to reflect latest discussions, updated underlying chatclients * Remove unneeded comments * Address PR feedback * Address PR feedback --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
dff700e469
commit
02814a4fc0
+41
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Shared.Diagnostics;
|
||||
|
||||
namespace Microsoft.Extensions.AI;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a file that is hosted by the AI service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Unlike <see cref="DataContent"/> which contains the data for a file or blob, this class represents a file that is hosted
|
||||
/// by the AI service and referenced by an identifier. Such identifiers are specific to the provider.
|
||||
/// </remarks>
|
||||
[DebuggerDisplay("FileId = {FileId}")]
|
||||
public sealed class HostedFileContent : AIContent
|
||||
{
|
||||
private string _fileId;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HostedFileContent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="fileId">The ID of the hosted file.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="fileId"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="fileId"/> is empty or composed entirely of whitespace.</exception>
|
||||
public HostedFileContent(string fileId)
|
||||
{
|
||||
_fileId = Throw.IfNullOrWhitespace(fileId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the hosted file.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="value"/> is empty or composed entirely of whitespace.</exception>
|
||||
public string FileId
|
||||
{
|
||||
get => _fileId;
|
||||
set => _fileId = Throw.IfNullOrWhitespace(value);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Shared.Diagnostics;
|
||||
|
||||
namespace Microsoft.Extensions.AI;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a vector store that is hosted by the AI service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Unlike <see cref="DataContent"/> which contains the data for a file or blob, this class represents a vector store that is hosted
|
||||
/// by the AI service and referenced by an identifier. Such identifiers are specific to the provider.
|
||||
/// </remarks>
|
||||
[DebuggerDisplay("VectorStoreId = {VectorStoreId}")]
|
||||
public sealed class HostedVectorStoreContent : AIContent
|
||||
{
|
||||
private string? _vectorStoreId;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HostedVectorStoreContent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="vectorStoreId">The ID of the hosted vector store.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="vectorStoreId"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="vectorStoreId"/> is empty or composed entirely of whitespace.</exception>
|
||||
public HostedVectorStoreContent(string vectorStoreId)
|
||||
{
|
||||
_vectorStoreId = Throw.IfNullOrWhitespace(vectorStoreId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the hosted vector store.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentException"><paramref name="value"/> is empty or composed entirely of whitespace.</exception>
|
||||
public string VectorStoreId
|
||||
{
|
||||
get => _vectorStoreId ?? string.Empty;
|
||||
set => _vectorStoreId = Throw.IfNullOrWhitespace(value);
|
||||
}
|
||||
}
|
||||
+8
-25
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.Extensions.AI;
|
||||
|
||||
namespace OpenAI.Assistants;
|
||||
namespace Microsoft.Extensions.AI;
|
||||
|
||||
/// <summary>
|
||||
/// Proposal for abstraction updates based on the common code interpreter tool properties.
|
||||
@@ -10,26 +8,11 @@ namespace OpenAI.Assistants;
|
||||
/// </summary>
|
||||
public class NewHostedCodeInterpreterTool : HostedCodeInterpreterTool
|
||||
{
|
||||
// Usage of an internal dictionary is temporary and only used here because the MEAI.Abstractions does not have this specialization yet and the
|
||||
// ChatClients must rely on the AdditionalProperties to check and set correctly the Code Interpreter Resource avoiding a customized RawRepresentationFactory implementation.
|
||||
private readonly Dictionary<string, object?> _additionalProperties = [];
|
||||
|
||||
/// <summary>Gets or sets the list of file IDs that the code interpreter tool can access.</summary>
|
||||
public IList<string> FileIds
|
||||
{
|
||||
get
|
||||
{
|
||||
// Only create the property in the dictionary when it is actually used
|
||||
if (!this._additionalProperties.TryGetValue("fileIds", out var value) || value is null)
|
||||
{
|
||||
value = new List<string>();
|
||||
this._additionalProperties["fileIds"] = value;
|
||||
}
|
||||
|
||||
return (IList<string>)value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IReadOnlyDictionary<string, object?> AdditionalProperties => this._additionalProperties;
|
||||
/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the code interpreter tool.</summary>
|
||||
/// <remarks>
|
||||
/// Services support different varied kinds of inputs. Most support the IDs of files that are hosted by the service,
|
||||
/// represented via <see cref="HostedFileContent"/>. Some also support binary data, represented via <see cref="DataContent"/>.
|
||||
/// Unsupported inputs will be ignored by the <see cref="IChatClient"/> to which the tool is passed.
|
||||
/// </remarks>
|
||||
public IList<AIContent>? Inputs { get; set; }
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
namespace Microsoft.Extensions.AI;
|
||||
|
||||
/// <summary>
|
||||
/// Proposal for abstraction updates based on the common file search tool properties.
|
||||
/// This provides a standardized interface for file search functionality across providers.
|
||||
/// </summary>
|
||||
public class NewHostedFileSearchTool : AITool
|
||||
{
|
||||
/// <summary>Gets or sets a collection of <see cref="AIContent"/> to be used as input to the code interpreter tool.</summary>
|
||||
/// <remarks>
|
||||
/// Services support different varied kinds of inputs. Most support the IDs of vector stores that are hosted by the service,
|
||||
/// represented via <see cref="HostedVectorStoreContent"/>. Some also support binary data, represented via <see cref="DataContent"/>.
|
||||
/// Unsupported inputs will be ignored by the <see cref="IChatClient"/> to which the tool is passed.
|
||||
/// </remarks>
|
||||
public IList<AIContent>? Inputs { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user