langchain.js
    Preparing search index...

    Implements

    Index

    Constructors

    Properties

    Methods

    _currentTenantIsOwner _ensureServerInfo _getLatestCommitHash _getPromptUrl _getServerInfo _getSettings _likeOrUnlikePrompt _logEvaluationFeedback _ownerConflictError _selectEvalResults addRunsToAnnotationQueue awaitPendingTraceBatches batchIngestRuns clonePublicDataset createAnnotationQueue createChatExample createCommit createComparativeExperiment createDataset createExample createExamples createFeedback createLLMExample createPresignedFeedbackToken createProject createPrompt createRun deleteAnnotationQueue deleteDataset deleteExample deleteFeedback deleteProject deletePrompt deleteRunFromAnnotationQueue diffDatasetVersions evaluateRun flush getDatasetUrl getHostUrl getProjectUrl getPrompt getRunFromAnnotationQueue getRunStats getRunUrl getSizeFromAnnotationQueue hasDataset hasProject indexDataset likePrompt listAnnotationQueues listCommits listDatasets listDatasetSplits listExamples listFeedback listGroupRuns listPresignedFeedbackTokens listProjects listPrompts listRuns listSharedExamples listSharedRuns logEvaluationFeedback multipartIngestRuns promptExists pullPromptCommit pushPrompt readAnnotationQueue readDataset readDatasetOpenaiFinetuning readDatasetSharedSchema readDatasetVersion readExample readFeedback readProject readRun readRunSharedLink readSharedDataset shareDataset shareRun similarExamples unlikePrompt unshareDataset unshareRun updateAnnotationQueue updateDataset updateDatasetSplits updateDatasetTag updateExample updateExamples updateExamplesMultipart updateFeedback updateProject updatePrompt updateRun uploadCsv uploadExamplesMultipart getDefaultClientConfig

    Constructors

    Properties

    debug: boolean = ...

    Methods

    • Parameters

      • owner: string

      Returns Promise<boolean>

    • Returns Promise<Record<string, any>>

    • Parameters

      • promptOwnerAndName: string

      Returns Promise<undefined | string>

    • Parameters

      • promptIdentifier: string

      Returns Promise<string>

    • Returns Promise<any>

    • Parameters

      • promptIdentifier: string
      • like: boolean

      Returns Promise<LikePromptResponse>

    • Parameters

      • action: string
      • owner: string

      Returns Promise<Error>

    • Add runs to an annotation queue with the specified queue ID.

      Parameters

      • queueId: string

        The ID of the annotation queue

      • runIds: string[]

        The IDs of the runs to be added to the annotation queue

      Returns Promise<void>

    • Awaits all pending trace batches. Useful for environments where you need to be sure that all tracing requests finish before execution ends, such as serverless environments.

      Returns Promise<void>

      A promise that resolves once all currently pending traces have sent.

      import { Client } from "langsmith";

      const client = new Client();

      try {
      // Tracing happens here
      ...
      } finally {
      await client.awaitPendingTraceBatches();
      }
    • Batch ingest/upsert multiple runs in the Langsmith system.

      Parameters

      • __namedParameters: { runCreates?: RunCreate[]; runUpdates?: RunUpdate[] }
      • Optionaloptions: { apiKey?: string; apiUrl?: string }

      Returns Promise<void>

    • Clone a public dataset to your own langsmith tenant. This operation is idempotent. If you already have a dataset with the given name, this function will do nothing.

      Parameters

      • tokenOrUrl: string

        The token of the public dataset to clone.

      • Optionaloptions: { datasetName?: string; sourceApiUrl?: string } = {}

        Additional options for cloning the dataset.

        • OptionaldatasetName?: string

          The name of the dataset to create in your tenant. Defaults to the name of the public dataset.

        • OptionalsourceApiUrl?: string

          The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.

      Returns Promise<void>

    • Create an annotation queue on the LangSmith API.

      Parameters

      • options: {
            description?: string;
            name: string;
            queueId?: string;
            rubricInstructions?: string;
        }

        The options for creating an annotation queue

        • Optionaldescription?: string

          The description of the annotation queue

        • name: string

          The name of the annotation queue

        • OptionalqueueId?: string

          The ID of the annotation queue

        • OptionalrubricInstructions?: string

      Returns Promise<AnnotationQueueWithDetails>

      The created AnnotationQueue object

    • Parameters

      • promptIdentifier: string
      • object: any
      • Optionaloptions: { parentCommitHash?: string }

      Returns Promise<string>

    • Parameters

      • __namedParameters: {
            createdAt?: Date;
            description?: string;
            experimentIds: string[];
            id?: string;
            metadata?: Record<string, unknown>;
            name: string;
            referenceDatasetId?: string;
        }

      Returns Promise<ComparativeExperiment>

    • Parameters

      • name: string
      • __namedParameters: {
            dataType?: DataType;
            description?: string;
            inputsSchema?: KVMap;
            metadata?: RecordStringAny;
            outputsSchema?: KVMap;
        } = {}

      Returns Promise<Dataset>

    • Parameters

      Returns Promise<Example[]>

    • Parameters

      • props: {
            attachments?: Attachments[];
            datasetId?: string;
            datasetName?: string;
            exampleIds?: string[];
            inputs?: KVMap[];
            metadata?: KVMap[];
            outputs?: KVMap[];
            sourceRunIds?: string[];
            splits?: (string | string[])[];
            useSourceRunAttachments?: string[][];
            useSourceRunIOs?: boolean[];
        }

      Returns Promise<Example[]>

      Use the uploads-only overload instead

    • Parameters

      • runId: null | string
      • key: string
      • __namedParameters: {
            comment?: string;
            comparativeExperimentId?: string;
            correction?: object;
            eager?: boolean;
            feedbackConfig?: FeedbackConfig;
            feedbackId?: string;
            feedbackSourceType?: FeedbackSourceType;
            projectId?: string;
            score?: ScoreType;
            sourceInfo?: object;
            sourceRunId?: string;
            value?: ValueType;
        }

      Returns Promise<Feedback>

    • Parameters

      Returns Promise<Example>

    • Creates a presigned feedback token and URL.

      The token can be used to authorize feedback metrics without needing an API key. This is useful for giving browser-based applications the ability to submit feedback without needing to expose an API key.

      Parameters

      • runId: string

        The ID of the run.

      • feedbackKey: string

        The feedback key.

      • options: { expiration?: string | TimeDelta; feedbackConfig?: FeedbackConfig } = {}

        Additional options for the token.

      Returns Promise<FeedbackIngestToken>

      A promise that resolves to a FeedbackIngestToken.

    • Parameters

      • promptIdentifier: string
      • Optionaloptions: { description?: string; isPublic?: boolean; readme?: string; tags?: string[] }

      Returns Promise<Prompt>

    • Parameters

      • run: CreateRunParams
      • Optionaloptions: { apiKey?: string; apiUrl?: string; workspaceId?: string }

      Returns Promise<void>

    • Delete an annotation queue with the specified queue ID.

      Parameters

      • queueId: string

        The ID of the annotation queue to delete

      Returns Promise<void>

    • Parameters

      • __namedParameters: { datasetId?: string; datasetName?: string }

      Returns Promise<void>

    • Parameters

      • exampleId: string

      Returns Promise<void>

    • Parameters

      • feedbackId: string

      Returns Promise<void>

    • Parameters

      • __namedParameters: { projectId?: string; projectName?: string }

      Returns Promise<void>

    • Parameters

      • promptIdentifier: string

      Returns Promise<void>

    • Delete a run from an an annotation queue.

      Parameters

      • queueId: string

        The ID of the annotation queue to delete the run from

      • queueRunId: string

        The ID of the run to delete from the annotation queue

      Returns Promise<void>

    • Parameters

      • __namedParameters: {
            datasetId?: string;
            datasetName?: string;
            fromVersion: string | Date;
            toVersion: string | Date;
        }

      Returns Promise<DatasetDiffInfo>

    • Parameters

      • run: string | Run
      • evaluator: RunEvaluator
      • __namedParameters: { loadChildRuns: boolean; referenceExample?: Example; sourceInfo?: KVMap } = ...

      Returns Promise<Feedback>

      This method is deprecated and will be removed in future LangSmith versions, use evaluate from langsmith/evaluation instead.

    • Flushes current queued traces.

      Returns Promise<void>

    • Parameters

      • __namedParameters: { datasetId?: string; datasetName?: string }

      Returns Promise<string>

    • Returns string

    • Parameters

      • __namedParameters: { projectId?: string; projectName?: string }

      Returns Promise<string>

    • Parameters

      • promptIdentifier: string

      Returns Promise<null | Prompt>

    • Get a run from an annotation queue at the specified index.

      Parameters

      • queueId: string

        The ID of the annotation queue

      • index: number

        The index of the run to retrieve

      Returns Promise<RunWithAnnotationQueueInfo>

      A Promise that resolves to a RunWithAnnotationQueueInfo object

      If the run is not found at the given index or for other API-related errors

    • Parameters

      • __namedParameters: {
            dataSourceType?: string;
            endTime?: string;
            error?: boolean;
            filter?: string;
            id?: string[];
            isRoot?: boolean;
            parentRun?: string;
            projectIds?: string[];
            projectNames?: string[];
            query?: string;
            referenceExampleIds?: string[];
            runType?: string;
            startTime?: string;
            trace?: string;
            traceFilter?: string;
            treeFilter?: string;
        }

      Returns Promise<any>

    • Parameters

      • __namedParameters: { projectOpts?: ProjectOptions; run?: Run; runId?: string }

      Returns Promise<string>

    • Get the size of an annotation queue.

      Parameters

      • queueId: string

        The ID of the annotation queue

      Returns Promise<{ size: number }>

    • Parameters

      • __namedParameters: { datasetId?: string; datasetName?: string }

      Returns Promise<boolean>

    • Parameters

      • __namedParameters: { projectId?: string; projectName?: string }

      Returns Promise<boolean>

    • Parameters

      • __namedParameters: { datasetId?: string; datasetName?: string; tag?: string }

      Returns Promise<void>

    • Parameters

      • promptIdentifier: string

      Returns Promise<LikePromptResponse>

    • List the annotation queues on the LangSmith API.

      Parameters

      • options: { limit?: number; name?: string; nameContains?: string; queueIds?: string[] } = {}

        The options for listing annotation queues

        • Optionallimit?: number

          The maximum number of queues to return

        • Optionalname?: string

          The name of the queue to filter by

        • OptionalnameContains?: string

          The substring that the queue name should contain

        • OptionalqueueIds?: string[]

          The IDs of the queues to filter by

      Returns AsyncIterableIterator<AnnotationQueue>

      An iterator of AnnotationQueue objects

    • Parameters

      • promptOwnerAndName: string

      Returns AsyncIterableIterator<PromptCommit>

    • Parameters

      • __namedParameters: {
            datasetIds?: string[];
            datasetName?: string;
            datasetNameContains?: string;
            limit?: number;
            metadata?: RecordStringAny;
            offset?: number;
        } = {}

      Returns AsyncIterable<Dataset>

    • Parameters

      • __namedParameters: { asOf?: string | Date; datasetId?: string; datasetName?: string }

      Returns Promise<string[]>

    • Parameters

      • __namedParameters: {
            asOf?: string | Date;
            datasetId?: string;
            datasetName?: string;
            exampleIds?: string[];
            filter?: string;
            includeAttachments?: boolean;
            inlineS3Urls?: boolean;
            limit?: number;
            metadata?: KVMap;
            offset?: number;
            splits?: string[];
        } = {}

      Returns AsyncIterable<Example>

    • Parameters

      • __namedParameters: {
            feedbackKeys?: string[];
            feedbackSourceTypes?: FeedbackSourceType[];
            runIds?: string[];
        } = {}

      Returns AsyncIterable<Feedback>

    • Parameters

      • props: GroupRunsParams

      Returns AsyncIterable<Thread>

    • Retrieves a list of presigned feedback tokens for a given run ID.

      Parameters

      • runId: string

        The ID of the run.

      Returns AsyncIterable<FeedbackIngestToken>

      An async iterable of FeedbackIngestToken objects.

    • Parameters

      • __namedParameters: {
            datasetVersion?: string;
            includeStats?: boolean;
            metadata?: RecordStringAny;
            name?: string;
            nameContains?: string;
            projectIds?: string[];
            referenceDatasetId?: string;
            referenceDatasetName?: string;
            referenceFree?: boolean;
        } = {}

      Returns AsyncIterable<TracerSessionResult>

    • Parameters

      • Optionaloptions: {
            isArchived?: boolean;
            isPublic?: boolean;
            query?: string;
            sortField?: PromptSortField;
        }

      Returns AsyncIterableIterator<Prompt>

    • List runs from the LangSmith server.

      Parameters

      • props: ListRunsParams

      Returns AsyncIterable<Run>

      • The runs.
      // List all runs in a project
      const projectRuns = client.listRuns({ projectName: "<your_project>" });
      // List LLM and Chat runs in the last 24 hours
      const todaysLLMRuns = client.listRuns({
      projectName: "<your_project>",
      start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
      run_type: "llm",
      });
      // List traces in a project
      const rootRuns = client.listRuns({
      projectName: "<your_project>",
      execution_order: 1,
      });
      // List runs without errors
      const correctRuns = client.listRuns({
      projectName: "<your_project>",
      error: false,
      });
      // List runs by run ID
      const runIds = [
      "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
      "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
      ];
      const selectedRuns = client.listRuns({ run_ids: runIds });
      // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
      const chainRuns = client.listRuns({
      projectName: "<your_project>",
      filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
      });
      // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
      const goodExtractorRuns = client.listRuns({
      projectName: "<your_project>",
      filter: 'eq(name, "extractor")',
      traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
      });
      // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
      const complexRuns = client.listRuns({
      projectName: "<your_project>",
      filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
      });
      // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
      const taggedRuns = client.listRuns({
      projectName: "<your_project>",
      filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
      });
    • Get shared examples.

      Parameters

      • shareToken: string

        The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.

      • Optionaloptions: { exampleIds?: string[] }

        Additional options for listing the examples.

        • OptionalexampleIds?: string[]

          A list of example IDs to filter by.

      Returns Promise<Example[]>

      The shared examples.

    • Parameters

      • shareToken: string
      • __namedParameters: { runIds?: string[] } = {}

      Returns Promise<Run[]>

    • Batch ingest/upsert multiple runs in the Langsmith system.

      Parameters

      • __namedParameters: { runCreates?: RunCreate[]; runUpdates?: RunUpdate[] }
      • Optionaloptions: { apiKey?: string; apiUrl?: string; useGzip?: boolean }

      Returns Promise<void>

    • Parameters

      • promptIdentifier: string

      Returns Promise<boolean>

    • Parameters

      • promptIdentifier: string
      • Optionaloptions: { includeModel?: boolean }

      Returns Promise<PromptCommit>

    • Parameters

      • promptIdentifier: string
      • Optionaloptions: {
            description?: string;
            isPublic?: boolean;
            object?: any;
            parentCommitHash?: string;
            readme?: string;
            tags?: string[];
        }

      Returns Promise<string>

    • Read an annotation queue with the specified queue ID.

      Parameters

      • queueId: string

        The ID of the annotation queue to read

      Returns Promise<AnnotationQueueWithDetails>

      The AnnotationQueueWithDetails object

    • Parameters

      • __namedParameters: { datasetId?: string; datasetName?: string }

      Returns Promise<Dataset>

    • Parameters

      • __namedParameters: { datasetId?: string; datasetName?: string }

      Returns Promise<any[]>

    • Parameters

      • OptionaldatasetId: string
      • OptionaldatasetName: string

      Returns Promise<DatasetShareSchema>

    • Get dataset version by closest date or exact tag.

      Use this to resolve the nearest version to a given timestamp or for a given tag.

      Parameters

      • options: { asOf?: string | Date; datasetId?: string; datasetName?: string; tag?: string }

        The options for getting the dataset version

        • OptionalasOf?: string | Date

          The timestamp of the dataset to retrieve

        • OptionaldatasetId?: string

          The ID of the dataset

        • OptionaldatasetName?: string

          The name of the dataset

        • Optionaltag?: string

          The tag of the dataset to retrieve

      Returns Promise<DatasetVersion>

      The dataset version

    • Parameters

      • exampleId: string

      Returns Promise<Example>

    • Parameters

      • feedbackId: string

      Returns Promise<Feedback>

    • Parameters

      • __namedParameters: { includeStats?: boolean; projectId?: string; projectName?: string }

      Returns Promise<TracerSessionResult>

    • Parameters

      • runId: string
      • __namedParameters: { loadChildRuns: boolean } = ...

      Returns Promise<Run>

    • Parameters

      • runId: string

      Returns Promise<undefined | string>

    • Parameters

      • shareToken: string

      Returns Promise<Dataset>

    • Parameters

      • OptionaldatasetId: string
      • OptionaldatasetName: string

      Returns Promise<DatasetShareSchema>

    • Parameters

      • runId: string
      • __namedParameters: { shareId?: string } = {}

      Returns Promise<string>

    • Lets you run a similarity search query on a dataset.

      Requires the dataset to be indexed. Please see the indexDataset method to set up indexing.

      Parameters

      • inputs: KVMap

        The input on which to run the similarity search. Must have the same schema as the dataset.

      • datasetId: string

        The dataset to search for similar examples.

      • limit: number

        The maximum number of examples to return. Will return the top limit most similar examples in order of most similar to least similar. If no similar examples are found, random examples will be returned.

      • filter: { filter?: string } = {}

        A filter string to apply to the search. Only examples will be returned that match the filter string. Some examples of filters

                       - eq(metadata.mykey, "value")
                       - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value"))
                       - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue"))
        

      Returns Promise<ExampleSearch[]>

      A list of similar examples.

      dataset_id = "123e4567-e89b-12d3-a456-426614174000"
      inputs = {"text": "How many people live in Berlin?"}
      limit = 5
      examples = await client.similarExamples(inputs, dataset_id, limit)
    • Parameters

      • promptIdentifier: string

      Returns Promise<LikePromptResponse>

    • Parameters

      • datasetId: string

      Returns Promise<void>

    • Parameters

      • runId: string

      Returns Promise<void>

    • Update an annotation queue with the specified queue ID.

      Parameters

      • queueId: string

        The ID of the annotation queue to update

      • options: { description?: string; name: string; rubricInstructions?: string }

        The options for updating the annotation queue

        • Optionaldescription?: string

          The new description for the annotation queue

        • name: string

          The new name for the annotation queue

        • OptionalrubricInstructions?: string

      Returns Promise<void>

    • Update a dataset

      Parameters

      • props: {
            datasetId?: string;
            datasetName?: string;
            description?: string;
            name?: string;
        }

        The dataset details to update

      Returns Promise<Dataset>

      The updated dataset

    • Parameters

      • __namedParameters: {
            datasetId?: string;
            datasetName?: string;
            exampleIds: string[];
            remove?: boolean;
            splitName: string;
        }

      Returns Promise<void>

    • Updates a tag on a dataset.

      If the tag is already assigned to a different version of this dataset, the tag will be moved to the new version. The as_of parameter is used to determine which version of the dataset to apply the new tags to.

      It must be an exact version of the dataset to succeed. You can use the "readDatasetVersion" method to find the exact version to apply the tags to.

      Parameters

      • props: { asOf: string | Date; datasetId?: string; datasetName?: string; tag: string }

      Returns Promise<void>

    • Parameters

      Returns Promise<object>

      This signature is deprecated, use updateExample(update: ExampleUpdate) instead

    • Parameters

      Returns Promise<object>

      This signature is deprecated, use updateExample(update: ExampleUpdate) instead

    • Parameters

      Returns Promise<object>

    • Update examples with attachments using multipart form data.

      Parameters

      • datasetId: string
      • updates: ExampleUpdate[] = []

        List of ExampleUpdateWithAttachments objects to upsert

      Returns Promise<UpdateExamplesResponse>

      Promise with the update response

    • Parameters

      • feedbackId: string
      • __namedParameters: {
            comment?: null | string;
            correction?: null | object;
            score?: null | number | boolean;
            value?: null | string | number | boolean | object;
        }

      Returns Promise<void>

    • Parameters

      • projectId: string
      • __namedParameters: {
            description?: null | string;
            endTime?: null | string;
            metadata?: null | RecordStringAny;
            name?: null | string;
            projectExtra?: null | RecordStringAny;
        }

      Returns Promise<TracerSession>

    • Parameters

      • promptIdentifier: string
      • Optionaloptions: {
            description?: string;
            isArchived?: boolean;
            isPublic?: boolean;
            readme?: string;
            tags?: string[];
        }

      Returns Promise<Record<string, any>>

    • Parameters

      • runId: string
      • run: RunUpdate
      • Optionaloptions: { apiKey?: string; apiUrl?: string; workspaceId?: string }

      Returns Promise<void>

    • Parameters

      • __namedParameters: UploadCSVParams

      Returns Promise<Dataset>

    • Upload examples with attachments using multipart form data.

      Parameters

      • datasetId: string
      • uploads: ExampleCreate[] = []

        List of ExampleUploadWithAttachments objects to upload

      Returns Promise<UploadExamplesResponse>

      Promise with the upload response

      This method is deprecated and will be removed in future LangSmith versions, please use createExamples instead

    • Returns {
          apiKey?: string;
          apiUrl: string;
          hideInputs?: boolean;
          hideOutputs?: boolean;
          webUrl?: string;
      }