Skip to content

Commit 4fd4c3f

Browse files
feat(api): api update
1 parent a61ec47 commit 4fd4c3f

File tree

8 files changed

+26
-800
lines changed

8 files changed

+26
-800
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 18
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-new-2e25417520c33948724b7835b9b98cdb13e719c64bb30310d63e6cfbb8f8c02a.yml
3-
openapi_spec_hash: e1117a859f74f4c7d41a8aee21c433e8
1+
configured_endpoints: 12
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-new-13d3700bbf9ff52715f14809e3a297c6f76e956a19b86d51ddf27059d846d276.yml
3+
openapi_spec_hash: c4f9fe259a4f8f58114611fc6f87f4f2
44
config_hash: 9b9291a6c872b063900a46386729ba3c

README.md

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,12 @@ const client = new Supermemory({
4343
apiKey: process.env['SUPERMEMORY_API_KEY'], // This is the default and can be omitted
4444
});
4545

46-
const params: Supermemory.MemoryAddParams = {
47-
content: 'This is a detailed article about machine learning concepts...',
48-
};
49-
const response: Supermemory.MemoryAddResponse = await client.memories.add(params);
46+
const params: Supermemory.SearchDocumentsParams = { q: 'machine learning concepts' };
47+
const response: Supermemory.SearchDocumentsResponse = await client.search.documents(params);
5048
```
5149

5250
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
5351

54-
## File uploads
55-
56-
Request parameters that correspond to file uploads can be passed in many different forms:
57-
58-
- `File` (or an object with the same structure)
59-
- a `fetch` `Response` (or an object with the same structure)
60-
- an `fs.ReadStream`
61-
- the return value of our `toFile` helper
62-
63-
```ts
64-
import fs from 'fs';
65-
import Supermemory, { toFile } from 'supermemory';
66-
67-
const client = new Supermemory();
68-
69-
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
70-
await client.memories.uploadFile({ file: fs.createReadStream('/path/to/file') });
71-
72-
// Or if you have the web `File` API you can pass a `File` instance:
73-
await client.memories.uploadFile({ file: new File(['my bytes'], 'file') });
74-
75-
// You can also pass a `fetch` `Response`:
76-
await client.memories.uploadFile({ file: await fetch('https://somesite/file') });
77-
78-
// Finally, if none of the above are convenient, you can use our `toFile` helper:
79-
await client.memories.uploadFile({ file: await toFile(Buffer.from('my bytes'), 'file') });
80-
await client.memories.uploadFile({ file: await toFile(new Uint8Array([0, 1, 2]), 'file') });
81-
```
82-
8352
## Handling errors
8453

8554
When the library is unable to connect to the API,
@@ -88,17 +57,15 @@ a subclass of `APIError` will be thrown:
8857

8958
<!-- prettier-ignore -->
9059
```ts
91-
const response = await client.memories
92-
.add({ content: 'This is a detailed article about machine learning concepts...' })
93-
.catch(async (err) => {
94-
if (err instanceof Supermemory.APIError) {
95-
console.log(err.status); // 400
96-
console.log(err.name); // BadRequestError
97-
console.log(err.headers); // {server: 'nginx', ...}
98-
} else {
99-
throw err;
100-
}
101-
});
60+
const response = await client.search.documents({ q: 'machine learning concepts' }).catch(async (err) => {
61+
if (err instanceof Supermemory.APIError) {
62+
console.log(err.status); // 400
63+
console.log(err.name); // BadRequestError
64+
console.log(err.headers); // {server: 'nginx', ...}
65+
} else {
66+
throw err;
67+
}
68+
});
10269
```
10370

10471
Error codes are as follows:
@@ -130,7 +97,7 @@ const client = new Supermemory({
13097
});
13198

13299
// Or, configure per-request:
133-
await client.memories.add({ content: 'This is a detailed article about machine learning concepts...' }, {
100+
await client.search.documents({ q: 'machine learning concepts' }, {
134101
maxRetries: 5,
135102
});
136103
```
@@ -147,7 +114,7 @@ const client = new Supermemory({
147114
});
148115

