-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathconnectionsBasics.js
More file actions
64 lines (53 loc) · 2.25 KB
/
Copy pathconnectionsBasics.js
File metadata and controls
64 lines (53 loc) · 2.25 KB
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
57
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how to use basic connections operations.
*
* @summary 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.
*/
const { AIProjectClient } = require("@azure/ai-projects");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
const endpoint = process.env["AZURE_AI_PROJECT_ENDPOINT_STRING"] || "<project endpoint string>";
async function main() {
const project = new AIProjectClient(endpoint, new DefaultAzureCredential());
// List the details of all the connections
const connections = [];
const connectionNames = [];
for await (const connection of project.connections.list()) {
connections.push(connection);
connectionNames.push(connection.name);
}
console.log(`Retrieved connections: ${connectionNames}`);
// Get the details of a connection, without credentials
const connectionName = connections[0].name;
const connection = await project.connections.get(connectionName);
console.log(
"connection.type: ",
connection.type,
"connection.name: ",
connection.name,
"connection.target: ",
connection.target,
);
const connectionWithCredentials = await project.connections.getWithCredentials(connectionName);
const credentials = connectionWithCredentials.credentials;
console.log("credentials.type: ", credentials.type, "credentials", credentials);
// List all connections of a specific type
const azureAIConnections = [];
for await (const azureOpenAIConnection of project.connections.list({
connectionType: "AzureOpenAI",
defaultConnection: true,
})) {
azureAIConnections.push(azureOpenAIConnection);
}
console.log(`Retrieved ${azureAIConnections.length} Azure OpenAI connections`);
// Get the details of a default connection
const defaultConnection = await project.connections.getDefault("AzureOpenAI", true);
console.log(`Retrieved default connection ${JSON.stringify(defaultConnection, null, 2)}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});
module.exports = { main };