Set up a tool function.

Signed-off-by: Alexander Trauzzi <acj@trauzzi.me>
This commit is contained in:
Alexander Trauzzi 2025-09-03 09:14:52 -05:00
parent 56f19a8081
commit 16a790fc1a
4 changed files with 33 additions and 7 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -17,6 +17,7 @@ limitations under the License.
using Dapr.AI.Conversation;
using Dapr.AI.Conversation.ConversationRoles;
using Dapr.AI.Conversation.Extensions;
using Dapr.AI.Conversation.Tools;
const string conversationComponentName = "echo";
const string prompt = "What is dapr?";
@ -27,7 +28,32 @@ var app = builder.Build();
var conversationClient = app.Services.GetRequiredService<DaprConversationClient>();
var conversationOptions = new ConversationOptions(conversationComponentName);
var conversationOptions = new ConversationOptions(conversationComponentName)
{
Tools = [
new ToolFunction("demo")
{
Parameters = new Dictionary<string, object?> {
{ "type", "object" },
{ "properties", new Dictionary<string, object?>
{
{ "location", new Dictionary<string, object?>
{
{ "type", "string" },
{ "description", "The city and state, e.g. San Francisco, CA" },
} },
{ "unit", new Dictionary<string, object?>
{
{ "type", "string" },
{ "enum", new[] { "celsius", "fahrenheit" } },
{ "description", "The temperature unit to use" },
} },
} },
{ "required", "location" },
},
},
],
};
var inputs = new ConversationInput(new List<IConversationMessage>
{
new UserMessage {

View File

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapr.AI" Version="1.16.0-rc16" />
<PackageReference Include="Dapr.AI" Version="1.16.0-rc18" />
</ItemGroup>
</Project>