Skip to content

Commit

Permalink
[Samples] fix samples-dev code to have await for async function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymeng committed Jan 17, 2025
1 parent 687a105 commit 4057bf4
Show file tree
Hide file tree
Showing 6,940 changed files with 8,530 additions and 8,531 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function main(): Promise<void> {
console.log(`Run finished with status: ${run.status}`);

// Delete the assistant when done
client.agents.deleteAgent(agent.id);
await client.agents.deleteAgent(agent.id);
console.log(`Deleted agent, agent ID: ${agent.id}`);

// Fetch and log all messages
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/ai-projects/samples-dev/agents/agentsBasics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function main(): Promise<void> {

console.log(`Created agent, agent ID : ${agent.id}`);

client.agents.deleteAgent(agent.id);
await client.agents.deleteAgent(agent.id);

console.log(`Deleted agent, agent ID: ${agent.id}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function main(): Promise<void> {
console.log(`Run finished with status: ${run.status}`);

// Delete the assistant when done
client.agents.deleteAgent(agent.id);
await client.agents.deleteAgent(agent.id);
console.log(`Deleted agent, agent ID: ${agent.id}`);

// Fetch and log all messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function main(): Promise<void> {
}

// Delete the assistant when done
client.agents.deleteAgent(agent.id);
await client.agents.deleteAgent(agent.id);
console.log(`Deleted agent, agent ID: ${agent.id}`);

// Fetch and log all messages
Expand Down
30 changes: 15 additions & 15 deletions sdk/ai/ai-projects/samples-dev/agents/agentsWithFunctionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,22 @@ export async function main(): Promise<void> {

console.log(`Run status - ${run.status}, run ID: ${run.id}`);
const messages = await agents.listMessages(thread.id);
messages.data.forEach((threadMessage) => {
console.log(
`Thread Message Created at - ${threadMessage.createdAt} - Role - ${threadMessage.role}`,
);
threadMessage.content.forEach((content: MessageContentOutput) => {
if (isOutputOfType<MessageTextContentOutput>(content, "text")) {
const textContent = content as MessageTextContentOutput;
console.log(`Text Message Content - ${textContent.text.value}`);
} else if (isOutputOfType<MessageImageFileContentOutput>(content, "image_file")) {
const imageContent = content as MessageImageFileContentOutput;
console.log(`Image Message Content - ${imageContent.imageFile.fileId}`);
}
});
});
await messages.data.forEach((threadMessage) => {
console.log(
`Thread Message Created at - ${threadMessage.createdAt} - Role - ${threadMessage.role}`,
);
threadMessage.content.forEach((content: MessageContentOutput) => {
if (isOutputOfType<MessageTextContentOutput>(content, "text")) {
const textContent = content as MessageTextContentOutput;
console.log(`Text Message Content - ${textContent.text.value}`);
} else if (isOutputOfType<MessageImageFileContentOutput>(content, "image_file")) {
const imageContent = content as MessageImageFileContentOutput;
console.log(`Image Message Content - ${imageContent.imageFile.fileId}`);
}
});
});
// Delete agent
agents.deleteAgent(agent.id);
await agents.deleteAgent(agent.id);
console.log(`Deleted agent, agent ID: ${agent.id}`);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/ai-projects/samples-dev/agents/agentsWithToolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export async function main(): Promise<void> {

// Create tool set
const toolSet = new ToolSet();
toolSet.addFileSearchTool([vectorStore.id]);
toolSet.addCodeInterpreterTool([codeInterpreterFile.id]);
await toolSet.addFileSearchTool([vectorStore.id]);
await toolSet.addCodeInterpreterTool([codeInterpreterFile.id]);

// Create agent with tool set
const agent = await client.agents.createAgent("gpt-4o", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function main(): Promise<void> {
// Create and upload first file
const file1Content = "Hello, Vector Store!";
const readable1 = new Readable();
readable1.push(file1Content);
readable1.push(null); // end the stream
await readable1.push(file1Content);
await readable1.push(null); // end the stream
const file1 = await client.agents.uploadFile(readable1, "assistants", {
fileName: "vectorFile1.txt",
});
Expand All @@ -40,8 +40,8 @@ export async function main(): Promise<void> {
// Create and upload second file
const file2Content = "This is another file for the Vector Store!";
const readable2 = new Readable();
readable2.push(file2Content);
readable2.push(null); // end the stream
await readable2.push(file2Content);
await readable2.push(null); // end the stream
const file2 = await client.agents.uploadFile(readable2, "assistants", {
fileName: "vectorFile2.txt",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function main(): Promise<void> {
// Create and upload first file
const file1Content = "Hello, Vector Store!";
const readable1 = new Readable();
readable1.push(file1Content);
readable1.push(null); // end the stream
await readable1.push(file1Content);
await readable1.push(null); // end the stream
const file1 = await client.agents.uploadFile(readable1, "assistants", {
fileName: "vectorFile1.txt",
});
Expand All @@ -40,8 +40,8 @@ export async function main(): Promise<void> {
// Create and upload second file
const file2Content = "This is another file for the Vector Store!";
const readable2 = new Readable();
readable2.push(file2Content);
readable2.push(null); // end the stream
await readable2.push(file2Content);
await readable2.push(null); // end the stream
const file2 = await client.agents.uploadFile(readable2, "assistants", {
fileName: "vectorFile2.txt",
});
Expand Down
22 changes: 11 additions & 11 deletions sdk/ai/ai-projects/samples-dev/agents/codeInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ export async function main(): Promise<void> {

// Iterate through messages and print details for each annotation
console.log(`Message Details:`);
messages.data.forEach((m) => {
console.log(`File Paths:`);
console.log(`Type: ${m.content[0].type}`);
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
const textContent = m.content[0] as MessageTextContentOutput;
console.log(`Text: ${textContent.text.value}`);
}
console.log(`File ID: ${m.id}`);
console.log(`Start Index: ${messages.firstId}`);
console.log(`End Index: ${messages.lastId}`);
});
await messages.data.forEach((m) => {
console.log(`File Paths:`);
console.log(`Type: ${m.content[0].type}`);
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
const textContent = m.content[0] as MessageTextContentOutput;
console.log(`Text: ${textContent.text.value}`);
}
console.log(`File ID: ${m.id}`);
console.log(`Start Index: ${messages.firstId}`);
console.log(`End Index: ${messages.lastId}`);
});

// Delete the agent once done
await client.agents.deleteAgent(agent.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ export async function main(): Promise<void> {

// Iterate through messages and print details for each annotation
console.log(`Message Details:`);
messages.data.forEach((m) => {
console.log(`File Paths:`);
console.log(`Type: ${m.content[0].type}`);
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
const textContent = m.content[0] as MessageTextContentOutput;
console.log(`Text: ${textContent.text.value}`);
}
console.log(`File ID: ${m.id}`);
console.log(`Start Index: ${messages.firstId}`);
console.log(`End Index: ${messages.lastId}`);
});
await messages.data.forEach((m) => {
console.log(`File Paths:`);
console.log(`Type: ${m.content[0].type}`);
if (isOutputOfType<MessageTextContentOutput>(m.content[0], "text")) {
const textContent = m.content[0] as MessageTextContentOutput;
console.log(`Text: ${textContent.text.value}`);
}
console.log(`File ID: ${m.id}`);
console.log(`Start Index: ${messages.firstId}`);
console.log(`End Index: ${messages.lastId}`);
});

// Delete the agent once done
await client.agents.deleteAgent(agent.id);
Expand Down
28 changes: 14 additions & 14 deletions sdk/ai/ai-projects/samples-dev/agents/fileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ export async function main(): Promise<void> {

console.log(`Current Run status - ${run.status}, run ID: ${run.id}`);
const messages = await client.agents.listMessages(thread.id);
messages.data.forEach((threadMessage) => {
console.log(
`Thread Message Created at - ${threadMessage.createdAt} - Role - ${threadMessage.role}`,
);
threadMessage.content.forEach((content: MessageContentOutput) => {
if (isOutputOfType<MessageTextContentOutput>(content, "text")) {
const textContent = content as MessageTextContentOutput;
console.log(`Text Message Content - ${textContent.text.value}`);
} else if (isOutputOfType<MessageImageFileContentOutput>(content, "image_file")) {
const imageContent = content as MessageImageFileContentOutput;
console.log(`Image Message Content - ${imageContent.imageFile.fileId}`);
}
});
});
await messages.data.forEach((threadMessage) => {
console.log(
`Thread Message Created at - ${threadMessage.createdAt} - Role - ${threadMessage.role}`,
);
threadMessage.content.forEach((content: MessageContentOutput) => {
if (isOutputOfType<MessageTextContentOutput>(content, "text")) {
const textContent = content as MessageTextContentOutput;
console.log(`Text Message Content - ${textContent.text.value}`);
} else if (isOutputOfType<MessageImageFileContentOutput>(content, "image_file")) {
const imageContent = content as MessageImageFileContentOutput;
console.log(`Image Message Content - ${imageContent.imageFile.fileId}`);
}
});
});

// Delete agent
await client.agents.deleteAgent(agent.id);
Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/ai-projects/samples-dev/agents/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export async function main(): Promise<void> {
// Create and upload file
const fileContent = "Hello, World!";
const readable = new Readable();
readable.push(fileContent);
readable.push(null); // end the stream
await readable.push(fileContent);
await readable.push(null); // end the stream
const file = await client.agents.uploadFile(readable, "assistants", { fileName: "myFile.txt" });
console.log(`Uploaded file, file ID : ${file.id}`);

Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/ai-projects/samples-dev/agents/filesWithPolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export async function main(): Promise<void> {
// Create file content
const fileContent = "Hello, World!";
const readable = new Readable();
readable.push(fileContent);
readable.push(null); // end the stream
await readable.push(fileContent);
await readable.push(null); // end the stream

// Upload file and poll
const poller = client.agents.uploadFileAndPoll(readable, "assistants", {
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/ai-projects/samples-dev/agents/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function main(): Promise<void> {

console.log(`Retrieved thread, thread ID : ${_thread.id}`);

client.agents.deleteThread(thread.id);
await client.agents.deleteThread(thread.id);

console.log(`Deleted thread, thread ID : ${_thread.id}`);
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/ai/ai-projects/samples-dev/agents/vectorStoreWithFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function main(): Promise<void> {
// Create and upload file
const fileContent = "Hello, Vector Store!";
const readable = new Readable();
readable.push(fileContent);
readable.push(null); // end the stream
await readable.push(fileContent);
await readable.push(null); // end the stream
const file = await client.agents.uploadFile(readable, "assistants", {
fileName: "vectorFile.txt",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function main(): Promise<void> {
// Create and upload file
const fileContent = "Hello, Vector Store!";
const readable = new Readable();
readable.push(fileContent);
readable.push(null); // end the stream
await readable.push(fileContent);
await readable.push(null); // end the stream
const file = await client.agents.uploadFile(readable, "assistants", {
fileName: "vectorFile.txt",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ async function fleetsCreateOrUpdateMinimumSet(): Promise<void> {
}

async function main(): Promise<void> {
fleetsCreateOrUpdate();
fleetsCreateOrUpdateMinimumSet();
await fleetsCreateOrUpdate();
await fleetsCreateOrUpdateMinimumSet();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function fleetsDelete(): Promise<void> {
}

async function main(): Promise<void> {
fleetsDelete();
await fleetsDelete();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function fleetsGet(): Promise<void> {
}

async function main(): Promise<void> {
fleetsGet();
await fleetsGet();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function fleetsListByResourceGroup(): Promise<void> {
}

async function main(): Promise<void> {
fleetsListByResourceGroup();
await fleetsListByResourceGroup();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function fleetsListBySubscription(): Promise<void> {
}

async function main(): Promise<void> {
fleetsListBySubscription();
await fleetsListBySubscription();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function fleetsListVirtualMachineScaleSets(): Promise<void> {
}

async function main(): Promise<void> {
fleetsListVirtualMachineScaleSets();
await fleetsListVirtualMachineScaleSets();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async function fleetsUpdate(): Promise<void> {
}

async function main(): Promise<void> {
fleetsUpdate();
await fleetsUpdate();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function operationsList(): Promise<void> {
}

async function main(): Promise<void> {
operationsList();
await operationsList();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function creationSupportedGet(): Promise<void> {
}

async function main(): Promise<void> {
creationSupportedGet();
await creationSupportedGet();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function creationSupportedList(): Promise<void> {
}

async function main(): Promise<void> {
creationSupportedList();
await creationSupportedList();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function marketplaceAgreementsCreateOrUpdate(): Promise<void> {
}

async function main(): Promise<void> {
marketplaceAgreementsCreateOrUpdate();
await marketplaceAgreementsCreateOrUpdate();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function marketplaceAgreementsList(): Promise<void> {
}

async function main(): Promise<void> {
marketplaceAgreementsList();
await marketplaceAgreementsList();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function monitorsAddMonitoredSubscriptions(): Promise<void> {
}

async function main(): Promise<void> {
monitorsAddMonitoredSubscriptions();
await monitorsAddMonitoredSubscriptions();
}

main().catch(console.error);
Loading

0 comments on commit 4057bf4

Please sign in to comment.