Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions samples/assistant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ This OpenAI extension internally uses the [function calling](https://platform.op

## Defining skills

You can define a skill by creating a function that uses the `AssistantSkillTrigger` binding. The following C# (out-of-process) example shows a skill that adds a todo item to a database:
You can define a skill by creating a function that uses the `AssistantSkillTrigger` binding. The following example shows a skill that adds a todo item to a database:

C# example:

```csharp
[Function(nameof(AddTodo))]
Expand All @@ -32,6 +34,27 @@ public Task AddTodo([AssistantSkillTrigger("Create a new todo task")] string tas
}
```

Nodejs example:

```ts
app.generic('AddTodo', {
trigger: trigger.generic({
type: 'assistantSkillTrigger',
functionDescription: 'Create a new todo task'
}),
handler: async (taskDescription: string, context: InvocationContext) => {
if (!taskDescription) {
throw new Error('Task description cannot be empty')
}

context.log(`Adding todo: ${taskDescription}`)

const todoId = crypto.randomUUID().substring(0, 6)
return todoManager.AddTodo(new TodoItem(todoId, taskDescription))
}
})
```

The `AssistantSkillTrigger` attribute requires a `FunctionDescription` string value, which is text describing what the function does.
This is critical for the AI assistant to be able to invoke the skill at the right time.
The name of the function parameter (e.g., `taskDescription`) is also an important hint to the AI assistant about what kind of information to provide to the skill.
Expand All @@ -46,6 +69,7 @@ The assistant will invoke a skill function whenever it decides to do so to satis
The sample is available in the following language stacks:

* [C# on the out-of-process worker](csharp-ooproc)
* [nodejs](nodejs)

Please refer to the [root README](../../README.md#requirements) for common prerequisites that apply to all samples.

Expand All @@ -71,7 +95,7 @@ Also note that the storage of chat history is done via table storage. You may co

1. Clone this repo and navigate to the sample folder.
1. Use a terminal window to navigate to the sample directory (e.g. `cd samples/assistant/csharp-ooproc`)
1. Run `func start --port 7168` to build and run the sample function app
1. Run `func start` to build and run the sample function app

If successful, you should see the following output from the `func` command:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
### Create a new assistant - instructions are hardcoded in the function
PUT http://localhost:7168/api/assistants/assistant123
PUT http://localhost:7071/api/assistants/assistant123


### Reminder #1
POST http://localhost:7168/api/assistants/assistant123
POST http://localhost:7071/api/assistants/assistant123
Content-Type: text/plain

Remind me to call my dad


### Reminder #2
POST http://localhost:7168/api/assistants/assistant123
POST http://localhost:7071/api/assistants/assistant123
Content-Type: text/plain

Oh, and to take out the trash


### Get the list of tasks
POST http://localhost:7168/api/assistants/assistant123
POST http://localhost:7071/api/assistants/assistant123
Content-Type: text/plain

What do I need to do today?


### Query the chat history
GET http://localhost:7168/api/assistants/assistant123?timestampUTC=2023-01-01T00:00:00Z
GET http://localhost:7071/api/assistants/assistant123?timestampUTC=2023-01-01T00:00:00Z
Accept: application/json
12 changes: 12 additions & 0 deletions samples/assistant/nodejs/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0",
"logging": {
"logLevel": {
"Microsoft.Azure.WebJobs.Extensions.OpenAI": "Information"
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
"version": "[4.*, 5.0.0)"
}
}
13 changes: 13 additions & 0 deletions samples/assistant/nodejs/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"FUNCTIONS_WORKER_RUNTIME": "node",
"CosmosDbConnectionString": "Local Cosmos DB emulator or Cosmos DB in Azure connection string",
"CosmosDatabaseName": "",
"CosmosContainerName": "",
"AZURE_OPENAI_ENDPOINT": "https://<resource-name>.openai.azure.com/",
"CHAT_MODEL_DEPLOYMENT_NAME": "gpt-3.5-turbo"
}
}
Loading