diff --git a/src/core.ts b/src/core.ts index b3ede40..dba74b0 100644 --- a/src/core.ts +++ b/src/core.ts @@ -409,7 +409,7 @@ export abstract class APIClient { !headers ? {} : Symbol.iterator in headers ? Object.fromEntries(Array.from(headers as Iterable).map((header) => [...header])) - : { ...headers } + : { ...(headers as any as Record) } ); } diff --git a/src/index.ts b/src/index.ts index 6fd5d4d..03203a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,8 @@ import { type Agent } from './_shims/index'; import * as qs from './internal/qs'; import * as Core from './core'; import * as Errors from './error'; +import * as Pagination from './pagination'; +import { type DatasetsIterrowsParams, DatasetsIterrowsResponse } from './pagination'; import * as Uploads from './uploads'; import * as API from './resources/index'; import { @@ -20,14 +22,11 @@ import { ListBenchmarksResponse, } from './resources/benchmarks'; import { - Datasetio, - DatasetioAppendRowsParams, - DatasetioGetRowsPaginatedParams, - PaginatedRowsResult, -} from './resources/datasetio'; -import { + DatasetIterrowsParams, + DatasetIterrowsResponse, DatasetListResponse, DatasetRegisterParams, + DatasetRegisterResponse, DatasetRetrieveResponse, Datasets, ListDatasetsResponse, @@ -286,7 +285,6 @@ export class LlamaStackClient extends Core.APIClient { shields: API.Shields = new API.Shields(this); syntheticDataGeneration: API.SyntheticDataGeneration = new API.SyntheticDataGeneration(this); telemetry: API.Telemetry = new API.Telemetry(this); - datasetio: API.Datasetio = new API.Datasetio(this); scoring: API.Scoring = new API.Scoring(this); scoringFunctions: API.ScoringFunctions = new API.ScoringFunctions(this); benchmarks: API.Benchmarks = new API.Benchmarks(this); @@ -353,13 +351,18 @@ LlamaStackClient.Safety = Safety; LlamaStackClient.Shields = Shields; LlamaStackClient.SyntheticDataGeneration = SyntheticDataGeneration; LlamaStackClient.Telemetry = Telemetry; -LlamaStackClient.Datasetio = Datasetio; LlamaStackClient.Scoring = Scoring; LlamaStackClient.ScoringFunctions = ScoringFunctions; LlamaStackClient.Benchmarks = Benchmarks; export declare namespace LlamaStackClient { export type RequestOptions = Core.RequestOptions; + export import DatasetsIterrows = Pagination.DatasetsIterrows; + export { + type DatasetsIterrowsParams as DatasetsIterrowsParams, + type DatasetsIterrowsResponse as DatasetsIterrowsResponse, + }; + export { Toolgroups as Toolgroups, type ListToolGroupsResponse as ListToolGroupsResponse, @@ -407,6 +410,9 @@ export declare namespace LlamaStackClient { type ListDatasetsResponse as ListDatasetsResponse, type DatasetRetrieveResponse as DatasetRetrieveResponse, type DatasetListResponse as DatasetListResponse, + type DatasetIterrowsResponse as DatasetIterrowsResponse, + type DatasetRegisterResponse as DatasetRegisterResponse, + type DatasetIterrowsParams as DatasetIterrowsParams, type DatasetRegisterParams as DatasetRegisterParams, }; @@ -528,13 +534,6 @@ export declare namespace LlamaStackClient { type TelemetrySaveSpansToDatasetParams as TelemetrySaveSpansToDatasetParams, }; - export { - Datasetio as Datasetio, - type PaginatedRowsResult as PaginatedRowsResult, - type DatasetioAppendRowsParams as DatasetioAppendRowsParams, - type DatasetioGetRowsPaginatedParams as DatasetioGetRowsPaginatedParams, - }; - export { Scoring as Scoring, type ScoringScoreResponse as ScoringScoreResponse, diff --git a/src/pagination.ts b/src/pagination.ts new file mode 100644 index 0000000..9e0d28e --- /dev/null +++ b/src/pagination.ts @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core'; + +export interface DatasetsIterrowsResponse { + data: Array; + + next_index: number; +} + +export interface DatasetsIterrowsParams { + dataset_id?: string; + + start_index?: number; + + limit?: number; +} + +export class DatasetsIterrows extends AbstractPage implements DatasetsIterrowsResponse { + data: Array; + + next_index: number; + + constructor( + client: APIClient, + response: Response, + body: DatasetsIterrowsResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.data = body.data || []; + this.next_index = body.next_index || 0; + } + + getPaginatedItems(): Item[] { + return this.data ?? []; + } + + // @deprecated Please use `nextPageInfo()` instead + nextPageParams(): Partial | null { + const info = this.nextPageInfo(); + if (!info) return null; + if ('params' in info) return info.params; + const params = Object.fromEntries(info.url.searchParams); + if (!Object.keys(params).length) return null; + return params; + } + + nextPageInfo(): PageInfo | null { + const cursor = this.next_index; + if (!cursor) { + return null; + } + + return { + params: { + start_index: cursor, + }, + }; + } +} diff --git a/src/resources.ts b/src/resources.ts new file mode 100644 index 0000000..b283d57 --- /dev/null +++ b/src/resources.ts @@ -0,0 +1 @@ +export * from './resources/index'; diff --git a/src/resources/benchmarks.ts b/src/resources/benchmarks.ts index 8c1c96d..1c7d93c 100644 --- a/src/resources/benchmarks.ts +++ b/src/resources/benchmarks.ts @@ -4,7 +4,7 @@ import { APIResource } from '../resource'; import * as Core from '../core'; export class Benchmarks extends APIResource { - retrieve(benchmarkId: string, options?: Core.RequestOptions): Core.APIPromise { + retrieve(benchmarkId: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/eval/benchmarks/${benchmarkId}`, options); } diff --git a/src/resources/datasetio.ts b/src/resources/datasetio.ts deleted file mode 100644 index ff3f533..0000000 --- a/src/resources/datasetio.ts +++ /dev/null @@ -1,80 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import { APIResource } from '../resource'; -import * as Core from '../core'; - -export class Datasetio extends APIResource { - appendRows(body: DatasetioAppendRowsParams, options?: Core.RequestOptions): Core.APIPromise { - return this._client.post('/v1/datasetio/rows', { - body, - ...options, - headers: { Accept: '*/*', ...options?.headers }, - }); - } - - /** - * Get a paginated list of rows from a dataset. - */ - getRowsPaginated( - query: DatasetioGetRowsPaginatedParams, - options?: Core.RequestOptions, - ): Core.APIPromise { - return this._client.get('/v1/datasetio/rows', { query, ...options }); - } -} - -/** - * A paginated list of rows from a dataset. - */ -export interface PaginatedRowsResult { - /** - * The rows in the current page. - */ - rows: Array | unknown | null>>; - - /** - * The total number of rows in the dataset. - */ - total_count: number; - - /** - * The token to get the next page of rows. - */ - next_page_token?: string; -} - -export interface DatasetioAppendRowsParams { - dataset_id: string; - - rows: Array | unknown | null>>; -} - -export interface DatasetioGetRowsPaginatedParams { - /** - * The ID of the dataset to get the rows from. - */ - dataset_id: string; - - /** - * The number of rows to get per page. - */ - rows_in_page: number; - - /** - * (Optional) A condition to filter the rows by. - */ - filter_condition?: string; - - /** - * The token to get the next page of rows. - */ - page_token?: string; -} - -export declare namespace Datasetio { - export { - type PaginatedRowsResult as PaginatedRowsResult, - type DatasetioAppendRowsParams as DatasetioAppendRowsParams, - type DatasetioGetRowsPaginatedParams as DatasetioGetRowsPaginatedParams, - }; -} diff --git a/src/resources/datasets.ts b/src/resources/datasets.ts index ae0ed16..a28f9f5 100644 --- a/src/resources/datasets.ts +++ b/src/resources/datasets.ts @@ -1,14 +1,11 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../resource'; +import { isRequestOptions } from '../core'; import * as Core from '../core'; -import * as Shared from './shared'; export class Datasets extends APIResource { - retrieve( - datasetId: string, - options?: Core.RequestOptions, - ): Core.APIPromise { + retrieve(datasetId: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/datasets/${datasetId}`, options); } @@ -18,12 +15,34 @@ export class Datasets extends APIResource { )._thenUnwrap((obj) => obj.data); } - register(body: DatasetRegisterParams, options?: Core.RequestOptions): Core.APIPromise { - return this._client.post('/v1/datasets', { - body, - ...options, - headers: { Accept: '*/*', ...options?.headers }, - }); + /** + * Get a paginated list of rows from a dataset. Uses cursor-based pagination. + */ + iterrows( + datasetId: string, + query?: DatasetIterrowsParams, + options?: Core.RequestOptions, + ): Core.APIPromise; + iterrows(datasetId: string, options?: Core.RequestOptions): Core.APIPromise; + iterrows( + datasetId: string, + query: DatasetIterrowsParams | Core.RequestOptions = {}, + options?: Core.RequestOptions, + ): Core.APIPromise { + if (isRequestOptions(query)) { + return this.iterrows(datasetId, {}, query); + } + return this._client.get(`/v1/datasetio/iterrows/${datasetId}`, { query, ...options }); + } + + /** + * Register a new dataset. + */ + register( + body: DatasetRegisterParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + return this._client.post('/v1/datasets', { body, ...options }); } unregister(datasetId: string, options?: Core.RequestOptions): Core.APIPromise { @@ -39,8 +58,6 @@ export interface ListDatasetsResponse { } export interface DatasetRetrieveResponse { - dataset_schema: Record; - identifier: string; metadata: Record | unknown | null>; @@ -49,23 +66,53 @@ export interface DatasetRetrieveResponse { provider_resource_id: string; - type: 'dataset'; + /** + * Purpose of the dataset. Each purpose has a required input data schema. + */ + purpose: 'post-training/messages' | 'eval/question-answer' | 'eval/messages-answer'; + + /** + * A dataset that can be obtained from a URI. + */ + source: DatasetRetrieveResponse.UriDataSource | DatasetRetrieveResponse.RowsDataSource; - url: DatasetRetrieveResponse.URL; + type: 'dataset'; } export namespace DatasetRetrieveResponse { - export interface URL { + /** + * A dataset that can be obtained from a URI. + */ + export interface UriDataSource { + type: 'uri'; + + /** + * The dataset can be obtained from a URI. E.g. - + * "https://mywebsite.com/mydata.jsonl" - "lsfs://mydata.jsonl" - + * "data:csv;base64,{base64_content}" + */ uri: string; } + + /** + * A dataset stored in rows. + */ + export interface RowsDataSource { + /** + * The dataset is stored in rows. E.g. - [ {"messages": [{"role": "user", + * "content": "Hello, world!"}, {"role": "assistant", "content": "Hello, world!"}]} + * ] + */ + rows: Array | unknown | null>>; + + type: 'rows'; + } } export type DatasetListResponse = Array; export namespace DatasetListResponse { export interface DatasetListResponseItem { - dataset_schema: Record; - identifier: string; metadata: Record | unknown | null>; @@ -74,36 +121,197 @@ export namespace DatasetListResponse { provider_resource_id: string; - type: 'dataset'; + /** + * Purpose of the dataset. Each purpose has a required input data schema. + */ + purpose: 'post-training/messages' | 'eval/question-answer' | 'eval/messages-answer'; + + /** + * A dataset that can be obtained from a URI. + */ + source: DatasetListResponseItem.UriDataSource | DatasetListResponseItem.RowsDataSource; - url: DatasetListResponseItem.URL; + type: 'dataset'; } export namespace DatasetListResponseItem { - export interface URL { + /** + * A dataset that can be obtained from a URI. + */ + export interface UriDataSource { + type: 'uri'; + + /** + * The dataset can be obtained from a URI. E.g. - + * "https://mywebsite.com/mydata.jsonl" - "lsfs://mydata.jsonl" - + * "data:csv;base64,{base64_content}" + */ uri: string; } + + /** + * A dataset stored in rows. + */ + export interface RowsDataSource { + /** + * The dataset is stored in rows. E.g. - [ {"messages": [{"role": "user", + * "content": "Hello, world!"}, {"role": "assistant", "content": "Hello, world!"}]} + * ] + */ + rows: Array | unknown | null>>; + + type: 'rows'; + } } } -export interface DatasetRegisterParams { - dataset_id: string; +/** + * A paginated list of rows from a dataset. + */ +export interface DatasetIterrowsResponse { + /** + * The rows in the current page. + */ + data: Array | unknown | null>>; + + /** + * Index into dataset for the first row in the next page. None if there are no more + * rows. + */ + next_start_index?: number; +} - dataset_schema: Record; +export interface DatasetRegisterResponse { + identifier: string; - url: DatasetRegisterParams.URL; + metadata: Record | unknown | null>; - metadata?: Record | unknown | null>; + provider_id: string; + + provider_resource_id: string; + + /** + * Purpose of the dataset. Each purpose has a required input data schema. + */ + purpose: 'post-training/messages' | 'eval/question-answer' | 'eval/messages-answer'; - provider_dataset_id?: string; + /** + * A dataset that can be obtained from a URI. + */ + source: DatasetRegisterResponse.UriDataSource | DatasetRegisterResponse.RowsDataSource; - provider_id?: string; + type: 'dataset'; +} + +export namespace DatasetRegisterResponse { + /** + * A dataset that can be obtained from a URI. + */ + export interface UriDataSource { + type: 'uri'; + + /** + * The dataset can be obtained from a URI. E.g. - + * "https://mywebsite.com/mydata.jsonl" - "lsfs://mydata.jsonl" - + * "data:csv;base64,{base64_content}" + */ + uri: string; + } + + /** + * A dataset stored in rows. + */ + export interface RowsDataSource { + /** + * The dataset is stored in rows. E.g. - [ {"messages": [{"role": "user", + * "content": "Hello, world!"}, {"role": "assistant", "content": "Hello, world!"}]} + * ] + */ + rows: Array | unknown | null>>; + + type: 'rows'; + } +} + +export interface DatasetIterrowsParams { + /** + * The number of rows to get. + */ + limit?: number; + + /** + * Index into dataset for the first row to get. Get all rows if None. + */ + start_index?: number; +} + +export interface DatasetRegisterParams { + /** + * The purpose of the dataset. One of - "post-training/messages": The dataset + * contains a messages column with list of messages for post-training. { + * "messages": [ {"role": "user", "content": "Hello, world!"}, {"role": + * "assistant", "content": "Hello, world!"}, ] } - "eval/question-answer": The + * dataset contains a question column and an answer column for evaluation. { + * "question": "What is the capital of France?", "answer": "Paris" } - + * "eval/messages-answer": The dataset contains a messages column with list of + * messages and an answer column for evaluation. { "messages": [ {"role": "user", + * "content": "Hello, my name is John Doe."}, {"role": "assistant", "content": + * "Hello, John Doe. How can I help you today?"}, {"role": "user", "content": + * "What's my name?"}, ], "answer": "John Doe" } + */ + purpose: 'post-training/messages' | 'eval/question-answer' | 'eval/messages-answer'; + + /** + * The data source of the dataset. Ensure that the data source schema is compatible + * with the purpose of the dataset. Examples: - { "type": "uri", "uri": + * "https://mywebsite.com/mydata.jsonl" } - { "type": "uri", "uri": + * "lsfs://mydata.jsonl" } - { "type": "uri", "uri": + * "data:csv;base64,{base64_content}" } - { "type": "uri", "uri": + * "huggingface://llamastack/simpleqa?split=train" } - { "type": "rows", "rows": [ + * { "messages": [ {"role": "user", "content": "Hello, world!"}, {"role": + * "assistant", "content": "Hello, world!"}, ] } ] } + */ + source: DatasetRegisterParams.UriDataSource | DatasetRegisterParams.RowsDataSource; + + /** + * The ID of the dataset. If not provided, an ID will be generated. + */ + dataset_id?: string; + + /** + * The metadata for the dataset. - E.g. {"description": "My dataset"} + */ + metadata?: Record | unknown | null>; } export namespace DatasetRegisterParams { - export interface URL { + /** + * A dataset that can be obtained from a URI. + */ + export interface UriDataSource { + type: 'uri'; + + /** + * The dataset can be obtained from a URI. E.g. - + * "https://mywebsite.com/mydata.jsonl" - "lsfs://mydata.jsonl" - + * "data:csv;base64,{base64_content}" + */ uri: string; } + + /** + * A dataset stored in rows. + */ + export interface RowsDataSource { + /** + * The dataset is stored in rows. E.g. - [ {"messages": [{"role": "user", + * "content": "Hello, world!"}, {"role": "assistant", "content": "Hello, world!"}]} + * ] + */ + rows: Array | unknown | null>>; + + type: 'rows'; + } } export declare namespace Datasets { @@ -111,6 +319,9 @@ export declare namespace Datasets { type ListDatasetsResponse as ListDatasetsResponse, type DatasetRetrieveResponse as DatasetRetrieveResponse, type DatasetListResponse as DatasetListResponse, + type DatasetIterrowsResponse as DatasetIterrowsResponse, + type DatasetRegisterResponse as DatasetRegisterResponse, + type DatasetIterrowsParams as DatasetIterrowsParams, type DatasetRegisterParams as DatasetRegisterParams, }; } diff --git a/src/resources/eval/eval.ts b/src/resources/eval/eval.ts index 9f59aa2..f585861 100644 --- a/src/resources/eval/eval.ts +++ b/src/resources/eval/eval.ts @@ -5,7 +5,7 @@ import * as Core from '../../core'; import * as ScoringFunctionsAPI from '../scoring-functions'; import * as Shared from '../shared'; import * as JobsAPI from './jobs'; -import { JobStatusResponse, Jobs } from './jobs'; +import { Jobs } from './jobs'; export class Eval extends APIResource { jobs: JobsAPI.Jobs = new JobsAPI.Jobs(this._client); @@ -131,6 +131,8 @@ export interface EvaluateResponse { export interface Job { job_id: string; + + status: 'completed' | 'in_progress' | 'failed' | 'scheduled'; } export interface EvalEvaluateRowsParams { @@ -195,5 +197,5 @@ export declare namespace Eval { type EvalRunEvalAlphaParams as EvalRunEvalAlphaParams, }; - export { Jobs as Jobs, type JobStatusResponse as JobStatusResponse }; + export { Jobs as Jobs }; } diff --git a/src/resources/eval/index.ts b/src/resources/eval/index.ts index 3b5e507..e8c35f3 100644 --- a/src/resources/eval/index.ts +++ b/src/resources/eval/index.ts @@ -11,4 +11,4 @@ export { type EvalRunEvalParams, type EvalRunEvalAlphaParams, } from './eval'; -export { Jobs, type JobStatusResponse } from './jobs'; +export { Jobs } from './jobs'; diff --git a/src/resources/eval/jobs.ts b/src/resources/eval/jobs.ts index ac03e30..13d4a4d 100644 --- a/src/resources/eval/jobs.ts +++ b/src/resources/eval/jobs.ts @@ -29,17 +29,7 @@ export class Jobs extends APIResource { /** * Get the status of a job. */ - status( - benchmarkId: string, - jobId: string, - options?: Core.RequestOptions, - ): Core.APIPromise { + status(benchmarkId: string, jobId: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/eval/benchmarks/${benchmarkId}/jobs/${jobId}`, options); } } - -export type JobStatusResponse = 'completed' | 'in_progress' | 'failed' | 'scheduled' | null; - -export declare namespace Jobs { - export { type JobStatusResponse as JobStatusResponse }; -} diff --git a/src/resources/index.ts b/src/resources/index.ts index c8b7b30..7786d12 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -24,17 +24,14 @@ export { type BenchmarkListResponse, type BenchmarkRegisterParams, } from './benchmarks'; -export { - Datasetio, - type PaginatedRowsResult, - type DatasetioAppendRowsParams, - type DatasetioGetRowsPaginatedParams, -} from './datasetio'; export { Datasets, type ListDatasetsResponse, type DatasetRetrieveResponse, type DatasetListResponse, + type DatasetIterrowsResponse, + type DatasetRegisterResponse, + type DatasetIterrowsParams, type DatasetRegisterParams, } from './datasets'; export { diff --git a/src/resources/models.ts b/src/resources/models.ts index 2c561fe..1f60531 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -4,7 +4,7 @@ import { APIResource } from '../resource'; import * as Core from '../core'; export class Models extends APIResource { - retrieve(modelId: string, options?: Core.RequestOptions): Core.APIPromise { + retrieve(modelId: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/models/${modelId}`, options); } diff --git a/src/resources/post-training/job.ts b/src/resources/post-training/job.ts index 8469da7..a7f8706 100644 --- a/src/resources/post-training/job.ts +++ b/src/resources/post-training/job.ts @@ -16,10 +16,7 @@ export class Job extends APIResource { )._thenUnwrap((obj) => obj.data); } - artifacts( - query: JobArtifactsParams, - options?: Core.RequestOptions, - ): Core.APIPromise { + artifacts(query: JobArtifactsParams, options?: Core.RequestOptions): Core.APIPromise { return this._client.get('/v1/post-training/job/artifacts', { query, ...options }); } @@ -31,7 +28,7 @@ export class Job extends APIResource { }); } - status(query: JobStatusParams, options?: Core.RequestOptions): Core.APIPromise { + status(query: JobStatusParams, options?: Core.RequestOptions): Core.APIPromise { return this._client.get('/v1/post-training/job/status', { query, ...options }); } } diff --git a/src/resources/scoring-functions.ts b/src/resources/scoring-functions.ts index 83d6e9d..23ee929 100644 --- a/src/resources/scoring-functions.ts +++ b/src/resources/scoring-functions.ts @@ -5,7 +5,7 @@ import * as Core from '../core'; import * as Shared from './shared'; export class ScoringFunctions extends APIResource { - retrieve(scoringFnId: string, options?: Core.RequestOptions): Core.APIPromise { + retrieve(scoringFnId: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/scoring-functions/${scoringFnId}`, options); } @@ -59,7 +59,9 @@ export namespace ScoringFnParams { type: 'llm_as_judge'; - aggregation_functions?: Array<'average' | 'median' | 'categorical_count' | 'accuracy'>; + aggregation_functions?: Array< + 'average' | 'weighted_average' | 'median' | 'categorical_count' | 'accuracy' + >; judge_score_regexes?: Array; @@ -69,7 +71,9 @@ export namespace ScoringFnParams { export interface RegexParserScoringFnParams { type: 'regex_parser'; - aggregation_functions?: Array<'average' | 'median' | 'categorical_count' | 'accuracy'>; + aggregation_functions?: Array< + 'average' | 'weighted_average' | 'median' | 'categorical_count' | 'accuracy' + >; parsing_regexes?: Array; } @@ -77,7 +81,9 @@ export namespace ScoringFnParams { export interface BasicScoringFnParams { type: 'basic'; - aggregation_functions?: Array<'average' | 'median' | 'categorical_count' | 'accuracy'>; + aggregation_functions?: Array< + 'average' | 'weighted_average' | 'median' | 'categorical_count' | 'accuracy' + >; } } diff --git a/src/resources/shared.ts b/src/resources/shared.ts index 0e17703..c18377e 100644 --- a/src/resources/shared.ts +++ b/src/resources/shared.ts @@ -170,9 +170,12 @@ export namespace ContentDelta { } } +/** + * A document to be used for document ingestion in the RAG Tool. + */ export interface Document { /** - * A image content item + * The content of the document. */ content: | string @@ -181,10 +184,19 @@ export interface Document { | Array | Document.URL; + /** + * The unique identifier for the document. + */ document_id: string; + /** + * Additional metadata for the document. + */ metadata: Record | unknown | null>; + /** + * The MIME type of the document. + */ mime_type?: string; } @@ -608,19 +620,23 @@ export interface SystemMessage { } export interface ToolCall { - arguments: Record< - string, + arguments: | string - | number - | boolean - | Array - | Record - | null - >; + | Record< + string, + | string + | number + | boolean + | Array + | Record + | null + >; call_id: string; tool_name: 'brave_search' | 'wolfram_alpha' | 'photogen' | 'code_interpreter' | (string & {}); + + arguments_json?: string; } export type ToolCallOrString = string | ToolCall; diff --git a/src/resources/shields.ts b/src/resources/shields.ts index 4e75b22..302fde1 100644 --- a/src/resources/shields.ts +++ b/src/resources/shields.ts @@ -4,7 +4,7 @@ import { APIResource } from '../resource'; import * as Core from '../core'; export class Shields extends APIResource { - retrieve(identifier: string, options?: Core.RequestOptions): Core.APIPromise { + retrieve(identifier: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/shields/${identifier}`, options); } diff --git a/src/resources/tool-runtime/tool-runtime.ts b/src/resources/tool-runtime/tool-runtime.ts index bdba648..d65a50f 100644 --- a/src/resources/tool-runtime/tool-runtime.ts +++ b/src/resources/tool-runtime/tool-runtime.ts @@ -72,7 +72,7 @@ export interface ToolInvocationResult { /** * A image content item */ - content: Shared.InterleavedContent; + content?: Shared.InterleavedContent; error_code?: number; diff --git a/src/resources/vector-dbs.ts b/src/resources/vector-dbs.ts index 37b60c1..ffb176d 100644 --- a/src/resources/vector-dbs.ts +++ b/src/resources/vector-dbs.ts @@ -4,10 +4,7 @@ import { APIResource } from '../resource'; import * as Core from '../core'; export class VectorDBs extends APIResource { - retrieve( - vectorDBId: string, - options?: Core.RequestOptions, - ): Core.APIPromise { + retrieve(vectorDBId: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.get(`/v1/vector-dbs/${vectorDBId}`, options); } diff --git a/tests/api-resources/datasetio.test.ts b/tests/api-resources/datasetio.test.ts deleted file mode 100644 index be79942..0000000 --- a/tests/api-resources/datasetio.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import LlamaStackClient from 'llama-stack-client'; -import { Response } from 'node-fetch'; - -const client = new LlamaStackClient({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' }); - -describe('resource datasetio', () => { - test('appendRows: only required params', async () => { - const responsePromise = client.datasetio.appendRows({ dataset_id: 'dataset_id', rows: [{ foo: true }] }); - const rawResponse = await responsePromise.asResponse(); - expect(rawResponse).toBeInstanceOf(Response); - const response = await responsePromise; - expect(response).not.toBeInstanceOf(Response); - const dataAndResponse = await responsePromise.withResponse(); - expect(dataAndResponse.data).toBe(response); - expect(dataAndResponse.response).toBe(rawResponse); - }); - - test('appendRows: required and optional params', async () => { - const response = await client.datasetio.appendRows({ dataset_id: 'dataset_id', rows: [{ foo: true }] }); - }); - - test('getRowsPaginated: only required params', async () => { - const responsePromise = client.datasetio.getRowsPaginated({ dataset_id: 'dataset_id', rows_in_page: 0 }); - const rawResponse = await responsePromise.asResponse(); - expect(rawResponse).toBeInstanceOf(Response); - const response = await responsePromise; - expect(response).not.toBeInstanceOf(Response); - const dataAndResponse = await responsePromise.withResponse(); - expect(dataAndResponse.data).toBe(response); - expect(dataAndResponse.response).toBe(rawResponse); - }); - - test('getRowsPaginated: required and optional params', async () => { - const response = await client.datasetio.getRowsPaginated({ - dataset_id: 'dataset_id', - rows_in_page: 0, - filter_condition: 'filter_condition', - page_token: 'page_token', - }); - }); -}); diff --git a/tests/api-resources/datasets.test.ts b/tests/api-resources/datasets.test.ts index 7424b93..d638df6 100644 --- a/tests/api-resources/datasets.test.ts +++ b/tests/api-resources/datasets.test.ts @@ -42,11 +42,39 @@ describe('resource datasets', () => { ); }); + test('iterrows', async () => { + const responsePromise = client.datasets.iterrows('dataset_id'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('iterrows: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.datasets.iterrows('dataset_id', { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(LlamaStackClient.NotFoundError); + }); + + test('iterrows: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.datasets.iterrows( + 'dataset_id', + { limit: 0, start_index: 0 }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(LlamaStackClient.NotFoundError); + }); + test('register: only required params', async () => { const responsePromise = client.datasets.register({ - dataset_id: 'dataset_id', - dataset_schema: { foo: { type: 'string' } }, - url: { uri: 'uri' }, + purpose: 'post-training/messages', + source: { type: 'uri', uri: 'uri' }, }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -59,12 +87,10 @@ describe('resource datasets', () => { test('register: required and optional params', async () => { const response = await client.datasets.register({ + purpose: 'post-training/messages', + source: { type: 'uri', uri: 'uri' }, dataset_id: 'dataset_id', - dataset_schema: { foo: { type: 'string' } }, - url: { uri: 'uri' }, metadata: { foo: true }, - provider_dataset_id: 'provider_dataset_id', - provider_id: 'provider_id', }); });