From 30253b751d480a41574804fa080a02449c37936a Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Fri, 17 Jan 2025 05:46:52 +0000
Subject: [PATCH 1/8] chore(internal): codegen related update (#11)
---
src/index.ts | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/index.ts b/src/index.ts
index 75e8799..242d2aa 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -61,7 +61,7 @@ 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.
@@ -69,7 +69,7 @@ export interface ClientOptions {
* 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.
@@ -85,7 +85,7 @@ export interface ClientOptions {
*
* @default 2
*/
- maxRetries?: number;
+ maxRetries?: number | undefined;
/**
* Default headers to include with every request to the API.
@@ -93,7 +93,7 @@ export interface ClientOptions {
* 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.
@@ -101,7 +101,7 @@ export interface ClientOptions {
* These can be removed in individual requests by explicitly setting the
* param to `undefined` in request options.
*/
- defaultQuery?: Core.DefaultQuery;
+ defaultQuery?: Core.DefaultQuery | undefined;
}
/**
From 69a063afb19f3739fc877ddbc90bf3c8da826d48 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Tue, 21 Jan 2025 12:04:45 +0000
Subject: [PATCH 2/8] chore(internal): codegen related update (#13)
---
tests/index.test.ts | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tests/index.test.ts b/tests/index.test.ts
index 788a4c6..90855ce 100644
--- a/tests/index.test.ts
+++ b/tests/index.test.ts
@@ -96,6 +96,15 @@ describe('instantiate client', () => {
expect(response).toEqual({ url: 'http://localhost:5000/foo', custom: true });
});
+ test('explicit global fetch', async () => {
+ // make sure the global fetch type is assignable to our Fetch type
+ const client = new ContextualAI({
+ baseURL: 'http://localhost:5000/',
+ apiKey: 'My API Key',
+ fetch: defaultFetch,
+ });
+ });
+
test('custom signal', async () => {
const client = new ContextualAI({
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
From ed84da5bd3a9085f5d9bed012112d8ef386a9f64 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Tue, 28 Jan 2025 13:08:41 +0000
Subject: [PATCH 3/8] chore(internal): codegen related update (#14)
---
tests/api-resources/agents/query.test.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/api-resources/agents/query.test.ts b/tests/api-resources/agents/query.test.ts
index 638f493..b771106 100644
--- a/tests/api-resources/agents/query.test.ts
+++ b/tests/api-resources/agents/query.test.ts
@@ -83,7 +83,7 @@ describe('resource query', () => {
{
created_after: '2019-12-27T18:11:19.117Z',
created_before: '2019-12-27T18:11:19.117Z',
- limit: 0,
+ limit: 1000,
offset: 0,
},
{ path: '/_stainless_unknown_path' },
From 6aaf723c236fa90c113f89e3c455c071fdf311e4 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Thu, 30 Jan 2025 22:39:04 +0000
Subject: [PATCH 4/8] feat(api): update via SDK Studio (#15)
---
.stats.yml | 4 +-
api.md | 20 ++++++
src/index.ts | 18 +++++
src/resources/agents/datasets/evaluate.ts | 24 +++----
src/resources/agents/evaluate/evaluate.ts | 2 +-
src/resources/agents/query.ts | 7 +-
src/resources/agents/tune/tune.ts | 12 ++--
src/resources/generate.ts | 86 +++++++++++++++++++++++
src/resources/index.ts | 2 +
src/resources/rerank.ts | 75 ++++++++++++++++++++
tests/api-resources/generate.test.ts | 34 +++++++++
tests/api-resources/rerank.test.ts | 31 ++++++++
12 files changed, 291 insertions(+), 24 deletions(-)
create mode 100644 src/resources/generate.ts
create mode 100644 src/resources/rerank.ts
create mode 100644 tests/api-resources/generate.test.ts
create mode 100644 tests/api-resources/rerank.test.ts
diff --git a/.stats.yml b/.stats.yml
index f83abfd..39a1051 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -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-c0b9cfd71efb976777313fb342d2e31ebeb44b1b3f9bb7ddea971e6b2bc5fd19.yml
diff --git a/api.md b/api.md
index b4ce066..1721b50 100644
--- a/api.md
+++ b/api.md
@@ -156,3 +156,23 @@ Types:
Methods:
- client.lmUnit.create({ ...params }) -> LMUnitCreateResponse
+
+# Rerank
+
+Types:
+
+- RerankCreateResponse
+
+Methods:
+
+- client.rerank.create({ ...params }) -> RerankCreateResponse
+
+# Generate
+
+Types:
+
+- GenerateCreateResponse
+
+Methods:
+
+- client.generate.create({ ...params }) -> GenerateCreateResponse
diff --git a/src/index.ts b/src/index.ts
index 242d2aa..12c6113 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -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,
@@ -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;
@@ -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;
@@ -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';
diff --git a/src/resources/agents/datasets/evaluate.ts b/src/resources/agents/datasets/evaluate.ts
index c413027..511ce10 100644
--- a/src/resources/agents/datasets/evaluate.ts
+++ b/src/resources/agents/datasets/evaluate.ts
@@ -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,
@@ -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,
@@ -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;
}
@@ -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;
}
diff --git a/src/resources/agents/evaluate/evaluate.ts b/src/resources/agents/evaluate/evaluate.ts
index 2c0bfb3..efb2917 100644
--- a/src/resources/agents/evaluate/evaluate.ts
+++ b/src/resources/agents/evaluate/evaluate.ts
@@ -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;
diff --git a/src/resources/agents/query.ts b/src/resources/agents/query.ts
index 07bfc88..0aa82f7 100644
--- a/src/resources/agents/query.ts
+++ b/src/resources/agents/query.ts
@@ -190,7 +190,7 @@ export namespace QueryResponse {
content: string;
/**
- * Role of sender
+ * Role of the sender
*/
role: 'user' | 'system' | 'assistant';
}
@@ -301,7 +301,8 @@ export interface QueryCreateParams {
export namespace QueryCreateParams {
/**
- * Message object for a message sent or received in a /query conversation
+ * Message object for a message sent or received in a /query and /generate
+ * conversation
*/
export interface Message {
/**
@@ -310,7 +311,7 @@ export namespace QueryCreateParams {
content: string;
/**
- * Role of sender
+ * Role of the sender
*/
role: 'user' | 'system' | 'assistant';
}
diff --git a/src/resources/agents/tune/tune.ts b/src/resources/agents/tune/tune.ts
index e2e5fc6..998b74a 100644
--- a/src/resources/agents/tune/tune.ts
+++ b/src/resources/agents/tune/tune.ts
@@ -57,21 +57,21 @@ export interface TuneCreateParams {
* JSON object represents a single training example. The four required fields are
* `guideline`, `prompt`, `reference`, and `knowledge`.
*
- * - `knowledge` (`list[str]`): Knowledge or retrievals used to generate the
- * reference response, as a list of string text chunks
+ * - `knowledge` (`list[str]`): Retrieved knowledge used to generate the reference
+ * answer. `knowledge` is a list of retrieved text chunks.
*
- * - `reference` field should be the model's response to the prompt.
+ * - `reference` (`str`): The gold-standard answer to the prompt.
*
- * - `guideline` (`str): Guidelines or criteria for model output
+ * - `guideline` (`str`): Guidelines for model output.
*
- * - `prompt` (required, `string`): Prompt or question model should respond to.
+ * - `prompt` (`str`): Question for the model to respond to.
*
* Example:
*
* ```json
* [
* {
- * "guideline": "The response should be accurate.",
+ * "guideline": "The answer should be accurate.",
* "prompt": "What was last quarter's revenue?",
* "reference": "According to recent reports, the Q3 revenue was $1.2 million, a 0.1 million increase from Q2.",
* "knowledge": [
diff --git a/src/resources/generate.ts b/src/resources/generate.ts
new file mode 100644
index 0000000..cb4f5db
--- /dev/null
+++ b/src/resources/generate.ts
@@ -0,0 +1,86 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../resource';
+import * as Core from '../core';
+
+export class Generate extends APIResource {
+ /**
+ * Generate a response using Contextual's Grounded Language Model (GLM), an LLM
+ * engineered specifically to prioritize faithfulness to in-context retrievals over
+ * parametric knowledge to reduce hallucinations in Retrieval-Augmented Generation.
+ *
+ * The total request cannot exceed 6,100 tokens.
+ */
+ create(body: GenerateCreateParams, options?: Core.RequestOptions): Core.APIPromise {
+ return this._client.post('/generate', { body, ...options });
+ }
+}
+
+/**
+ * /generate result object.
+ */
+export interface GenerateCreateResponse {
+ /**
+ * The model's response to the last user message.
+ */
+ response: string;
+}
+
+export interface GenerateCreateParams {
+ /**
+ * Extra parameters to be passed to Contextual's GLM
+ */
+ extra_body: GenerateCreateParams.ExtraBody;
+
+ /**
+ * List of messages in the conversation so far. The last message must be from the
+ * user.
+ */
+ messages: Array;
+
+ /**
+ * The version of the Contextual's GLM to use. Currently, we just have "v1".
+ */
+ model: string;
+}
+
+export namespace GenerateCreateParams {
+ /**
+ * Extra parameters to be passed to Contextual's GLM
+ */
+ export interface ExtraBody {
+ /**
+ * The knowledge sources the model can use when generating a response.
+ */
+ knowledge: Array;
+
+ /**
+ * Instructions that the model follows when generating responses. Note that we do
+ * not guarantee that the model follows these instructions exactly.
+ */
+ system_prompt?: string;
+ }
+
+ /**
+ * Message object for a message sent or received in a /query and /generate
+ * conversation
+ */
+ export interface Message {
+ /**
+ * Content of the message
+ */
+ content: string;
+
+ /**
+ * Role of the sender
+ */
+ role: 'user' | 'system' | 'assistant';
+ }
+}
+
+export declare namespace Generate {
+ export {
+ type GenerateCreateResponse as GenerateCreateResponse,
+ type GenerateCreateParams as GenerateCreateParams,
+ };
+}
diff --git a/src/resources/index.ts b/src/resources/index.ts
index 0ccc44b..2036b1b 100644
--- a/src/resources/index.ts
+++ b/src/resources/index.ts
@@ -24,4 +24,6 @@ export {
type DatastoreCreateParams,
type DatastoreListParams,
} from './datastores/datastores';
+export { Generate, type GenerateCreateResponse, type GenerateCreateParams } from './generate';
export { LMUnit, type LMUnitCreateResponse, type LMUnitCreateParams } from './lmunit';
+export { Rerank, type RerankCreateResponse, type RerankCreateParams } from './rerank';
diff --git a/src/resources/rerank.ts b/src/resources/rerank.ts
new file mode 100644
index 0000000..c4b8bed
--- /dev/null
+++ b/src/resources/rerank.ts
@@ -0,0 +1,75 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../resource';
+import * as Core from '../core';
+
+export class Rerank extends APIResource {
+ /**
+ * Rank a list of documents according to their relevance to a query.
+ *
+ * The total request cannot exceed 400,000 tokens. The combined length of any
+ * document and the query must not exceed 4,000 tokens.
+ */
+ create(body: RerankCreateParams, options?: Core.RequestOptions): Core.APIPromise {
+ return this._client.post('/rerank', { body, ...options });
+ }
+}
+
+/**
+ * Rerank output response.
+ */
+export interface RerankCreateResponse {
+ /**
+ * The ranked list of documents containing the index of the document and the
+ * relevance score, sorted by relevance score.
+ */
+ results: Array;
+}
+
+export namespace RerankCreateResponse {
+ /**
+ * Reranked result object.
+ */
+ export interface Result {
+ /**
+ * Index of the document in the input list, starting with 0
+ */
+ index: number;
+
+ /**
+ * Relevance scores assess how likely a document is to have information that is
+ * helpful to answer the query. Our model outputs the scores in a wide range, and
+ * we normalize scores to a 0-1 scale and truncate the response to 8 decimal
+ * places. Our reranker is designed for RAG, so its purpose is to check whether a
+ * document has information that is helpful to answer the query. A reranker that is
+ * designed for direct Q&A (Question & Answer) would behave differently.
+ */
+ relevance_score: number;
+ }
+}
+
+export interface RerankCreateParams {
+ /**
+ * The texts to be reranked according to their relevance to the query
+ */
+ documents: Array;
+
+ /**
+ * The version of the reranker to use. Currently, we just have "v1".
+ */
+ model: string;
+
+ /**
+ * The string against which documents will be ranked for relevance
+ */
+ query: string;
+
+ /**
+ * The number of top-ranked results to return
+ */
+ top_n?: number;
+}
+
+export declare namespace Rerank {
+ export { type RerankCreateResponse as RerankCreateResponse, type RerankCreateParams as RerankCreateParams };
+}
diff --git a/tests/api-resources/generate.test.ts b/tests/api-resources/generate.test.ts
new file mode 100644
index 0000000..4e89314
--- /dev/null
+++ b/tests/api-resources/generate.test.ts
@@ -0,0 +1,34 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import ContextualAI from 'contextual-client';
+import { Response } from 'node-fetch';
+
+const client = new ContextualAI({
+ apiKey: 'My API Key',
+ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource generate', () => {
+ test('create: only required params', async () => {
+ const responsePromise = client.generate.create({
+ extra_body: { knowledge: ['string'] },
+ messages: [{ content: 'content', role: 'user' }],
+ model: 'model',
+ });
+ 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('create: required and optional params', async () => {
+ const response = await client.generate.create({
+ extra_body: { knowledge: ['string'], system_prompt: 'system_prompt' },
+ messages: [{ content: 'content', role: 'user' }],
+ model: 'model',
+ });
+ });
+});
diff --git a/tests/api-resources/rerank.test.ts b/tests/api-resources/rerank.test.ts
new file mode 100644
index 0000000..3b01b31
--- /dev/null
+++ b/tests/api-resources/rerank.test.ts
@@ -0,0 +1,31 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import ContextualAI from 'contextual-client';
+import { Response } from 'node-fetch';
+
+const client = new ContextualAI({
+ apiKey: 'My API Key',
+ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource rerank', () => {
+ test('create: only required params', async () => {
+ const responsePromise = client.rerank.create({ documents: ['string'], model: 'model', query: 'x' });
+ 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('create: required and optional params', async () => {
+ const response = await client.rerank.create({
+ documents: ['string'],
+ model: 'model',
+ query: 'x',
+ top_n: 0,
+ });
+ });
+});
From 0cfb143e6a706365c1ea6d21404e1d3dfdca87eb Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Sat, 1 Feb 2025 00:29:44 +0000
Subject: [PATCH 5/8] feat(api): update via SDK Studio (#16)
---
.stats.yml | 2 +-
src/resources/generate.ts | 24 +++++++-----------------
tests/api-resources/generate.test.ts | 5 +++--
3 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/.stats.yml b/.stats.yml
index 39a1051..2802e8c 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
configured_endpoints: 35
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-c0b9cfd71efb976777313fb342d2e31ebeb44b1b3f9bb7ddea971e6b2bc5fd19.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-f12595f01023503858500b15936a1d0d38701e48552d34c98b00a41205d2b8da.yml
diff --git a/src/resources/generate.ts b/src/resources/generate.ts
index cb4f5db..f17dbc1 100644
--- a/src/resources/generate.ts
+++ b/src/resources/generate.ts
@@ -28,9 +28,9 @@ export interface GenerateCreateResponse {
export interface GenerateCreateParams {
/**
- * Extra parameters to be passed to Contextual's GLM
+ * The knowledge sources the model can use when generating a response.
*/
- extra_body: GenerateCreateParams.ExtraBody;
+ knowledge: Array;
/**
* List of messages in the conversation so far. The last message must be from the
@@ -42,25 +42,15 @@ export interface GenerateCreateParams {
* The version of the Contextual's GLM to use. Currently, we just have "v1".
*/
model: string;
-}
-export namespace GenerateCreateParams {
/**
- * Extra parameters to be passed to Contextual's GLM
+ * Instructions that the model follows when generating responses. Note that we do
+ * not guarantee that the model follows these instructions exactly.
*/
- export interface ExtraBody {
- /**
- * The knowledge sources the model can use when generating a response.
- */
- knowledge: Array;
-
- /**
- * Instructions that the model follows when generating responses. Note that we do
- * not guarantee that the model follows these instructions exactly.
- */
- system_prompt?: string;
- }
+ system_prompt?: string;
+}
+export namespace GenerateCreateParams {
/**
* Message object for a message sent or received in a /query and /generate
* conversation
diff --git a/tests/api-resources/generate.test.ts b/tests/api-resources/generate.test.ts
index 4e89314..4c76b89 100644
--- a/tests/api-resources/generate.test.ts
+++ b/tests/api-resources/generate.test.ts
@@ -11,7 +11,7 @@ const client = new ContextualAI({
describe('resource generate', () => {
test('create: only required params', async () => {
const responsePromise = client.generate.create({
- extra_body: { knowledge: ['string'] },
+ knowledge: ['string'],
messages: [{ content: 'content', role: 'user' }],
model: 'model',
});
@@ -26,9 +26,10 @@ describe('resource generate', () => {
test('create: required and optional params', async () => {
const response = await client.generate.create({
- extra_body: { knowledge: ['string'], system_prompt: 'system_prompt' },
+ knowledge: ['string'],
messages: [{ content: 'content', role: 'user' }],
model: 'model',
+ system_prompt: 'system_prompt',
});
});
});
From 6cb56149556ce93fae414e40e23114229929f8ed Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Wed, 5 Feb 2025 04:00:34 +0000
Subject: [PATCH 6/8] feat(client): send `X-Stainless-Timeout` header (#17)
---
src/core.ts | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/core.ts b/src/core.ts
index 296cf32..156ed7f 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -280,6 +280,7 @@ export abstract class APIClient {
options: FinalRequestOptions,
{ retryCount = 0 }: { retryCount?: number } = {},
): { req: RequestInit; url: string; timeout: number } {
+ options = { ...options };
const { method, path, query, headers: headers = {} } = options;
const body =
@@ -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)
@@ -323,7 +324,7 @@ export abstract class APIClient {
signal: options.signal ?? null,
};
- return { req, url, timeout };
+ return { req, url, timeout: options.timeout };
}
private buildHeaders({
@@ -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);
From 54f55516820f04498db0f45997539d9fa142f589 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Sat, 8 Feb 2025 02:03:24 +0000
Subject: [PATCH 7/8] feat(api): update via SDK Studio (#18)
---
.stats.yml | 2 +-
src/resources/agents/agents.ts | 6 ++--
src/resources/agents/evaluate/jobs.ts | 30 ++++++++++++++++++++
src/resources/agents/query.ts | 35 +++++++++++++++++-------
tests/api-resources/agents/query.test.ts | 1 +
5 files changed, 60 insertions(+), 14 deletions(-)
diff --git a/.stats.yml b/.stats.yml
index 2802e8c..53f3a7c 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
configured_endpoints: 35
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-f12595f01023503858500b15936a1d0d38701e48552d34c98b00a41205d2b8da.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/contextual-ai%2Fsunrise-d79ccb778953ad5c2ae4b99115429c8b3f68b3b23d9b6d90b1b40393f11a4383.yml
diff --git a/src/resources/agents/agents.ts b/src/resources/agents/agents.ts
index c30e8d5..61ecf1d 100644
--- a/src/resources/agents/agents.ts
+++ b/src/resources/agents/agents.ts
@@ -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;
@@ -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;
@@ -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;
diff --git a/src/resources/agents/evaluate/jobs.ts b/src/resources/agents/evaluate/jobs.ts
index 0721938..403f451 100644
--- a/src/resources/agents/evaluate/jobs.ts
+++ b/src/resources/agents/evaluate/jobs.ts
@@ -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;
}
}
diff --git a/src/resources/agents/query.ts b/src/resources/agents/query.ts
index 0aa82f7..b957a2d 100644
--- a/src/resources/agents/query.ts
+++ b/src/resources/agents/query.ts
@@ -14,8 +14,12 @@ export class Query extends APIResource {
params: QueryCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise {
- const { retrievals_only, ...body } = params;
- return this._client.post(`/agents/${agentId}/query`, { query: { retrievals_only }, body, ...options });
+ const { include_retrieval_content_text, retrievals_only, ...body } = params;
+ return this._client.post(`/agents/${agentId}/query`, {
+ query: { include_retrieval_content_text, retrievals_only },
+ body,
+ ...options,
+ });
}
/**
@@ -135,14 +139,10 @@ export namespace QueryResponse {
type: string;
/**
- * Retrieved content
+ * Text of the retrieved content. Included in response to a query if
+ * `include_retrieval_content_text` is True
*/
- content?: string;
-
- /**
- * Reserved for extra metadata
- */
- extras?: Record;
+ content_text?: string;
/**
* Index of the retrieved item in the retrieval_contents list (starting from 1)
@@ -210,6 +210,11 @@ export namespace RetrievalInfoResponse {
*/
content_id: string;
+ /**
+ * Text of the content.
+ */
+ content_text: string;
+
/**
* Height of the image.
*/
@@ -276,7 +281,17 @@ export interface QueryCreateParams {
messages: Array;
/**
- * Query param: Set to `true` to skip generation of the response.
+ * Query param: Ignored if `retrievals_only` is True. Set to `true` to include the
+ * text of the retrieved contents in the response. If `false`, only metadata about
+ * the retrieved contents will be included, not content text. Content text and
+ * other metadata can also be fetched separately using the
+ * `/agents/{agent_id}/query/{message_id}/retrieval/info` endpoint.
+ */
+ include_retrieval_content_text?: boolean;
+
+ /**
+ * Query param: Set to `true` to fetch retrieval content and metadata, and then
+ * skip generation of the response.
*/
retrievals_only?: boolean;
diff --git a/tests/api-resources/agents/query.test.ts b/tests/api-resources/agents/query.test.ts
index b771106..da47fd4 100644
--- a/tests/api-resources/agents/query.test.ts
+++ b/tests/api-resources/agents/query.test.ts
@@ -25,6 +25,7 @@ describe('resource query', () => {
test('create: required and optional params', async () => {
const response = await client.agents.query.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
messages: [{ content: 'content', role: 'user' }],
+ include_retrieval_content_text: true,
retrievals_only: true,
conversation_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
llm_model_id: 'llm_model_id',
From a8752d92103e1ee75ce85d6f26319288a25e1df4 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Sat, 8 Feb 2025 02:03:43 +0000
Subject: [PATCH 8/8] release: 0.2.0
---
.release-please-manifest.json | 2 +-
CHANGELOG.md | 18 ++++++++++++++++++
package.json | 2 +-
src/version.ts | 2 +-
4 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 466df71..2be9c43 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.1.0"
+ ".": "0.2.0"
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 25c63b5..9bd0303 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
diff --git a/package.json b/package.json
index 91b63c2..6fb574d 100644
--- a/package.json
+++ b/package.json
@@ -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 ",
"types": "dist/index.d.ts",
diff --git a/src/version.ts b/src/version.ts
index 1baa228..bade2ff 100644
--- a/src/version.ts
+++ b/src/version.ts
@@ -1 +1 @@
-export const VERSION = '0.1.0'; // x-release-please-version
+export const VERSION = '0.2.0'; // x-release-please-version