From 97f835f3b5a75631fa1ac5024998a2c49721463d Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Sat, 21 Oct 2023 01:07:10 +0900 Subject: [PATCH] Add eager flag; bump (#264) --- js/package.json | 2 +- js/src/client.ts | 5 ++++- python/langsmith/client.py | 25 ++++++++++++++++++++++++- python/pyproject.toml | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/js/package.json b/js/package.json index 1d8ec9691..c82f4a20d 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "langsmith", - "version": "0.0.43", + "version": "0.0.44", "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.", "files": [ "dist/", diff --git a/js/src/client.ts b/js/src/client.ts index a26991279..1fd564cee 100644 --- a/js/src/client.ts +++ b/js/src/client.ts @@ -1244,6 +1244,7 @@ export class Client { feedbackSourceType = "api", sourceRunId, feedbackId, + eager = false, }: { score?: ScoreType; value?: ValueType; @@ -1253,6 +1254,7 @@ export class Client { feedbackSourceType?: FeedbackSourceType; sourceRunId?: string; feedbackId?: string; + eager?: boolean; } ): Promise { const feedback_source: feedback_source = { @@ -1276,7 +1278,8 @@ export class Client { comment, feedback_source: feedback_source, }; - const response = await this.caller.call(fetch, `${this.apiUrl}/feedback`, { + const url = `${this.apiUrl}/feedback` + (eager ? "/eager" : ""); + const response = await this.caller.call(fetch, url, { method: "POST", headers: { ...this.headers, "Content-Type": "application/json" }, body: JSON.stringify(feedback), diff --git a/python/langsmith/client.py b/python/langsmith/client.py index de43028c1..957973bdd 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -1054,6 +1054,23 @@ def list_shared_examples( for dataset in response.json() ] + def list_shared_projects( + self, + *, + dataset_share_token: Optional[str] = None, + project_ids: Optional[List[ID_TYPE]] = None, + name: Optional[str] = None, + name_contains: Optional[str] = None, + ) -> Iterator[ls_schemas.TracerSession]: + params = {"id": project_ids, "name": name, "name_contains": name_contains} + yield from [ + ls_schemas.TracerSession(**dataset, _host_url=self._host_url) + for dataset in self._get_paginated_list( + f"/public/{dataset_share_token}/datasets/sessions", + params=params, + ) + ] + def create_project( self, project_name: str, @@ -1935,6 +1952,7 @@ def create_feedback( ] = ls_schemas.FeedbackSourceType.API, source_run_id: Optional[ID_TYPE] = None, feedback_id: Optional[ID_TYPE] = None, + eager: bool = False, ) -> ls_schemas.Feedback: """Create a feedback in the LangSmith API. @@ -1962,6 +1980,11 @@ def create_feedback( feedback_id : str or UUID or None, default=None The ID of the feedback to create. If not provided, a random UUID will be generated. + eager : bool, default=False + Whether to skip the write queue when creating the feedback. This means + that the feedback will be immediately available for reading, but may + cause the write to fail if the API is under heavy load, since the target + run_id may have not been created yet. """ if not isinstance(feedback_source_type, ls_schemas.FeedbackSourceType): feedback_source_type = ls_schemas.FeedbackSourceType(feedback_source_type) @@ -1992,7 +2015,7 @@ def create_feedback( ) self.request_with_retries( "POST", - self.api_url + "/feedback", + self.api_url + "/feedback" + ("/eager" if eager else ""), request_kwargs={ "data": json.dumps( feedback.dict(exclude_none=True), default=_serialize_json diff --git a/python/pyproject.toml b/python/pyproject.toml index 46e04df2f..a008a4cbc 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langsmith" -version = "0.0.47" +version = "0.0.48" description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform." authors = ["LangChain "] license = "MIT"