Skip to content

Commit

Permalink
rm method
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 18, 2024
1 parent b91c89c commit edad4f4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 90 deletions.
69 changes: 19 additions & 50 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3281,61 +3281,30 @@ export class Client {
}

/**
* List runs from an annotation queue with the specified queue ID.
* Get a run from an annotation queue at the specified index.
* @param queueId - The ID of the annotation queue
* @param limit - The maximum number of runs to return
* @returns An async iterable of RunWithAnnotationQueueInfo objects
* @param index - The index of the run to retrieve
* @returns A Promise that resolves to a RunWithAnnotationQueueInfo object
* @throws {Error} If the run is not found at the given index or for other API-related errors
*/
public async *listRunsFromAnnotationQueue(
public async getRunFromAnnotationQueue(
queueId: string,
limit?: number
): AsyncIterable<RunWithAnnotationQueueInfo> {
index: number
): Promise<RunWithAnnotationQueueInfo> {
const baseUrl = `/annotation-queues/${assertUuid(queueId, "queueId")}/run`;
let index = 0;
let i = 0;
while (true) {
try {
console.log("GETTT", `${this.apiUrl}${baseUrl}/${index}`);
const response = await this.caller.call(
_getFetchImplementation(),
`${this.apiUrl}${baseUrl}/${index}`,
{
method: "GET",
headers: this.headers,
signal: AbortSignal.timeout(this.timeout_ms),
...this.fetchOptions,
}
);

if (!response.ok) {
if (response.status === 404) {
break;
}
await raiseForStatus(response, "list runs from annotation queue");
}

const run: RunWithAnnotationQueueInfo = await response.json();
yield run;

i++;
if (limit !== undefined && i >= limit) {
return;
}

index++;
} catch (error) {
if (
error &&
typeof error === "object" &&
"message" in error &&
typeof error.message === "string" &&
error.message.includes("404")
) {
break;
}
throw error;
const response = await this.caller.call(
_getFetchImplementation(),
`${this.apiUrl}${baseUrl}/${index}`,
{
method: "GET",
headers: this.headers,
signal: AbortSignal.timeout(this.timeout_ms),
...this.fetchOptions,
}
}
);

await raiseForStatus(response, "get run from annotation queue");
return await response.json();
}

protected async _currentTenantIsOwner(owner: string): Promise<boolean> {
Expand Down
17 changes: 10 additions & 7 deletions js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,20 +1213,23 @@ test("annotationqueue crud", async () => {
// 3. Add the run to the annotation queue
await client.addRunsToAnnotationQueue(fetchedQueue.id, [runId]);

// 4. Check that the run is in the annotation queue
const queuedRuns = await toArray(
client.listRunsFromAnnotationQueue(queue.id)
);
expect(queuedRuns.some((r) => r.id === runId)).toBe(true);

// 5. Update the annotation queue description and check that it is updated
// 4. Update the annotation queue description and check that it is updated
const newDescription = "Updated description";
await client.updateAnnotationQueue(queue.id, {
name: queueName,
description: newDescription,
});
const updatedQueue = await client.readAnnotationQueue(queue.id);
expect(updatedQueue.description).toBe(newDescription);

// Get the run from the annotation queue
const run = await client.getRunFromAnnotationQueue(queueId, 0);
expect(run).toBeDefined();
expect(run.id).toBe(runId);
expect(run.name).toBe("Test Run");
expect(run.run_type).toBe("chain");
expect(run.inputs).toEqual({ foo: "bar" });
expect(run.outputs).toEqual({ baz: "qux" });
} finally {
// 6. Delete the annotation queue
await client.deleteAnnotationQueue(queueId);
Expand Down
51 changes: 18 additions & 33 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4681,45 +4681,30 @@ def add_runs_to_annotation_queue(
)
ls_utils.raise_for_status_with_text(response)

def list_runs_from_annotation_queue(
self, queue_id: ID_TYPE, *, limit: Optional[int] = None
) -> Iterator[ls_schemas.RunWithAnnotationQueueInfo]:
"""List runs from an annotation queue with the specified queue ID.
def get_run_from_annotation_queue(
self, queue_id: ID_TYPE, *, index: int
) -> ls_schemas.RunWithAnnotationQueueInfo:
"""Get a run from an annotation queue at the specified index.
Args:
queue_id (ID_TYPE): The ID of the annotation queue.
limit (Optional[int]): The maximum number of runs to return.
index (int): The index of the run to retrieve.
Yields:
ls_schemas.RunWithAnnotationQueueInfo: An iterator of runs from the
annotation queue.
Returns:
ls_schemas.RunWithAnnotationQueueInfo: The run at the specified index.
Raises:
ls_utils.LangSmithNotFoundError: If the run is not found at the given index.
ls_utils.LangSmithError: For other API-related errors.
"""
base_url = f"/annotation-queues/{_as_uuid(queue_id, 'queue_id')}/run"
index = 0
i = 0
while True:
try:
response = self.request_with_retries(
"GET",
f"{base_url}/{index}",
headers=self._headers,
)
if response.status_code == 404:
break
ls_utils.raise_for_status_with_text(response)

run = ls_schemas.RunWithAnnotationQueueInfo(**response.json())
yield run

i += 1
if limit is not None and i >= limit:
return

index += 1
except ls_utils.LangSmithNotFoundError:
break
except ls_utils.LangSmithError as e:
raise e
response = self.request_with_retries(
"GET",
f"{base_url}/{index}",
headers=self._headers,
)
ls_utils.raise_for_status_with_text(response)
return ls_schemas.RunWithAnnotationQueueInfo(**response.json())

def create_comparative_experiment(
self,
Expand Down

0 comments on commit edad4f4

Please sign in to comment.