149116
// Override per-request:
150-
await client.memories.add({ content: 'This is a detailed article about machine learning concepts...' }, {
117+
await client.search.documents({ q: 'machine learning concepts' }, {
151118
timeout: 5 * 1000,
152119
});
153120
```
@@ -170,17 +137,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
170137
```ts
171138
const client = new Supermemory();
172139

173-
const response = await client.memories
174-
.add({ content: 'This is a detailed article about machine learning concepts...' })
175-
.asResponse();
140+
const response = await client.search.documents({ q: 'machine learning concepts' }).asResponse();
176141
console.log(response.headers.get('X-My-Header'));
177142
console.log(response.statusText); // access the underlying Response object
178143

179-
const { data: response, response: raw } = await client.memories
180-
.add({ content: 'This is a detailed article about machine learning concepts...' })
144+
const { data: response, response: raw } = await client.search
145+
.documents({ q: 'machine learning concepts' })
181146
.withResponse();
182147
console.log(raw.headers.get('X-My-Header'));
183-
console.log(response.id);
148+
console.log(response.results);
184149
```
185150

186151
### Logging

api.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
# Memories
22

3-
Types:
4-
5-
- <code><a href="./src/resources/memories.ts">MemoryUpdateResponse</a></code>
6-
- <code><a href="./src/resources/memories.ts">MemoryListResponse</a></code>
7-
- <code><a href="./src/resources/memories.ts">MemoryAddResponse</a></code>
8-
- <code><a href="./src/resources/memories.ts">MemoryGetResponse</a></code>
9-
- <code><a href="./src/resources/memories.ts">MemoryUploadFileResponse</a></code>
10-
11-
Methods:
12-
13-
- <code title="patch /v3/memories/{id}">client.memories.<a href="./src/resources/memories.ts">update</a>(id, { ...params }) -> MemoryUpdateResponse</code>
14-
- <code title="post /v3/memories/list">client.memories.<a href="./src/resources/memories.ts">list</a>({ ...params }) -> MemoryListResponse</code>
15-
- <code title="delete /v3/memories/{id}">client.memories.<a href="./src/resources/memories.ts">delete</a>(id) -> void</code>
16-
- <code title="post /v3/memories">client.memories.<a href="./src/resources/memories.ts">add</a>({ ...params }) -> MemoryAddResponse</code>
17-
- <code title="get /v3/memories/{id}">client.memories.<a href="./src/resources/memories.ts">get</a>(id) -> MemoryGetResponse</code>
18-
- <code title="post /v3/memories/file">client.memories.<a href="./src/resources/memories.ts">uploadFile</a>({ ...params }) -> MemoryUploadFileResponse</code>
19-
203
# Search
214

225
Types:

src/client.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,7 @@ import {
3333
ConnectionListResponse,
3434
Connections,
3535
} from './resources/connections';
36-
import {
37-
Memories,
38-
MemoryAddParams,
39-
MemoryAddResponse,
40-
MemoryGetResponse,
41-
MemoryListParams,
42-
MemoryListResponse,
43-
MemoryUpdateParams,
44-
MemoryUpdateResponse,
45-
MemoryUploadFileParams,
46-
MemoryUploadFileResponse,
47-
} from './resources/memories';
36+
import { Memories } from './resources/memories';
4837
import {
4938
Search,
5039
SearchDocumentsParams,
@@ -771,18 +760,7 @@ Supermemory.Connections = Connections;
771760
export declare namespace Supermemory {
772761
export type RequestOptions = Opts.RequestOptions;
773762

774-
export {
775-
Memories as Memories,
776-
type MemoryUpdateResponse as MemoryUpdateResponse,
777-
type MemoryListResponse as MemoryListResponse,
778-
type MemoryAddResponse as MemoryAddResponse,
779-
type MemoryGetResponse as MemoryGetResponse,
780-
type MemoryUploadFileResponse as MemoryUploadFileResponse,
781-
type MemoryUpdateParams as MemoryUpdateParams,
782-
type MemoryListParams as MemoryListParams,
783-
type MemoryAddParams as MemoryAddParams,
784-
type MemoryUploadFileParams as MemoryUploadFileParams,
785-
};
763+
export { Memories as Memories };
786764

787765
export {
788766
Search as Search,

src/resources/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@ export {
1717
type ConnectionImportParams,
1818
type ConnectionListDocumentsParams,
1919
} from './connections';
20-
export {
21-
Memories,
22-
type MemoryUpdateResponse,
23-
type MemoryListResponse,
24-
type MemoryAddResponse,
25-
type MemoryGetResponse,
26-
type MemoryUploadFileResponse,
27-
type MemoryUpdateParams,
28-
type MemoryListParams,
29-
type MemoryAddParams,
30-
type MemoryUploadFileParams,
31-
} from './memories';
20+
export { Memories } from './memories';
3221
export {
3322
Search,
3423
type SearchDocumentsResponse,

0 commit comments

Comments
 (0)