Skip to content

Commit

Permalink
Refresh agent samples and utilities for improved functionality (#32307)
Browse files Browse the repository at this point in the history
Enhance agent samples and utilities to improve their functionality and
usability. Updates include better error handling and streamlined vector
store creation.


### Packages impacted by this PR


### Issues associated with this PR
Couple of the samples was not working

### Describe the problem that is addressed by this PR
Handle proper server error message.
Handle camel casing for tool names.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [x] Added a changelog (if necessary)
  • Loading branch information
ganeshyb authored Dec 20, 2024
1 parent bf36b8f commit b05f996
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 81 deletions.
9 changes: 3 additions & 6 deletions sdk/ai/ai-projects/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Release History

## 1.0.0-beta.2 (Unreleased)

### Features Added

### Breaking Changes
## 1.0.0-beta.2 (2024-12-19)

### Bugs Fixed

### Other Changes
- Address issue creating tool definition from connection.
- Improve Error handling api call failure.

## 1.0.0-beta.1 (2024-12-19)

Expand Down
8 changes: 5 additions & 3 deletions sdk/ai/ai-projects/samples-dev/agents/agentsWithToolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export async function main(): Promise<void> {
console.log(`Uploaded file, file ID: ${fileSearchFile.id}`);

// Create vector store for file search tool
const vectorStore = await client.agents.createVectorStoreAndPoll({
fileIds: [fileSearchFile.id],
});
const vectorStore = await client.agents
.createVectorStoreAndPoll({
fileIds: [fileSearchFile.id],
})
.pollUntilDone();

// Create tool set
const toolSet = new ToolSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* This sample demonstrates how to use agent operations with code interpreter from the Azure Agents service.
*
* @summary demonstrates how to use agent operations with code interpreter.
* @azsdk-weight 100
*
*/

Expand Down
60 changes: 28 additions & 32 deletions sdk/ai/ai-projects/samples/v1-beta/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ urlFragment: ai-projects-javascript-beta

These sample programs show how to use the JavaScript client libraries for Azure AI Projects in some common scenarios.

<!--
| **File Name** | **Description** |
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [agents\codeInterpreterWithStreaming.js][agents_codeinterpreterwithstreaming] | demonstrates how to use agent operations with code interpreter. |
| [agents\agentCreateWithTracingConsole.js][agents_agentcreatewithtracingconsole] | Create Agent and instrument using open telemetry. |
| [agents\agentsAzureAiSearch.js][agents_agentsazureaisearch] | demonstrates how to use agent operations with the Azure AI Search tool. |
| [agents\agentsBasics.js][agents_agentsbasics] | demonstrates how to use basic agent operations. |
Expand All @@ -24,7 +24,6 @@ These sample programs show how to use the JavaScript client libraries for Azure
| [agents\batchVectorStoreWithFiles.js][agents_batchvectorstorewithfiles] | demonstrates how to create the batch vector store with the list of files. |
| [agents\batchVectorStoreWithFilesAndPolling.js][agents_batchvectorstorewithfilesandpolling] | demonstrates how to create the batch vector store with the list of files using polling operation. |
| [agents\codeInterpreter.js][agents_codeinterpreter] | demonstrates how to use agent operations with code interpreter. |
| [agents\codeInterpreterWithStreaming.js][agents_codeinterpreterwithstreaming] | demonstrates how to use agent operations with code interpreter. |
| [agents\fileSearch.js][agents_filesearch] | This sample demonstrates how to use agent operations with file searching. |
| [agents\files.js][agents_files] | demonstrates how to use basic files agent operations. |
| [agents\filesWithLocalUpload.js][agents_fileswithlocalupload] | demonstrates how to use basic files agent operations with local file upload. |
Expand All @@ -38,7 +37,6 @@ These sample programs show how to use the JavaScript client libraries for Azure
| [agents\vectorStores.js][agents_vectorstores] | demonstrates how to create the vector store. |
| [agents\vectorStoresWithPolling.js][agents_vectorstoreswithpolling] | demonstrates how to create the vector store using polling operation. |
| [connections\connectionsBasics.js][connections_connectionsbasics] | Given an AIProjectClient, this sample demonstrates how to enumerate the properties of all connections, get the properties of a default connection, and get the properties of a connection by its name. |
-->

## Prerequisites

Expand All @@ -65,45 +63,43 @@ npm install
3. Run whichever samples you like (note that some samples may require additional setup, see the table above):

```bash
node agents\agentCreateWithTracingConsole.js
node agents\codeInterpreterWithStreaming.js
```

Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):

```bash
npx dev-tool run vendored cross-env AZURE_AI_PROJECTS_CONNECTION_STRING="<azure ai projects connection string>" APPLICATIONINSIGHTS_CONNECTION_STRING="<applicationinsights connection string>" node agents\agentCreateWithTracingConsole.js
npx dev-tool run vendored cross-env AZURE_AI_PROJECTS_CONNECTION_STRING="<azure ai projects connection string>" node agents\codeInterpreterWithStreaming.js
```

## Next Steps

Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.

<!--
[agents_agentcreatewithtracingconsole]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentCreateWithTracingConsole.js
[agents_agentsazureaisearch]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentsAzureAiSearch.js
[agents_agentsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentsBasics.js
[agents_agentsbinggrounding]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentsBingGrounding.js
[agents_agentsbinggroundingwithstreaming]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentsBingGroundingWithStreaming.js
[agents_agentswithfunctiontool]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentsWithFunctionTool.js
[agents_agentswithtoolset]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\agentsWithToolset.js
[agents_batchvectorstorewithfiles]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\batchVectorStoreWithFiles.js
[agents_batchvectorstorewithfilesandpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\batchVectorStoreWithFilesAndPolling.js
[agents_codeinterpreter]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\codeInterpreter.js
[agents_codeinterpreterwithstreaming]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\codeInterpreterWithStreaming.js
[agents_filesearch]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\fileSearch.js
[agents_files]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\files.js
[agents_fileswithlocalupload]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\filesWithLocalUpload.js
[agents_fileswithpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\filesWithPolling.js
[agents_messages]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\messages.js
[agents_runsteps]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\runSteps.js
[agents_streaming]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\streaming.js
[agents_threads]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\threads.js
[agents_vectorstorewithfiles]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\vectorStoreWithFiles.js
[agents_vectorstorewithfilesandpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\vectorStoreWithFilesAndPolling.js
[agents_vectorstores]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\vectorStores.js
[agents_vectorstoreswithpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents\vectorStoresWithPolling.js
[connections_connectionsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/connections\connectionsBasics.js
[apiref]: https://learn.microsoft.com/javascript/api/@azure/ai-projects
[agents_codeinterpreterwithstreaming]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/codeInterpreterWithStreaming.js
[agents_agentcreatewithtracingconsole]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentCreateWithTracingConsole.js
[agents_agentsazureaisearch]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsAzureAiSearch.js
[agents_agentsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBasics.js
[agents_agentsbinggrounding]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBingGrounding.js
[agents_agentsbinggroundingwithstreaming]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsBingGroundingWithStreaming.js
[agents_agentswithfunctiontool]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsWithFunctionTool.js
[agents_agentswithtoolset]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/agentsWithToolset.js
[agents_batchvectorstorewithfiles]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/batchVectorStoreWithFiles.js
[agents_batchvectorstorewithfilesandpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/batchVectorStoreWithFilesAndPolling.js
[agents_codeinterpreter]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/codeInterpreter.js
[agents_filesearch]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/fileSearch.js
[agents_files]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/files.js
[agents_fileswithlocalupload]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/filesWithLocalUpload.js
[agents_fileswithpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/filesWithPolling.js
[agents_messages]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/messages.js
[agents_runsteps]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/runSteps.js
[agents_streaming]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/streaming.js
[agents_threads]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/threads.js
[agents_vectorstorewithfiles]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/vectorStoreWithFiles.js
[agents_vectorstorewithfilesandpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/vectorStoreWithFilesAndPolling.js
[agents_vectorstores]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/vectorStores.js
[agents_vectorstoreswithpolling]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/agents/vectorStoresWithPolling.js
[connections_connectionsbasics]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-projects/samples/v1-beta/javascript/connections/connectionsBasics.js
<!-- [apiref]: https://learn.microsoft.com/javascript/api/@azure/ai-projects -->
[freesub]: https://azure.microsoft.com/free/
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-projects/README.md
-->
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ async function main() {
console.log(`Uploaded file, file ID: ${fileSearchFile.id}`);

// Create vector store for file search tool
const vectorStore = await client.agents.createVectorStoreAndPoll({
fileIds: [fileSearchFile.id],
});
const vectorStore = await client.agents
.createVectorStoreAndPoll({
fileIds: [fileSearchFile.id],
})
.pollUntilDone();

// Create tool set
const toolSet = new ToolSet();
Expand Down
Loading

0 comments on commit b05f996

Please sign in to comment.