Skip to content

Commit c7b1f9c

Browse files
committed
Test
0 parents  commit c7b1f9c

31 files changed

+2121
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Local
2+
.DS_Store
3+
*.local
4+
*.log*
5+
6+
# Dist
7+
node_modules
8+
dist/
9+
doc_build/
10+
11+
# IDE
12+
.vscode/*
13+
!.vscode/extensions.json
14+
.idea

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rspress website
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
npm install
9+
```
10+
11+
## Get started
12+
13+
Start the dev server:
14+
15+
```bash
16+
npm run dev
17+
```
18+
19+
Build the website for production:
20+
21+
```bash
22+
npm run build
23+
```
24+
25+
Preview the production build locally:
26+
27+
```bash
28+
npm run preview
29+
```

bun.lock

Lines changed: 907 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/en/_meta.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"text": "docs",
4+
"link": "/guide/docs",
5+
"activeMatch": "/guide/docs"
6+
},
7+
{
8+
"text": "changelog",
9+
"link": "/guide/start/changelog/",
10+
"activeMatch": "/guide/start/changelog"
11+
}
12+
]

docs/en/guide/_meta.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"type": "dir",
4+
"name": "start",
5+
"label": "start",
6+
"collapsible": false,
7+
"collapsed": false
8+
},
9+
{
10+
"type": "dir",
11+
"name": "docs",
12+
"label": "docs",
13+
"collapsible": true,
14+
"collapsed": false
15+
}
16+
]

docs/en/guide/docs/assistant.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
The `Assistant` module provides a powerful API that allows users to request structured JSON data from the assistant. This functionality can be used for automation tasks such as extracting bill details, categorizing expenses, or parsing text data.
2+
3+
## `isAvailable` Variable
4+
5+
### Description
6+
7+
Indicates whether the Assistant API is available.
8+
9+
- This status depends on the selected AI provider and whether a valid API Key is configured.
10+
- If the appropriate API Key is not provided, the Assistant API will be unavailable.
11+
12+
## `requestStructuredData` Method
13+
14+
### Description
15+
16+
`requestStructuredData` allows users to send a text prompt to the assistant and receive structured data in JSON format based on a defined schema.
17+
18+
### Syntax
19+
20+
```ts
21+
function requestStructuredData<R>(prompt: string, schema: JSONSchemaArray | JSONSchemaObject): Promise<R>;
22+
```
23+
24+
### Parameters
25+
26+
- `prompt` (`string`): The input prompt describing the content to be parsed.
27+
- `schema` (`JSONSchemaArray | JSONSchemaObject`): The expected output JSON schema, defining the structure of the returned data.
28+
29+
### Return Value
30+
31+
Returns a `Promise` resolving to structured JSON data that matches the `schema` definition, with a type of `R`.
32+
33+
---
34+
35+
## JSON Schema Definition
36+
37+
The `schema` parameter in the `requestStructuredData` method defines the structure of the returned JSON data, with the following types:
38+
39+
### `JSONSchemaType`
40+
41+
```ts
42+
type JSONSchemaType = JSONSchemaPrimitive | JSONSchemaArray | JSONSchemaObject;
43+
```
44+
45+
Primitive data type definition:
46+
47+
```ts
48+
type JSONSchemaPrimitive = {
49+
type: "string" | "number" | "boolean";
50+
required?: boolean;
51+
description: string;
52+
};
53+
```
54+
55+
Array type definition:
56+
57+
```ts
58+
type JSONSchemaArray = {
59+
type: "array";
60+
items: JSONSchemaType;
61+
required?: boolean;
62+
description: string;
63+
};
64+
```
65+
66+
Object type definition:
67+
68+
```ts
69+
type JSONSchemaObject = {
70+
type: "object";
71+
properties: Record<string, JSONSchemaType>;
72+
required?: boolean;
73+
description: string;
74+
};
75+
```
76+
77+
### Example
78+
79+
```ts
80+
const schema: JSONSchemaObject = {
81+
type: "object",
82+
properties: {
83+
totalAmount: {
84+
type: "number",
85+
required: true,
86+
description: "Total bill amount",
87+
},
88+
category: {
89+
type: "string",
90+
required: true,
91+
description: "Bill category",
92+
},
93+
date: {
94+
type: "string",
95+
required: false,
96+
description: "Bill date",
97+
},
98+
location: {
99+
type: "string",
100+
required: false,
101+
description: "Bill location",
102+
},
103+
},
104+
};
105+
```
106+
107+
---
108+
109+
## Example Usage
110+
111+
### Parsing Bill Information
112+
113+
Suppose we have a bill, and we need to extract its amount, date, category, and location.
114+
115+
```ts
116+
const someBillDetails = `
117+
- Amount: $15.00
118+
- Date: 2024-03-11 14:30
119+
- Location: City Center Parking Lot
120+
- Category: Parking
121+
`;
122+
123+
const prompt = `Please parse the following bill and output the structured data: ${someBillDetails}`;
124+
125+
const data = await Assistant.requestStructuredData(prompt, schema);
126+
console.log(data);
127+
```
128+
129+
### Possible Output
130+
131+
```json
132+
{
133+
"totalAmount": 15.0,
134+
"category": "Parking",
135+
"date": "2024-03-11 14:30",
136+
"location": "City Center Parking Lot"
137+
}
138+
```
139+
140+
---
141+
142+
## Usage Considerations
143+
144+
1. **Ensure the `schema` is correctly defined**: The JSON schema should match the expected data format.
145+
2. **Use `required` attributes carefully**: If a field is essential, set `required: true`.
146+
3. **Provide a clear `prompt`**: A detailed `prompt` improves the accuracy of the assistant's response.
147+
4. **Error Handling**: Since `requestStructuredData` returns a `Promise`, handle potential errors using `try-catch`.
148+
149+
Example error handling:
150+
151+
```ts
152+
try {
153+
const data = await Assistant.requestStructuredData(prompt, schema);
154+
console.log("Parsed result:", data);
155+
} catch (error) {
156+
console.error("Parsing failed:", error);
157+
}
158+
```

0 commit comments

Comments
 (0)