Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agents threads wrappers, tests, and sample #31700

Merged
merged 8 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions sdk/ai/ai-projects/src/agents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import { Client } from "@azure-rest/core-client";
import { AgentDeletionStatusOutput, AgentOutput, AgentThreadOutput, FileDeletionStatusOutput, FileListResponseOutput, OpenAIFileOutput, OpenAIPageableListOfAgentOutput, OpenAIPageableListOfThreadRunOutput, ThreadDeletionStatusOutput, ThreadMessageOutput, ThreadRunOutput } from "../generated/src/outputModels.js";
import { CancelRunParameters, CreateMessageParameters, CreateRunParameters, CreateThreadAndRunParameters, CreateThreadParameters, DeleteFileParameters, DeleteThreadParameters, GetFileContentParameters, GetFileParameters, GetRunParameters, GetThreadParameters, ListAgentsQueryParamProperties, ListFilesParameters, ListMessagesParameters, ListRunsParameters, SubmitToolOutputsToRunParameters, UpdateMessageParameters, UpdateRunParameters, UpdateThreadParameters, UploadFileParameters } from "../generated/src/parameters.js";
import { CancelRunParameters, CreateMessageParameters, CreateRunParameters, CreateThreadAndRunParameters, DeleteFileParameters, DeleteThreadParameters, GetFileContentParameters, GetFileParameters, GetRunParameters, GetThreadParameters, ListAgentsQueryParamProperties, ListFilesParameters, ListMessagesParameters, ListRunsParameters, SubmitToolOutputsToRunParameters, UpdateMessageParameters, UpdateRunParameters, UploadFileParameters } from "../generated/src/parameters.js";
import { createAgent, deleteAgent, getAgent, listAgents, updateAgent } from "./assistants.js";
import { deleteFile, getFile, getFileContent, listFiles, uploadFile } from "./files.js";
import { createThread, deleteThread, getThread, updateThread } from "./threads.js";
import { cancelRun, createRun, createThreadAndRun, getRun, listRuns, submitToolOutputsToRun, updateRun } from "./runs.js";
import { createMessage, listMessages, updateMessage } from "./messages.js";
import { CreateAgentOptions, UpdateAgentOptions } from "../generated/src/models.js";
import { AgentThreadCreationOptions, CreateAgentOptions, UpdateAgentOptions, UpdateAgentThreadOptions } from "../generated/src/models.js";

export interface AgentsOperations {
/** Creates a new agent. */
Expand All @@ -37,7 +37,7 @@ export interface AgentsOperations {

/** Creates a new thread. Threads contain messages and can be run by agents. */
createThread: (
options: CreateThreadParameters,
options?: AgentThreadCreationOptions,
) => Promise<AgentThreadOutput>;
/** Gets information about an existing thread. */
getThread: (
Expand All @@ -47,7 +47,7 @@ export interface AgentsOperations {
/** Modifies an existing thread. */
updateThread: (
threadId: string,
options: UpdateThreadParameters,
options?: UpdateAgentThreadOptions,
) => Promise<AgentThreadOutput>;
/** Deletes an existing thread. */
deleteThread: (
Expand Down Expand Up @@ -152,14 +152,14 @@ function getAgents(context: Client) : AgentsOperations {
assistantId: string
) => deleteAgent(context, assistantId),

createThread: (options: CreateThreadParameters) =>
createThread(context, options),
getThread: (threadId: string, options?: GetThreadParameters) =>
getThread(context, threadId, options),
updateThread: (threadId: string, options: UpdateThreadParameters) =>
updateThread(context, threadId, options),
deleteThread: (threadId: string, options?: DeleteThreadParameters) =>
deleteThread(context, threadId, options),
createThread: (options?: AgentThreadCreationOptions) =>
createThread(context, {body: options as Record<string, unknown>}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curios why this is needed ?

getThread: (threadId: string) =>
getThread(context, threadId),
updateThread: (threadId: string, options?: UpdateAgentThreadOptions) =>
updateThread(context, threadId, {body: options as Record<string, unknown>}),
deleteThread: (threadId: string) =>
deleteThread(context, threadId),

createRun: (threadId: string, options: CreateRunParameters) =>
createRun(context, threadId, options),
Expand Down
22 changes: 11 additions & 11 deletions sdk/ai/ai-projects/src/agents/threads.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Client, createRestError } from "@azure-rest/core-client";
import { CreateThreadParameters, DeleteThreadParameters, GetThreadParameters, UpdateThreadParameters } from "../generated/src/parameters.js";
import { AgentThreadOutput, ThreadDeletionStatusOutput } from "../generated/src/outputModels.js";

const expectedStatuses = ["200"];

/** Creates a new thread. Threads contain messages and can be run by agents. */
export async function createThread(
context: Client,
options: CreateThreadParameters,
options?: CreateThreadParameters,
): Promise<AgentThreadOutput> {
const result = await context.path("/threads").post(options);
if (!expectedStatuses.includes(result.status)) {
throw createRestError(result);
}
return result.body;
return result.body;
}

/** Gets information about an existing thread. */
export async function getThread(
context: Client,
Expand All @@ -31,24 +31,24 @@ export async function getThread(
if (!expectedStatuses.includes(result.status)) {
throw createRestError(result);
}
return result.body;
return result.body;
}

/** Modifies an existing thread. */
export async function updateThread(
context: Client,
threadId: string,
options: UpdateThreadParameters,
options?: UpdateThreadParameters,
): Promise<AgentThreadOutput> {
const result = await context
.path("/threads/{threadId}", threadId)
.post(options);
if (!expectedStatuses.includes(result.status)) {
throw createRestError(result);
}
return result.body;
return result.body;
}

/** Deletes an existing thread. */
export async function deleteThread(
context: Client,
Expand Down