Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0"
".": "0.2.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 33
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-4ed32c3243ce7a772e55bb1ba204736fc3fb1d712d8ca0eb91bac0c7ac626938.yml
configured_endpoints: 35
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-d79ccb778953ad5c2ae4b99115429c8b3f68b3b23d9b6d90b1b40393f11a4383.yml
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 0.2.0 (2025-02-08)

Full Changelog: [v0.1.0...v0.2.0](https://github.com/ContextualAI/contextual-client-node/compare/v0.1.0...v0.2.0)

### Features

* **api:** update via SDK Studio ([#15](https://github.com/ContextualAI/contextual-client-node/issues/15)) ([6aaf723](https://github.com/ContextualAI/contextual-client-node/commit/6aaf723c236fa90c113f89e3c455c071fdf311e4))
* **api:** update via SDK Studio ([#16](https://github.com/ContextualAI/contextual-client-node/issues/16)) ([0cfb143](https://github.com/ContextualAI/contextual-client-node/commit/0cfb143e6a706365c1ea6d21404e1d3dfdca87eb))
* **api:** update via SDK Studio ([#18](https://github.com/ContextualAI/contextual-client-node/issues/18)) ([54f5551](https://github.com/ContextualAI/contextual-client-node/commit/54f55516820f04498db0f45997539d9fa142f589))
* **client:** send `X-Stainless-Timeout` header ([#17](https://github.com/ContextualAI/contextual-client-node/issues/17)) ([6cb5614](https://github.com/ContextualAI/contextual-client-node/commit/6cb56149556ce93fae414e40e23114229929f8ed))


### Chores

* **internal:** codegen related update ([#11](https://github.com/ContextualAI/contextual-client-node/issues/11)) ([30253b7](https://github.com/ContextualAI/contextual-client-node/commit/30253b751d480a41574804fa080a02449c37936a))
* **internal:** codegen related update ([#13](https://github.com/ContextualAI/contextual-client-node/issues/13)) ([69a063a](https://github.com/ContextualAI/contextual-client-node/commit/69a063afb19f3739fc877ddbc90bf3c8da826d48))
* **internal:** codegen related update ([#14](https://github.com/ContextualAI/contextual-client-node/issues/14)) ([ed84da5](https://github.com/ContextualAI/contextual-client-node/commit/ed84da5bd3a9085f5d9bed012112d8ef386a9f64))

## 0.1.0 (2025-01-15)

Full Changelog: [v0.1.0-alpha.2...v0.1.0](https://github.com/ContextualAI/contextual-client-node/compare/v0.1.0-alpha.2...v0.1.0)
Expand Down
20 changes: 20 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,23 @@ Types:
Methods:

- <code title="post /lmunit">client.lmUnit.<a href="./src/resources/lmunit.ts">create</a>({ ...params }) -> LMUnitCreateResponse</code>

# Rerank

Types:

- <code><a href="./src/resources/rerank.ts">RerankCreateResponse</a></code>

Methods:

- <code title="post /rerank">client.rerank.<a href="./src/resources/rerank.ts">create</a>({ ...params }) -> RerankCreateResponse</code>

# Generate

Types:

- <code><a href="./src/resources/generate.ts">GenerateCreateResponse</a></code>

Methods:

- <code title="post /generate">client.generate.<a href="./src/resources/generate.ts">create</a>({ ...params }) -> GenerateCreateResponse</code>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contextual-client",
"version": "0.1.0",
"version": "0.2.0",
"description": "The official TypeScript library for the Contextual AI API",
"author": "Contextual AI <support@contextual.ai>",
"types": "dist/index.d.ts",
Expand Down
20 changes: 14 additions & 6 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export abstract class APIClient {
options: FinalRequestOptions<Req>,
{ retryCount = 0 }: { retryCount?: number } = {},
): { req: RequestInit; url: string; timeout: number } {
options = { ...options };
const { method, path, query, headers: headers = {} } = options;

const body =
Expand All @@ -292,9 +293,9 @@ export abstract class APIClient {

const url = this.buildURL(path!, query);
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
const timeout = options.timeout ?? this.timeout;
options.timeout = options.timeout ?? this.timeout;
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
const minAgentTimeout = timeout + 1000;
const minAgentTimeout = options.timeout + 1000;
if (
typeof (httpAgent as any)?.options?.timeout === 'number' &&
minAgentTimeout > ((httpAgent as any).options.timeout ?? 0)
Expand Down Expand Up @@ -323,7 +324,7 @@ export abstract class APIClient {
signal: options.signal ?? null,
};

return { req, url, timeout };
return { req, url, timeout: options.timeout };
}

private buildHeaders({
Expand Down Expand Up @@ -351,15 +352,22 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
// Don't set theses headers if they were already set or removed through default headers or by the caller.
// We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
// for the removal case.
if (
getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
getHeader(headers, 'x-stainless-retry-count') === undefined
) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}
if (
getHeader(defaultHeaders, 'x-stainless-timeout') === undefined &&
getHeader(headers, 'x-stainless-timeout') === undefined &&
options.timeout
) {
reqHeaders['x-stainless-timeout'] = String(options.timeout);
}

this.validateHeaders(reqHeaders, headers);

Expand Down
28 changes: 23 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
} from './pagination';
import * as Uploads from './uploads';
import * as API from './resources/index';
import { Generate, GenerateCreateParams, GenerateCreateResponse } from './resources/generate';
import { LMUnit, LMUnitCreateParams, LMUnitCreateResponse } from './resources/lmunit';
import { Rerank, RerankCreateParams, RerankCreateResponse } from './resources/rerank';
import {
Agent as AgentsAPIAgent,
AgentCreateParams,
Expand Down Expand Up @@ -61,15 +63,15 @@ export interface ClientOptions {
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
* much longer than this timeout before the promise succeeds or fails.
*/
timeout?: number;
timeout?: number | undefined;

/**
* An HTTP agent used to manage HTTP(S) connections.
*
* If not provided, an agent will be constructed by default in the Node.js environment,
* otherwise no agent is used.
*/
httpAgent?: Agent;
httpAgent?: Agent | undefined;

/**
* Specify a custom `fetch` function implementation.
Expand All @@ -85,23 +87,23 @@ export interface ClientOptions {
*
* @default 2
*/
maxRetries?: number;
maxRetries?: number | undefined;

/**
* Default headers to include with every request to the API.
*
* These can be removed in individual requests by explicitly setting the
* header to `undefined` or `null` in request options.
*/
defaultHeaders?: Core.Headers;
defaultHeaders?: Core.Headers | undefined;

/**
* Default query parameters to include with every request to the API.
*
* These can be removed in individual requests by explicitly setting the
* param to `undefined` in request options.
*/
defaultQuery?: Core.DefaultQuery;
defaultQuery?: Core.DefaultQuery | undefined;
}

/**
Expand Down Expand Up @@ -157,6 +159,8 @@ export class ContextualAI extends Core.APIClient {
datastores: API.Datastores = new API.Datastores(this);
agents: API.Agents = new API.Agents(this);
lmUnit: API.LMUnit = new API.LMUnit(this);
rerank: API.Rerank = new API.Rerank(this);
generate: API.Generate = new API.Generate(this);

protected override defaultQuery(): Core.DefaultQuery | undefined {
return this._options.defaultQuery;
Expand Down Expand Up @@ -203,6 +207,8 @@ ContextualAI.DatastoresDatastoresPage = DatastoresDatastoresPage;
ContextualAI.Agents = Agents;
ContextualAI.AgentsPage = AgentsPage;
ContextualAI.LMUnit = LMUnit;
ContextualAI.Rerank = Rerank;
ContextualAI.Generate = Generate;
export declare namespace ContextualAI {
export type RequestOptions = Core.RequestOptions;

Expand Down Expand Up @@ -252,6 +258,18 @@ export declare namespace ContextualAI {
type LMUnitCreateResponse as LMUnitCreateResponse,
type LMUnitCreateParams as LMUnitCreateParams,
};

export {
Rerank as Rerank,
type RerankCreateResponse as RerankCreateResponse,
type RerankCreateParams as RerankCreateParams,
};

export {
Generate as Generate,
type GenerateCreateResponse as GenerateCreateResponse,
type GenerateCreateParams as GenerateCreateParams,
};
}

export { toFile, fileFromPath } from './uploads';
Expand Down
6 changes: 3 additions & 3 deletions src/resources/agents/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export interface AgentMetadata {
* These queries will show up as suggestions in the Contextual UI when users load
* the agent. We recommend including common queries that users will ask, as well as
* complex queries so users understand the types of complex queries the system can
* handle.
* handle. The max length of all the suggested queries is 1000.
*/
suggested_queries?: Array<string>;

Expand Down Expand Up @@ -209,7 +209,7 @@ export interface AgentCreateParams {
* These queries will show up as suggestions in the Contextual UI when users load
* the agent. We recommend including common queries that users will ask, as well as
* complex queries so users understand the types of complex queries the system can
* handle.
* handle. The max length of all the suggested queries is 1000.
*/
suggested_queries?: Array<string>;

Expand Down Expand Up @@ -237,7 +237,7 @@ export interface AgentUpdateParams {
* These queries will show up as suggestions in the Contextual UI when users load
* the agent. We recommend including common queries that users will ask, as well as
* complex queries so users understand the types of complex queries the system can
* handle.
* handle. The max length of all the suggested queries is 1000.
*/
suggested_queries?: Array<string>;

Expand Down
24 changes: 12 additions & 12 deletions src/resources/agents/datasets/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { type Response } from '../../../_shims/index';
export class Evaluate extends APIResource {
/**
* Create a new evaluation `Dataset` for the specified `Agent` using the provided
* JSONL file. A `Dataset` is a versioned collection of samples conforming to a
* particular schema, and can be used to store `Evaluation` test-sets and retrieve
* `Evaluation` results.
* JSONL or CSV file. A `Dataset` is a versioned collection of samples conforming
* to a particular schema, and can be used to store `Evaluation` test-sets and
* retrieve `Evaluation` results.
*
* Each `Dataset` is versioned and validated against its schema during creation and
* subsequent updates. The provided `Dataset` file must conform to the schema
* defined for the `dataset_type`.
*
* File schema for `dataset_type` `evaluation_set` is a JSONL or CSV file where
* each line is one JSON object with the following required keys:
* File schema for `dataset_type` `evaluation_set` is a CSV file or a JSONL file
* where each line is one JSON object. The following keys are required:
*
* - `prompt` (required, `string`): Prompt or question
* - `prompt` (`string`): Prompt or question
*
* - `reference` (required, `string`): Required reference or ground truth response
* - `reference` (`string`): Reference or ground truth response
*/
create(
agentId: string,
Expand Down Expand Up @@ -80,12 +80,12 @@ export class Evaluate extends APIResource {
* Create a new version of the dataset by appending content to the `Dataset` and
* validating against its schema.
*
* File schema for `dataset_type` `evaluation_set` is a JSONL file where each line
* is one JSON object with the following required keys:
* File schema for `dataset_type` `evaluation_set` is a CSV file or a JSONL file
* where each line is one JSON object. The following keys are required:
*
* - `prompt` (`string`): Prompt or question
*
* - `reference` (`string`): Required reference or ground truth response
* - `reference` (`string`): Reference or ground truth response
*/
update(
agentId: string,
Expand Down Expand Up @@ -184,7 +184,7 @@ export interface EvaluateCreateParams {
dataset_type: 'evaluation_set';

/**
* JSONL file containing the evaluation dataset
* JSONL or CSV file containing the evaluation dataset
*/
file: Core.Uploadable;
}
Expand All @@ -210,7 +210,7 @@ export interface EvaluateUpdateParams {
dataset_type: 'evaluation_set';

/**
* JSONL file containing the entries to append to the evaluation dataset
* JSONL or CSV file containing the entries to append to the evaluation dataset
*/
file: Core.Uploadable;
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/agents/evaluate/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface EvaluateCreateParams {
/**
* ID of the model to evaluate. Uses the default model if not specified.
*/
llm_model_id?: string | null;
llm_model_id?: string;
}

Evaluate.Jobs = Jobs;
Expand Down
30 changes: 30 additions & 0 deletions src/resources/agents/evaluate/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,36 @@ export namespace ListEvaluationJobsResponse {
* Email of the user who launched the evaluation round
*/
user_email: string;

/**
* Timestamp indicating when the evaluation round finished processing
*/
finished_at?: string;

/**
* Number of predictions that failed during the evaluation round
*/
num_failed_predictions?: number;

/**
* Total number of predictions made during the evaluation round
*/
num_predictions?: number;

/**
* Number of predictions that were successful during the evaluation round
*/
num_successful_predictions?: number;

/**
* Timestamp indicating when the evaluation round started processing
*/
processing_started_at?: string;

/**
* Score of the evaluation round
*/
summary_results?: unknown;
}
}

Expand Down
Loading