Skip to content

Commit 4baa92d

Browse files
committed
feat: files readme
1 parent e70ecbc commit 4baa92d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ for await (const chunk of streamResponse) {
5757

5858
The `AI21` class provides a `chat` property that gives you access to the Chat API. You can use this to generate text, complete prompts, and more.
5959

60+
### Files
61+
62+
63+
The `AI21` class provides a `files` property that gives you access to the Files API. You can use this to upload files to the AI21 Studio. These files will be used as context for the conversational-rag engine.
64+
65+
66+
```typescript
67+
import { AI21 } from 'ai21';
68+
69+
const client = new AI21({
70+
apiKey: process.env.AI21_API_KEY, // or pass it in directly
71+
});
72+
73+
const fileUploadResponse = await client.files.upload({
74+
file: 'path/to/file',
75+
labels: ['science', 'biology'],
76+
path: 'path/to/file',
77+
});
78+
79+
80+
const file = await client.files.get(fileUploadResponse.fileId);
81+
82+
83+
const convRagResponse = await client.conversationalRag.create({
84+
messages: [{ role: 'user', content: 'This question presumes that the answer can be found within the uploaded files.' }],
85+
});
86+
```
87+
88+
6089
## Configuration
6190

6291
The `AI21` class accepts several configuration options, which you can pass in when creating a new instance:

0 commit comments

Comments
 (0)