Skip to content

Commit 628fbde

Browse files
feat(api): manual updates
1 parent 9fdb2c0 commit 628fbde

File tree

8 files changed

+181
-81
lines changed

8 files changed

+181
-81
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 14
1+
configured_endpoints: 15
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-bd2f55f423e09b74f83cbad6034fb76f7052363308d02533a908b49543cff459.yml
33
openapi_spec_hash: 6d7566ebda7fecac4069744949d547e0
4-
config_hash: 4e1eddd5022c75526a18c05e8a04e2c8
4+
config_hash: bad49a5f0d0d03ed67d97a3adc3e00d6

api.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ Methods:
5656
- <code title="post /queries/top-pages">client.queries.<a href="./src/resources/queries.ts">topPages</a>({ ...params }) -> QueryTopPagesResponse</code>
5757
- <code title="post /queries/top-snippets">client.queries.<a href="./src/resources/queries.ts">topSnippets</a>({ ...params }) -> QueryTopSnippetsResponse</code>
5858

59-
# Parsers
59+
# Models
6060

6161
Types:
6262

63-
- <code><a href="./src/resources/parsers.ts">ParserParseDocumentResponse</a></code>
63+
- <code><a href="./src/resources/models.ts">ModelParseDocumentResponse</a></code>
64+
- <code><a href="./src/resources/models.ts">ModelRerankResponse</a></code>
6465

6566
Methods:
6667

67-
- <code title="post /parsers/parse-document">client.parsers.<a href="./src/resources/parsers.ts">parseDocument</a>({ ...params }) -> ParserParseDocumentResponse</code>
68+
- <code title="post /parsers/parse-document">client.models.<a href="./src/resources/models.ts">parseDocument</a>({ ...params }) -> ModelParseDocumentResponse</code>
69+
- <code title="post /models/rerank">client.models.<a href="./src/resources/models.ts">rerank</a>({ ...params }) -> ModelRerankResponse</code>

