@@ -43,12 +43,40 @@ const client = new Supermemory({
43
43
apiKey: process .env [' SUPERMEMORY_API_KEY' ], // This is the default and can be omitted
44
44
});
45
45
46
- const params: Supermemory .SearchDocumentsParams = { q: ' machine learning concepts' };
47
- const response: Supermemory .SearchDocumentsResponse = await client .search .documents (params );
46
+ const memory: Supermemory .MemoryUpdateResponse = await client .memories .update (' id' );
48
47
```
49
48
50
49
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
51
50
51
+ ## File uploads
52
+
53
+ Request parameters that correspond to file uploads can be passed in many different forms:
54
+
55
+ - ` File ` (or an object with the same structure)
56
+ - a ` fetch ` ` Response ` (or an object with the same structure)
57
+ - an ` fs.ReadStream `
58
+ - the return value of our ` toFile ` helper
59
+
60
+ ``` ts
61
+ import fs from ' fs' ;
62
+ import Supermemory , { toFile } from ' supermemory' ;
63
+
64
+ const client = new Supermemory ();
65
+
66
+ // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
67
+ await client .memories .uploadFile ({ file: fs .createReadStream (' /path/to/file' ) });
68
+
69
+ // Or if you have the web `File` API you can pass a `File` instance:
70
+ await client .memories .uploadFile ({ file: new File ([' my bytes' ], ' file' ) });
71
+
72
+ // You can also pass a `fetch` `Response`:
73
+ await client .memories .uploadFile ({ file: await fetch (' https://somesite/file' ) });
74
+
75
+ // Finally, if none of the above are convenient, you can use our `toFile` helper:
76
+ await client .memories .uploadFile ({ file: await toFile (Buffer .from (' my bytes' ), ' file' ) });
77
+ await client .memories .uploadFile ({ file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ) });
78
+ ```
79
+
52
80
## Handling errors
53
81
54
82
When the library is unable to connect to the API,
@@ -57,7 +85,7 @@ a subclass of `APIError` will be thrown:
57
85
58
86
<!-- prettier-ignore -->
59
87
``` ts
60
- const response = await client .search . documents ({ q: ' machine learning concepts ' } ).catch (async (err ) => {
88
+ const memory = await client .memories . update ( ' id ' ).catch (async (err ) => {
61
89
if (err instanceof Supermemory .APIError ) {
62
90
console .log (err .status ); // 400
63
91
console .log (err .name ); // BadRequestError
@@ -97,7 +125,7 @@ const client = new Supermemory({
97
125
});
98
126
99
127
// Or, configure per-request:
100
- await client .search . documents ({ q : ' machine learning concepts ' } , {
128
+ await client .memories . update ( ' id ' , {
101
129
maxRetries: 5 ,
102
130
});
103
131
```
@@ -114,7 +142,7 @@ const client = new Supermemory({
114
142
});
115
143
116
144
// Override per-request:
117
- await client .search . documents ({ q: ' machine learning concepts ' } , {
145
+ await client .memories . update ( ' id ' , {
118
146
timeout: 5 * 1000 ,
119
147
});
120
148
```
@@ -137,15 +165,13 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
137
165
``` ts
138
166
const client = new Supermemory ();
139
167
140
- const response = await client .search . documents ({ q: ' machine learning concepts ' } ).asResponse ();
168
+ const response = await client .memories . update ( ' id ' ).asResponse ();
141
169
console .log (response .headers .get (' X-My-Header' ));
142
170
console .log (response .statusText ); // access the underlying Response object
143
171
144
- const { data : response, response : raw } = await client .search
145
- .documents ({ q: ' machine learning concepts' })
146
- .withResponse ();
172
+ const { data : memory, response : raw } = await client .memories .update (' id' ).withResponse ();
147
173
console .log (raw .headers .get (' X-My-Header' ));
148
- console .log (response . results );
174
+ console .log (memory . id );
149
175
```
150
176
151
177
### Logging
0 commit comments