schemas.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. export interface TracerSession {
  2. tenant_id: string;
  3. id: string;
  4. start_time: number;
  5. end_time?: number;
  6. description?: string;
  7. name?: string;
  8. /** Extra metadata for the project. */
  9. extra?: KVMap;
  10. reference_dataset_id?: string;
  11. }
  12. export interface TracerSessionResult extends TracerSession {
  13. run_count?: number;
  14. latency_p50?: number;
  15. latency_p99?: number;
  16. total_tokens?: number;
  17. prompt_tokens?: number;
  18. completion_tokens?: number;
  19. last_run_start_time?: number;
  20. feedback_stats?: Record<string, unknown>;
  21. run_facets?: KVMap[];
  22. }
  23. export type KVMap = Record<string, any>;
  24. export type RunType = "llm" | "chain" | "tool" | "retriever" | "embedding" | "prompt" | "parser";
  25. export type ScoreType = number | boolean | null;
  26. export type ValueType = number | boolean | string | object | null;
  27. export type DataType = "kv" | "llm" | "chat";
  28. export interface BaseExample {
  29. dataset_id: string;
  30. inputs: KVMap;
  31. outputs?: KVMap;
  32. metadata?: KVMap;
  33. source_run_id?: string;
  34. }
  35. export interface AttachmentInfo {
  36. presigned_url: string;
  37. mime_type?: string;
  38. }
  39. export type AttachmentData = Uint8Array | ArrayBuffer;
  40. export type AttachmentDescription = {
  41. mimeType: string;
  42. data: AttachmentData;
  43. };
  44. export type Attachments = Record<string, [
  45. string,
  46. AttachmentData
  47. ] | AttachmentDescription>;
  48. /**
  49. * A run can represent either a trace (root run)
  50. * or a child run (~span).
  51. */
  52. export interface BaseRun {
  53. /** Optionally, a unique identifier for the run. */
  54. id?: string;
  55. /** A human-readable name for the run. */
  56. name: string;
  57. /** The epoch time at which the run started, if available. */
  58. start_time?: number;
  59. /** Specifies the type of run (tool, chain, llm, etc.). */
  60. run_type: string;
  61. /** The epoch time at which the run ended, if applicable. */
  62. end_time?: number;
  63. /** Any additional metadata or settings for the run. */
  64. extra?: KVMap;
  65. /** Error message, captured if the run faces any issues. */
  66. error?: string;
  67. /** Serialized state of the run for potential future use. */
  68. serialized?: object;
  69. /** Events like 'start', 'end' linked to the run. */
  70. events?: KVMap[];
  71. /** Inputs that were used to initiate the run. */
  72. inputs: KVMap;
  73. /** Outputs produced by the run, if any. */
  74. outputs?: KVMap;
  75. /** ID of an example that might be related to this run. */
  76. reference_example_id?: string;
  77. /** ID of a parent run, if this run is part of a larger operation. */
  78. parent_run_id?: string;
  79. /** Tags for further categorizing or annotating the run. */
  80. tags?: string[];
  81. /** Unique ID assigned to every run within this nested trace. **/
  82. trace_id?: string;
  83. /**
  84. * The dotted order for the run.
  85. *
  86. * This is a string composed of {time}{run-uuid}.* so that a trace can be
  87. * sorted in the order it was executed.
  88. *
  89. * Example:
  90. * - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
  91. * - Children:
  92. * - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
  93. * - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
  94. */
  95. dotted_order?: string;
  96. /**
  97. * Attachments associated with the run.
  98. * Each entry is a tuple of [mime_type, bytes]
  99. */
  100. attachments?: Attachments;
  101. }
  102. type S3URL = {
  103. ROOT: {
  104. /** A pre-signed URL */
  105. presigned_url: string;
  106. /** The S3 path to the object in storage */
  107. s3_url: string;
  108. };
  109. };
  110. /**
  111. * Describes properties of a run when loaded from the database.
  112. * Extends the BaseRun interface.
  113. */
  114. export interface Run extends BaseRun {
  115. /** A unique identifier for the run, mandatory when loaded from DB. */
  116. id: string;
  117. /** The ID of the project that owns this run. */
  118. session_id?: string;
  119. /** IDs of any child runs spawned by this run. */
  120. child_run_ids?: string[];
  121. /** Child runs, loaded explicitly via a heavier query. */
  122. child_runs?: Run[];
  123. /** Stats capturing feedback for this run. */
  124. feedback_stats?: KVMap;
  125. /** The URL path where this run is accessible within the app. */
  126. app_path?: string;
  127. /** The manifest ID that correlates with this run. */
  128. manifest_id?: string;
  129. /** The current status of the run, such as 'success'. */
  130. status?: string;
  131. /** Number of tokens used in the prompt. */
  132. prompt_tokens?: number;
  133. /** Number of tokens generated in the completion. */
  134. completion_tokens?: number;
  135. /** Total token count, combining prompt and completion. */
  136. total_tokens?: number;
  137. /** Time when the first token was processed. */
  138. first_token_time?: number;
  139. /** IDs of parent runs, if multiple exist. */
  140. parent_run_ids?: string[];
  141. /** Whether the run is included in a dataset. */
  142. in_dataset?: boolean;
  143. /** The output S3 URLs */
  144. outputs_s3_urls?: S3URL;
  145. /** The input S3 URLs */
  146. inputs_s3_urls?: S3URL;
  147. }
  148. export interface RunCreate extends BaseRun {
  149. revision_id?: string;
  150. child_runs?: this[];
  151. session_name?: string;
  152. }
  153. export interface RunUpdate {
  154. id?: string;
  155. end_time?: number;
  156. extra?: KVMap;
  157. tags?: string[];
  158. error?: string;
  159. inputs?: KVMap;
  160. outputs?: KVMap;
  161. parent_run_id?: string;
  162. reference_example_id?: string;
  163. events?: KVMap[];
  164. session_id?: string;
  165. session_name?: string;
  166. /** Unique ID assigned to every run within this nested trace. **/
  167. trace_id?: string;
  168. /**
  169. * The dotted order for the run.
  170. *
  171. * This is a string composed of {time}{run-uuid}.* so that a trace can be
  172. * sorted in the order it was executed.
  173. *
  174. * Example:
  175. * - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
  176. * - Children:
  177. * - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
  178. * - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
  179. */
  180. dotted_order?: string;
  181. /**
  182. * Attachments associated with the run.
  183. * Each entry is a tuple of [mime_type, bytes]
  184. */
  185. attachments?: Attachments;
  186. }
  187. export interface ExampleCreate {
  188. id?: string;
  189. inputs: KVMap;
  190. outputs?: KVMap;
  191. metadata?: KVMap;
  192. split?: string | string[];
  193. attachments?: Attachments;
  194. created_at?: string;
  195. dataset_id?: string;
  196. dataset_name?: string;
  197. source_run_id?: string;
  198. use_source_run_io?: boolean;
  199. use_source_run_attachments?: string[];
  200. }
  201. export interface ExampleUploadWithAttachments extends ExampleCreate {
  202. }
  203. export interface ExampleUpdate {
  204. id: string;
  205. inputs?: KVMap;
  206. outputs?: KVMap;
  207. metadata?: KVMap;
  208. split?: string | string[];
  209. attachments?: Attachments;
  210. attachments_operations?: KVMap;
  211. dataset_id?: string;
  212. }
  213. export interface ExampleUpdateWithoutId extends Omit<ExampleUpdate, "id"> {
  214. }
  215. export interface ExampleUpdateWithAttachments extends ExampleUpdate {
  216. }
  217. export interface UploadExamplesResponse {
  218. count: number;
  219. example_ids: string[];
  220. }
  221. export interface UpdateExamplesResponse extends UploadExamplesResponse {
  222. }
  223. export interface Example extends BaseExample {
  224. id: string;
  225. created_at: string;
  226. modified_at?: string;
  227. source_run_id?: string;
  228. runs: Run[];
  229. attachments?: Record<string, AttachmentInfo>;
  230. split?: string | string[];
  231. }
  232. interface RawAttachmentInfo {
  233. presigned_url: string;
  234. s3_url: string;
  235. mime_type?: string;
  236. }
  237. export interface RawExample extends BaseExample {
  238. id: string;
  239. created_at: string;
  240. modified_at: string;
  241. source_run_id?: string;
  242. runs: Run[];
  243. attachment_urls?: Record<string, RawAttachmentInfo>;
  244. }
  245. export interface ExampleUpdateWithId extends ExampleUpdate {
  246. }
  247. export interface ExampleSearch extends BaseExample {
  248. id: string;
  249. }
  250. export interface BaseDataset {
  251. name: string;
  252. description: string;
  253. tenant_id: string;
  254. data_type?: DataType;
  255. inputs_schema_definition?: KVMap;
  256. outputs_schema_definition?: KVMap;
  257. }
  258. export interface Dataset extends BaseDataset {
  259. id: string;
  260. created_at: string;
  261. modified_at: string;
  262. example_count?: number;
  263. session_count?: number;
  264. last_session_start_time?: number;
  265. }
  266. export interface DatasetShareSchema {
  267. dataset_id: string;
  268. share_token: string;
  269. url: string;
  270. }
  271. export interface DatasetVersion {
  272. tags?: string[];
  273. as_of: string;
  274. }
  275. export interface FeedbackSourceBase {
  276. type: string;
  277. metadata?: KVMap;
  278. }
  279. export interface APIFeedbackSource extends FeedbackSourceBase {
  280. type: "api";
  281. }
  282. export interface ModelFeedbackSource extends FeedbackSourceBase {
  283. type: "model";
  284. }
  285. export interface FeedbackBase {
  286. created_at: string;
  287. modified_at: string;
  288. run_id: string;
  289. key: string;
  290. score: ScoreType;
  291. value: ValueType;
  292. comment: string | null;
  293. correction: string | object | null;
  294. feedback_source: APIFeedbackSource | ModelFeedbackSource | KVMap | null;
  295. }
  296. export interface FeedbackCreate extends FeedbackBase {
  297. id: string;
  298. }
  299. export interface Feedback extends FeedbackBase {
  300. id: string;
  301. }
  302. export interface LangChainBaseMessage {
  303. _getType: () => string;
  304. content: string;
  305. additional_kwargs?: KVMap;
  306. }
  307. export interface FeedbackIngestToken {
  308. id: string;
  309. url: string;
  310. expires_at: string;
  311. }
  312. export interface TimeDelta {
  313. days?: number;
  314. hours?: number;
  315. minutes?: number;
  316. }
  317. export interface FeedbackCategory {
  318. value: number;
  319. label?: string | null;
  320. }
  321. /**
  322. * Represents the configuration for feedback.
  323. * This determines how the LangSmith service interprets feedback
  324. * values of the associated key.
  325. */
  326. export interface FeedbackConfig {
  327. /**
  328. * The type of feedback.
  329. * - "continuous": Feedback with a continuous numeric.
  330. * - "categorical": Feedback with a categorical value (classes)
  331. * - "freeform": Feedback with a freeform text value (notes).
  332. */
  333. type: "continuous" | "categorical" | "freeform";
  334. /**
  335. * The minimum value for continuous feedback.
  336. */
  337. min?: number | null;
  338. /**
  339. * The maximum value for continuous feedback.
  340. */
  341. max?: number | null;
  342. /**
  343. * The categories for categorical feedback.
  344. * Each category can be a string or an object with additional properties.
  345. *
  346. * If feedback is categorical, this defines the valid categories the server will accept.
  347. * Not applicable to continuous or freeform feedback types.
  348. */
  349. categories?: FeedbackCategory[] | null;
  350. }
  351. export interface DatasetDiffInfo {
  352. examples_modified: string[];
  353. examples_added: string[];
  354. examples_removed: string[];
  355. }
  356. export interface ComparisonEvaluationResult {
  357. key: string;
  358. scores: Record<string, ScoreType>;
  359. source_run_id?: string;
  360. }
  361. export interface ComparativeExperiment {
  362. id: string;
  363. name: string;
  364. description: string;
  365. tenant_id: string;
  366. created_at: string;
  367. modified_at: string;
  368. reference_dataset_id: string;
  369. extra?: Record<string, unknown>;
  370. experiments_info?: Array<Record<string, unknown>>;
  371. feedback_stats?: Record<string, unknown>;
  372. }
  373. /**
  374. * Represents the expected output schema returned by traceable
  375. * or by run tree output for LangSmith to correctly display
  376. * documents in the UI
  377. */
  378. export type RetrieverOutput = Array<{
  379. page_content: string;
  380. type: "Document";
  381. metadata?: KVMap;
  382. }>;
  383. export interface InvocationParamsSchema {
  384. ls_provider?: string;
  385. ls_model_name?: string;
  386. ls_model_type: "chat" | "llm";
  387. ls_temperature?: number;
  388. ls_max_tokens?: number;
  389. ls_stop?: string[];
  390. }
  391. export interface PromptCommit {
  392. owner: string;
  393. repo: string;
  394. commit_hash: string;
  395. manifest: Record<string, any>;
  396. examples: Array<Record<any, any>>;
  397. }
  398. export interface Prompt {
  399. repo_handle: string;
  400. description?: string;
  401. readme?: string;
  402. id: string;
  403. tenant_id: string;
  404. created_at: string;
  405. updated_at: string;
  406. is_public: boolean;
  407. is_archived: boolean;
  408. tags: string[];
  409. original_repo_id?: string;
  410. upstream_repo_id?: string;
  411. owner?: string;
  412. full_name: string;
  413. num_likes: number;
  414. num_downloads: number;
  415. num_views: number;
  416. liked_by_auth_user: boolean;
  417. last_commit_hash?: string;
  418. num_commits: number;
  419. original_repo_full_name?: string;
  420. upstream_repo_full_name?: string;
  421. }
  422. export interface ListPromptsResponse {
  423. repos: Prompt[];
  424. total: number;
  425. }
  426. export interface ListCommitsResponse {
  427. commits: PromptCommit[];
  428. total: number;
  429. }
  430. export type PromptSortField = "num_downloads" | "num_views" | "updated_at" | "num_likes";
  431. export interface LikePromptResponse {
  432. likes: number;
  433. }
  434. export interface LangSmithSettings {
  435. id: string;
  436. display_name: string;
  437. created_at: string;
  438. tenant_handle?: string;
  439. }
  440. export interface AnnotationQueue {
  441. /** The unique identifier of the annotation queue. */
  442. id: string;
  443. /** The name of the annotation queue. */
  444. name: string;
  445. /** An optional description of the annotation queue. */
  446. description?: string;
  447. /** The timestamp when the annotation queue was created. */
  448. created_at: string;
  449. /** The timestamp when the annotation queue was last updated. */
  450. updated_at: string;
  451. /** The ID of the tenant associated with the annotation queue. */
  452. tenant_id: string;
  453. }
  454. export interface AnnotationQueueWithDetails extends AnnotationQueue {
  455. /** The rubric instructions for the annotation queue. */
  456. rubric_instructions?: string;
  457. }
  458. export interface RunWithAnnotationQueueInfo extends BaseRun {
  459. /** The last time this run was reviewed. */
  460. last_reviewed_time?: string;
  461. /** The time this run was added to the queue. */
  462. added_at?: string;
  463. }
  464. /**
  465. * Breakdown of input token counts.
  466. *
  467. * Does not *need* to sum to full input token count. Does *not* need to have all keys.
  468. */
  469. export type InputTokenDetails = {
  470. /**
  471. * Audio input tokens.
  472. */
  473. audio?: number;
  474. /**
  475. * Input tokens that were cached and there was a cache hit.
  476. *
  477. * Since there was a cache hit, the tokens were read from the cache.
  478. * More precisely, the model state given these tokens was read from the cache.
  479. */
  480. cache_read?: number;
  481. /**
  482. * Input tokens that were cached and there was a cache miss.
  483. *
  484. * Since there was a cache miss, the cache was created from these tokens.
  485. */
  486. cache_creation?: number;
  487. };
  488. /**
  489. * Breakdown of output token counts.
  490. *
  491. * Does *not* need to sum to full output token count. Does *not* need to have all keys.
  492. */
  493. export type OutputTokenDetails = {
  494. /**
  495. * Audio output tokens
  496. */
  497. audio?: number;
  498. /**
  499. * Reasoning output tokens.
  500. *
  501. * Tokens generated by the model in a chain of thought process (i.e. by
  502. * OpenAI's o1 models) that are not returned as part of model output.
  503. */
  504. reasoning?: number;
  505. };
  506. /**
  507. * Usage metadata for a message, such as token counts.
  508. */
  509. export type UsageMetadata = {
  510. /**
  511. * Count of input (or prompt) tokens. Sum of all input token types.
  512. */
  513. input_tokens: number;
  514. /**
  515. * Count of output (or completion) tokens. Sum of all output token types.
  516. */
  517. output_tokens: number;
  518. /**
  519. * Total token count. Sum of input_tokens + output_tokens.
  520. */
  521. total_tokens: number;
  522. /**
  523. * Breakdown of input token counts.
  524. *
  525. * Does *not* need to sum to full input token count. Does *not* need to have all keys.
  526. */
  527. input_token_details?: InputTokenDetails;
  528. /**
  529. * Breakdown of output token counts.
  530. *
  531. * Does *not* need to sum to full output token count. Does *not* need to have all keys.
  532. */
  533. output_token_details?: OutputTokenDetails;
  534. };
  535. export {};