From edad4f4308202399c3f94f9be4bf31e42fbc046b Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:12:41 -0700 Subject: [PATCH] rm method --- js/src/client.ts | 69 +++++++++------------------------ js/src/tests/client.int.test.ts | 17 ++++---- python/langsmith/client.py | 51 +++++++++--------------- 3 files changed, 47 insertions(+), 90 deletions(-) diff --git a/js/src/client.ts b/js/src/client.ts index b21fd5597..b7ef0beef 100644 --- a/js/src/client.ts +++ b/js/src/client.ts @@ -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 { + index: number + ): Promise { 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 { diff --git a/js/src/tests/client.int.test.ts b/js/src/tests/client.int.test.ts index bb7af37c2..ddf160fa3 100644 --- a/js/src/tests/client.int.test.ts +++ b/js/src/tests/client.int.test.ts @@ -1213,13 +1213,7 @@ 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, @@ -1227,6 +1221,15 @@ test("annotationqueue crud", async () => { }); 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); diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 4cc2ef91a..123f869f6 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -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,