src/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ import {
3232
DocumentUpdateResponse,
3333
Documents,
3434
} from './resources/documents';
35-
import { ParserParseDocumentParams, ParserParseDocumentResponse, Parsers } from './resources/parsers';
35+
import {
36+
ModelParseDocumentParams,
37+
ModelParseDocumentResponse,
38+
ModelRerankParams,
39+
ModelRerankResponse,
40+
Models,
41+
} from './resources/models';
3642
import {
3743
Queries,
3844
QueryTopDocumentsParams,
@@ -164,7 +170,7 @@ export class ZeroEntropy extends Core.APIClient {
164170
collections: API.Collections = new API.Collections(this);
165171
documents: API.Documents = new API.Documents(this);
166172
queries: API.Queries = new API.Queries(this);
167-
parsers: API.Parsers = new API.Parsers(this);
173+
models: API.Models = new API.Models(this);
168174

169175
/**
170176
* Check whether the base URL is set to its default.
@@ -215,7 +221,7 @@ ZeroEntropy.Documents = Documents;
215221
ZeroEntropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
216222
DocumentGetInfoListResponsesGetDocumentInfoListCursor;
217223
ZeroEntropy.Queries = Queries;
218-
ZeroEntropy.Parsers = Parsers;
224+
ZeroEntropy.Models = Models;
219225
export declare namespace ZeroEntropy {
220226
export type RequestOptions = Core.RequestOptions;
221227

@@ -269,9 +275,11 @@ export declare namespace ZeroEntropy {
269275
};
270276

271277
export {
272-
Parsers as Parsers,
273-
type ParserParseDocumentResponse as ParserParseDocumentResponse,
274-
type ParserParseDocumentParams as ParserParseDocumentParams,
278+
Models as Models,
279+
type ModelParseDocumentResponse as ModelParseDocumentResponse,
280+
type ModelRerankResponse as ModelRerankResponse,
281+
type ModelParseDocumentParams as ModelParseDocumentParams,
282+
type ModelRerankParams as ModelRerankParams,
275283
};
276284
}
277285

src/resources/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ export {
2525
type DocumentGetInfoListParams,
2626
type DocumentGetPageInfoParams,
2727
} from './documents';
28-
export { Parsers, type ParserParseDocumentResponse, type ParserParseDocumentParams } from './parsers';
28+
export {
29+
Models,
30+
type ModelParseDocumentResponse,
31+
type ModelRerankResponse,
32+
type ModelParseDocumentParams,
33+
type ModelRerankParams,
34+
} from './models';
2935
export {
3036
Queries,
3137
type QueryTopDocumentsResponse,

src/resources/models.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../resource';
4+
import * as Core from '../core';
5+
6+
export class Models extends APIResource {
7+
/**
8+
* This provides access to the parsers that we use for indexing. This endpoint will
9+
* not access any collection or search index, and the result will not be saved.
10+
* This will use the same parsing method as the `/documents/add-document` endpoint.
11+
*
12+
* A common use-case for this endpoint, is to use our parser in combination with
13+
* your own pre-processing step, before then uploading it to the search index using
14+
* the `text-pages` filetype.
15+
*/
16+
parseDocument(
17+
body: ModelParseDocumentParams,
18+
options?: Core.RequestOptions,
19+
): Core.APIPromise<ModelParseDocumentResponse> {
20+
return this._client.post('/parsers/parse-document', { body, ...options });
21+
}
22+
23+
/**
24+
* Reranks the provided documents, according to the provided query.
25+
*
26+
* The results will be sorted by descending order of relevance. For each document,
27+
* the index and the score will be returned. The index is relative to the documents
28+
* array that was passed in. The score is the query-document relevancy determined
29+
* by the reranker model. The value will be returned in descending order to
30+
* relevance.
31+
*/
32+
rerank(body: ModelRerankParams, options?: Core.RequestOptions): Core.APIPromise<ModelRerankResponse> {
33+
return this._client.post('/models/rerank', { body, ...options });
34+
}
35+
}
36+
37+
export interface ModelParseDocumentResponse {
38+
/**
39+
* The parsed pages. Each string will contain the full contents of a page.
40+
*/
41+
pages: Array<string>;
42+
}
43+
44+
export interface ModelRerankResponse {
45+
/**
46+
* The results, ordered by descending order of relevance to the query.
47+
*/
48+
results: Array<ModelRerankResponse.Result>;
49+
}
50+
51+
export namespace ModelRerankResponse {
52+
export interface Result {
53+
/**
54+
* The index of this document, relative to the original document array passed into
55+
* the request.
56+
*/
57+
index: number;
58+
59+
/**
60+
* The relevance score between this document and the query. This number will range
61+
* between 0.0 and 1.0. This score is dependent on only the query and the scored
62+
* document; other documents do not affect this score. This value is deterministic,
63+
* but may vary slightly due to floating point error.
64+
*/
65+
relevance_score: number;
66+
}
67+
}
68+
69+
export interface ModelParseDocumentParams {
70+
/**
71+
* The document's raw data, as a base64-encoded string
72+
*/
73+
base64_data: string;
74+
}
75+
76+
export interface ModelRerankParams {
77+
/**
78+
* The list of documents to rerank. Each document is a string.
79+
*/
80+
documents: Array<string>;
81+
82+
/**
83+
* The query to rerank the documents by. Results will be in descending order of
84+
* relevance.
85+
*/
86+
query: string;
87+
88+
/**
89+
* The model ID to use for reranking. Options are: ["zerank-1-large"]
90+
*/
91+
model?: string;
92+
93+
/**
94+
* If provided, then only the top `n` documents will be returned in the results
95+
* array.
96+
*/
97+
top_n?: number | null;
98+
}
99+
100+
export declare namespace Models {
101+
export {
102+
type ModelParseDocumentResponse as ModelParseDocumentResponse,
103+
type ModelRerankResponse as ModelRerankResponse,
104+
type ModelParseDocumentParams as ModelParseDocumentParams,
105+
type ModelRerankParams as ModelRerankParams,
106+
};
107+
}

src/resources/parsers.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/api-resources/models.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import ZeroEntropy from 'zeroentropy';
4+
import { Response } from 'node-fetch';
5+
6+
const client = new ZeroEntropy({
7+
apiKey: 'My API Key',
8+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
9+
});
10+
11+
describe('resource models', () => {
12+
test('parseDocument: only required params', async () => {
13+
const responsePromise = client.models.parseDocument({ base64_data: 'base64_data' });
14+
const rawResponse = await responsePromise.asResponse();
15+
expect(rawResponse).toBeInstanceOf(Response);
16+
const response = await responsePromise;
17+
expect(response).not.toBeInstanceOf(Response);
18+
const dataAndResponse = await responsePromise.withResponse();
19+
expect(dataAndResponse.data).toBe(response);
20+
expect(dataAndResponse.response).toBe(rawResponse);
21+
});
22+
23+
test('parseDocument: required and optional params', async () => {
24+
const response = await client.models.parseDocument({ base64_data: 'base64_data' });
25+
});
26+
27+
test('rerank: only required params', async () => {
28+
const responsePromise = client.models.rerank({ documents: ['string'], query: 'query' });
29+
const rawResponse = await responsePromise.asResponse();
30+
expect(rawResponse).toBeInstanceOf(Response);
31+
const response = await responsePromise;
32+
expect(response).not.toBeInstanceOf(Response);
33+
const dataAndResponse = await responsePromise.withResponse();
34+
expect(dataAndResponse.data).toBe(response);
35+
expect(dataAndResponse.response).toBe(rawResponse);
36+
});
37+
38+
test('rerank: required and optional params', async () => {
39+
const response = await client.models.rerank({
40+
documents: ['string'],
41+
query: 'query',
42+
model: 'model',
43+
top_n: 0,
44+
});
45+
});
46+
});

tests/api-resources/parsers.test.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)