-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathAssistantSkills.cs
56 lines (47 loc) · 1.92 KB
/
AssistantSkills.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.OpenAI.Assistants;
using Microsoft.Extensions.Logging;
namespace AssistantSample;
/// <summary>
/// Defines assistant skills that can be triggered by the assistant chat bot.
/// </summary>
public class AssistantSkills
{
readonly ITodoManager todoManager;
readonly ILogger<AssistantSkills> logger;
/// <summary>
/// Initializes a new instance of the <see cref="AssistantSkills"/> class.
/// </summary>
/// <remarks>
/// This constructor is called by the Azure Functions runtime's dependency injection container.
/// </remarks>
public AssistantSkills(ITodoManager todoManager, ILogger<AssistantSkills> logger)
{
this.todoManager = todoManager ?? throw new ArgumentNullException(nameof(todoManager));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
/// <summary>
/// Called by the assistant to create new todo tasks.
/// </summary>
[Function(nameof(AddTodo))]
public Task AddTodo([AssistantSkillTrigger("Create a new todo task")] string taskDescription)
{
if (string.IsNullOrEmpty(taskDescription))
{
throw new ArgumentException("Task description cannot be empty");
}
this.logger.LogInformation("Adding todo: {task}", taskDescription);
string todoId = Guid.NewGuid().ToString()[..6];
return this.todoManager.AddTodoAsync(new TodoItem(todoId, taskDescription));
}
/// <summary>
/// Called by the assistant to fetch the list of previously created todo tasks.
/// </summary>
[Function(nameof(GetTodos))]
public Task<IReadOnlyList<TodoItem>> GetTodos(
[AssistantSkillTrigger("Fetch the list of previously created todo tasks")] object inputIgnored)
{
this.logger.LogInformation("Fetching list of todos");
return this.todoManager.GetTodosAsync();
}
}