@clidey/dory 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/features.mdx +140 -363
- package/package.json +1 -1
- package/src/plugins/sanitize.ts +47 -4
package/docs/features.mdx
CHANGED
|
@@ -1,440 +1,217 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
3
|
-
description:
|
|
2
|
+
title: "Conversational AI: Chatting with Your Documents"
|
|
3
|
+
description: "Enable interactive Q&A over your uploaded documents using the Morphik Agent and Console chat. This step-by-step guide shows how to setup, invoke, and optimize conversational workflows for research and support scenarios."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# Conversational AI: Chatting with Your Documents
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
# Heading 1
|
|
10
|
-
```
|
|
11
|
-
# Heading 1
|
|
12
|
-
|
|
13
|
-
```mdx
|
|
14
|
-
## Heading 2
|
|
15
|
-
```
|
|
16
|
-
# Heading 2
|
|
17
|
-
|
|
18
|
-
```mdx
|
|
19
|
-
### Heading 3
|
|
20
|
-
```
|
|
21
|
-
# Heading 3
|
|
22
|
-
```mdx
|
|
23
|
-
#### Heading 4
|
|
24
|
-
```
|
|
25
|
-
# Heading 4
|
|
26
|
-
```mdx
|
|
27
|
-
##### Heading 5
|
|
28
|
-
```
|
|
29
|
-
# Heading 5
|
|
30
|
-
```mdx
|
|
31
|
-
###### Heading 6
|
|
32
|
-
```
|
|
33
|
-
# Heading 6
|
|
34
|
-
|
|
35
|
-
<br />
|
|
36
|
-
|
|
37
|
-
## Lists Examples
|
|
38
|
-
|
|
39
|
-
```mdx
|
|
40
|
-
- List item 1
|
|
41
|
-
- List item 2
|
|
42
|
-
- List item 3
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
- List item 1
|
|
46
|
-
- List item 2
|
|
47
|
-
- List item 3
|
|
48
|
-
|
|
49
|
-
```mdx
|
|
50
|
-
1. List item 1
|
|
51
|
-
2. List item 2
|
|
52
|
-
3. List item 3
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
1. List item 1
|
|
56
|
-
2. List item 2
|
|
57
|
-
3. List item 3
|
|
8
|
+
Enable interactive Q&A over your uploaded documents using the Morphik Agent and Console chat. This step-by-step guide shows you how to set up, invoke, and optimize conversational workflows for research and support scenarios, empowering you to get precise, context-aware answers directly from your document collections.
|
|
58
9
|
|
|
10
|
+
---
|
|
59
11
|
|
|
12
|
+
## 1. Introduction
|
|
60
13
|
|
|
61
|
-
|
|
14
|
+
Conversational AI with Morphik lets you transform your document repositories into intelligent, interactive knowledge assistants. By leveraging Morphik's agent framework and chat interface, you can ask natural language questions about your documents and receive accurate, sourced responses combining search, analysis, and knowledge graph insights.
|
|
62
15
|
|
|
63
|
-
|
|
16
|
+
This guide focuses specifically on the **chatting experience** — how to activate and use the Morphik Agent alongside the Morphik Console or SDK to carry contextual conversations grounded in your document data.
|
|
64
17
|
|
|
65
|
-
|
|
66
|
-
<img src="./assets/dory.jpeg" alt="Example image" className="object-cover w-64 h-64" />
|
|
67
|
-
```
|
|
18
|
+
---
|
|
68
19
|
|
|
69
|
-
|
|
20
|
+
## 2. Prerequisites
|
|
70
21
|
|
|
22
|
+
Before starting, ensure you have:
|
|
71
23
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
24
|
+
- A running Morphik server instance (hosted or self-hosted).
|
|
25
|
+
- Documents uploaded to Morphik via the Console or SDK.
|
|
26
|
+
- The Morphik Agent enabled and configured (part of Morphik Core).
|
|
27
|
+
- Access to the Morphik Console for interactive chat or access to the Python SDK for programmatic use.
|
|
75
28
|
|
|
76
|
-
|
|
29
|
+
> <Check>
|
|
30
|
+
> Make sure your user account has permissions to query documents and knowledge graphs.
|
|
31
|
+
>
|
|
32
|
+
---
|
|
77
33
|
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
function example() {
|
|
81
|
-
return "Hello World";
|
|
82
|
-
}
|
|
83
|
-
```
|
|
34
|
+
## 3. Workflow Overview
|
|
84
35
|
|
|
85
|
-
###
|
|
36
|
+
### What You Will Accomplish
|
|
86
37
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
```javascript
|
|
94
|
-
function example() {
|
|
95
|
-
return "Hello World";
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
</CodeGroup>
|
|
38
|
+
- Set up Morphik Agent to interpret user queries.
|
|
39
|
+
- Use natural language to query documents interactively.
|
|
40
|
+
- Receive well-organized answers with clear source attributions.
|
|
41
|
+
- Understand how the agent leverages multiple tools for retrieval and analysis.
|
|
99
42
|
|
|
43
|
+
### Time Estimate
|
|
100
44
|
|
|
101
|
-
|
|
102
|
-
<br />
|
|
103
|
-
<br />
|
|
45
|
+
~15–30 minutes to get a working chat interface and basic conversational flow.
|
|
104
46
|
|
|
47
|
+
### Difficulty Level
|
|
105
48
|
|
|
106
|
-
|
|
49
|
+
Intermediate — some familiarity with Morphik platform and basic querying.
|
|
107
50
|
|
|
108
|
-
|
|
51
|
+
---
|
|
109
52
|
|
|
110
|
-
|
|
111
|
-
mermaid
|
|
112
|
-
graph TD
|
|
53
|
+
## 4. Setting Up Conversational AI
|
|
113
54
|
|
|
114
|
-
|
|
115
|
-
Start([Start Process]) --> Validate[Validate Input]
|
|
55
|
+
### Step 1: Confirm Documents Are Ingested
|
|
116
56
|
|
|
117
|
-
|
|
118
|
-
Validate -->|Valid| ProcessData{Is Data Clean?}
|
|
119
|
-
Validate -->|Invalid| Error[Show Error Message]
|
|
57
|
+
You must have documents ingested into Morphik.
|
|
120
58
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Clean --> Analyze[Analyze Data]
|
|
59
|
+
- Use the Console to upload or verify documents.
|
|
60
|
+
- Or use the Python SDK `ingest_text()` or `ingest_file()` functions.
|
|
124
61
|
|
|
125
|
-
|
|
126
|
-
ProcessData -->|No| Notify[Notify User]
|
|
127
|
-
Notify --> Wait[Wait for Input]
|
|
128
|
-
Wait --> Validate
|
|
62
|
+
### Step 2: Configure the Morphik Agent
|
|
129
63
|
|
|
130
|
-
|
|
131
|
-
Analyze --> Split1 & Split2
|
|
64
|
+
The Morphik Agent acts as the orchestrator between user queries and Morphik's internal tools.
|
|
132
65
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
Split2[Update Dashboard] --> Merge
|
|
136
|
-
end
|
|
66
|
+
- The agent uses a system prompt describing available tools like chunk retrieval, document analysis, knowledge graph queries, and code execution.
|
|
67
|
+
- It converts user input into function calls to relevant Morphik APIs.
|
|
137
68
|
|
|
138
|
-
|
|
139
|
-
Decision2 -->|Yes| WaitMore[Wait for More Input]
|
|
140
|
-
WaitMore --> Validate
|
|
141
|
-
Decision2 -->|No| End([End Process])
|
|
69
|
+
Typical agent setup (embedded in Morphik Core):
|
|
142
70
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
class ProcessData,Decision2 decision;
|
|
71
|
+
```python
|
|
72
|
+
from core.agent import MorphikAgent
|
|
146
73
|
|
|
74
|
+
# Assume document_service is your Morphik document API client
|
|
75
|
+
agent = MorphikAgent(document_service=document_service, model="gpt-4") # or any supported model
|
|
147
76
|
```
|
|
148
77
|
|
|
149
|
-
|
|
150
|
-
<p>Note: Mermaid should be inside a code block with type "mermaid"</p>
|
|
151
|
-
</strong>
|
|
152
|
-
|
|
153
|
-
```mermaid
|
|
154
|
-
graph TD
|
|
78
|
+
### Step 3: Build a Chat Interface
|
|
155
79
|
|
|
156
|
-
|
|
157
|
-
Start([Start Process]) --> Validate[Validate Input]
|
|
80
|
+
You can interact with the agent through several clients:
|
|
158
81
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
Validate -->|Invalid| Error[Show Error Message]
|
|
82
|
+
- **Morphik Console Chat**: Web-based chat UI within the Morphik Console.
|
|
83
|
+
- **Python SDK**: Run queries programmatically by sending conversational history and user queries.
|
|
162
84
|
|
|
163
|
-
|
|
164
|
-
ProcessData -->|Yes| Clean[Clean Data]
|
|
165
|
-
Clean --> Analyze[Analyze Data]
|
|
85
|
+
Example: Basic agent run call from Python
|
|
166
86
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
Notify --> Wait[Wait for Input]
|
|
170
|
-
Wait --> Validate
|
|
87
|
+
```python
|
|
88
|
+
import asyncio
|
|
171
89
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Split1[Generate Report] --> Merge
|
|
177
|
-
Split2[Update Dashboard] --> Merge
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
Merge --> Decision2{Is More Input Needed?}
|
|
181
|
-
Decision2 -->|Yes| WaitMore[Wait for More Input]
|
|
182
|
-
WaitMore --> Validate
|
|
183
|
-
Decision2 -->|No| End([End Process])
|
|
184
|
-
|
|
185
|
-
%% Style and Class Definitions
|
|
186
|
-
classDef decision fill:#f9f,stroke:#333,stroke-width:2px;
|
|
187
|
-
class ProcessData,Decision2 decision;
|
|
90
|
+
async def chat(agent, user_query):
|
|
91
|
+
auth_context = ... # your auth context
|
|
92
|
+
response = await agent.run(query=user_query, auth=auth_context)
|
|
93
|
+
print(response["response"])
|
|
188
94
|
|
|
95
|
+
asyncio.run(chat(agent, "What is reinforcement learning?"))
|
|
189
96
|
```
|
|
190
97
|
|
|
191
|
-
|
|
98
|
+
> <Tip>
|
|
99
|
+
> The agent requires an authenticated user context (`auth`) to respect data access control.
|
|
100
|
+
>
|
|
101
|
+
### Step 4: Execute Conversational Queries
|
|
192
102
|
|
|
193
|
-
|
|
194
|
-
<AccordionGroup>
|
|
195
|
-
<Accordion title="First Section" icon="DocumentIcon">
|
|
196
|
-
This is the content of the first accordion section.
|
|
197
|
-
</Accordion>
|
|
198
|
-
<Accordion title="Second Section" icon="CodeBracketIcon">
|
|
199
|
-
This is the content of the second accordion section.
|
|
200
|
-
</Accordion>
|
|
201
|
-
</AccordionGroup>
|
|
202
|
-
```
|
|
103
|
+
With the agent configured and interface in place, you can ask questions like:
|
|
203
104
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
</Accordion>
|
|
208
|
-
<Accordion title="Second Section" icon="CodeBracketIcon">
|
|
209
|
-
This is the content of the second accordion section.
|
|
210
|
-
</Accordion>
|
|
211
|
-
</AccordionGroup>
|
|
105
|
+
- "Summarize the key points in the document about AI."
|
|
106
|
+
- "Show me diagrams related to reinforcement learning."
|
|
107
|
+
- "What entities appear in the contract documents?"
|
|
212
108
|
|
|
213
|
-
|
|
109
|
+
The agent breaks these queries into tool calls behind the scenes and constructs rich, sourced responses.
|
|
214
110
|
|
|
215
|
-
|
|
216
|
-
<Note>
|
|
217
|
-
This is a note callout with important information.
|
|
218
|
-
</Note>
|
|
219
|
-
```
|
|
111
|
+
---
|
|
220
112
|
|
|
221
|
-
|
|
222
|
-
This is a note callout with important information.
|
|
223
|
-
</Note>
|
|
113
|
+
## 5. How the Morphik Agent Works Behind the Scenes
|
|
224
114
|
|
|
225
|
-
|
|
226
|
-
<Warning>
|
|
227
|
-
This is a warning callout for critical information.
|
|
228
|
-
</Warning>
|
|
229
|
-
```
|
|
115
|
+
The Morphik Agent integrates several internal tools to answer user questions effectively:
|
|
230
116
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
117
|
+
- **`retrieve_chunks`**: Finds the most relevant text and image fragments from indexed documents.
|
|
118
|
+
- **`retrieve_document`**: Accesses full documents or metadata by ID.
|
|
119
|
+
- **`document_analyzer`**: Extracts entities, facts, sentiment, and summaries.
|
|
120
|
+
- **`knowledge_graph_query`**: Navigates entities and relationships in knowledge graphs.
|
|
121
|
+
- **Other tools** like code execution and persistent memory saving.
|
|
234
122
|
|
|
235
|
-
|
|
236
|
-
<Info>
|
|
237
|
-
This is an info callout for general information.
|
|
238
|
-
</Info>
|
|
239
|
-
```
|
|
123
|
+
The agent dynamically decides which APIs to invoke based on the query context.
|
|
240
124
|
|
|
241
|
-
|
|
242
|
-
This is an info callout for general information.
|
|
243
|
-
</Info>
|
|
125
|
+
---
|
|
244
126
|
|
|
245
|
-
|
|
246
|
-
<Tip>
|
|
247
|
-
This is a tip callout for helpful suggestions.
|
|
248
|
-
</Tip>
|
|
249
|
-
```
|
|
127
|
+
## 6. Best Practices & Tips
|
|
250
128
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
129
|
+
- **Scope Your Queries**: Use filters like folder name or user ID to limit results and speed up responses.
|
|
130
|
+
- **Use Multi-Turn Conversations**: Provide context from earlier messages to get more precise answers.
|
|
131
|
+
- **Attribute Your Sources**: The agent returns source references for transparent answers.
|
|
132
|
+
- **Monitor Token Limits**: Be mindful of model token constraints; truncate or segment documents if needed.
|
|
133
|
+
- **Keep Your Documents Up to Date**: Re-ingest changed documents so retrieval returns current info.
|
|
254
134
|
|
|
255
|
-
|
|
256
|
-
<Check>
|
|
257
|
-
This is a check callout for completed items.
|
|
258
|
-
</Check>
|
|
259
|
-
```
|
|
135
|
+
---
|
|
260
136
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
href="#"
|
|
282
|
-
/>
|
|
283
|
-
</CardGroup>
|
|
284
|
-
```
|
|
137
|
+
## 7. Troubleshooting Common Issues
|
|
138
|
+
|
|
139
|
+
<AccordionGroup title="Troubleshooting Conversational AI">
|
|
140
|
+
<Accordion title="Agent Returns No or Irrelevant Results">
|
|
141
|
+
- Verify your documents are indexed and visible to your user.
|
|
142
|
+
- Check query filters and ensure they match existing document metadata.
|
|
143
|
+
- Increase the number of chunks retrieved to widen the search scope.
|
|
144
|
+
</Accordion>
|
|
145
|
+
<Accordion title="Agent Fails or Crashes During Execution">
|
|
146
|
+
- Confirm your Morphik service is running with adequate resources.
|
|
147
|
+
- Check logs for errors related to tool invocation or model loading.
|
|
148
|
+
- Validate your authentication token or context is correct.
|
|
149
|
+
- Check model supported in your configuration (e.g. GPT-4).
|
|
150
|
+
</Accordion>
|
|
151
|
+
<Accordion title="Sources or Citations Are Missing in Responses">
|
|
152
|
+
- Ensure your documents contain proper metadata with chunks.
|
|
153
|
+
- Confirm the agent is using the correct source map.
|
|
154
|
+
- Verify that retrieval calls return source IDs.
|
|
155
|
+
</Accordion>
|
|
156
|
+
</AccordionGroup>
|
|
285
157
|
|
|
286
|
-
|
|
287
|
-
<Card
|
|
288
|
-
title="Example Card"
|
|
289
|
-
description="This is an example card component with an icon and title."
|
|
290
|
-
icon="FileText"
|
|
291
|
-
href="#"
|
|
292
|
-
/>
|
|
293
|
-
<Card
|
|
294
|
-
title="Another Card"
|
|
295
|
-
description="This is another example card with different content."
|
|
296
|
-
icon="Code"
|
|
297
|
-
href="#"
|
|
298
|
-
/>
|
|
299
|
-
</CardGroup>
|
|
300
|
-
|
|
301
|
-
<br />
|
|
302
|
-
|
|
303
|
-
### Expandable
|
|
304
|
-
|
|
305
|
-
```mdx
|
|
306
|
-
<Expandable title="Click to Expand">
|
|
307
|
-
This is an expandable section that can be toggled.
|
|
308
|
-
</Expandable>
|
|
309
|
-
```
|
|
158
|
+
---
|
|
310
159
|
|
|
311
|
-
|
|
312
|
-
This is an expandable section that can be toggled.
|
|
313
|
-
</Expandable>
|
|
160
|
+
## 8. Example: Interactive Chat with Morphik Console
|
|
314
161
|
|
|
315
|
-
|
|
162
|
+
1. Open the Morphik Console in your browser.
|
|
163
|
+
2. Navigate to the 'Chat' tab.
|
|
164
|
+
3. Enter the query:
|
|
316
165
|
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
{ path: "src/mdx/source.tsx", range: "1-46" },
|
|
320
|
-
{ path: "docs/features.mdx", range: "318-322" },
|
|
321
|
-
]} />
|
|
166
|
+
```text
|
|
167
|
+
What does the document say about reinforcement learning?
|
|
322
168
|
```
|
|
323
169
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
{ path: "docs/features.mdx", range: "318-322" },
|
|
327
|
-
]} />
|
|
328
|
-
|
|
329
|
-
<br />
|
|
330
|
-
<br />
|
|
331
|
-
<br />
|
|
332
|
-
|
|
170
|
+
4. The chat will return a detailed answer with markdown formatting and source attributions.
|
|
171
|
+
5. Explore linked entities or images directly within the chat where available.
|
|
333
172
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
### Grids
|
|
337
|
-
|
|
338
|
-
#### Rows
|
|
339
|
-
```mdx
|
|
340
|
-
<Row cols={2}>
|
|
341
|
-
<Icon icon="FileText" />
|
|
342
|
-
<Icon icon="CheckCircle" />
|
|
343
|
-
</Row>
|
|
344
|
-
```
|
|
173
|
+
---
|
|
345
174
|
|
|
346
|
-
|
|
347
|
-
<Icon icon="FileText" />
|
|
348
|
-
<Icon icon="CheckCircle" />
|
|
349
|
-
</Row>
|
|
175
|
+
## 9. Example: Python SDK Conversational Query
|
|
350
176
|
|
|
351
|
-
|
|
177
|
+
```python
|
|
178
|
+
from morphik import Morphik
|
|
352
179
|
|
|
353
|
-
|
|
180
|
+
morphik = Morphik("morphik://user:token@api.morphik.ai")
|
|
354
181
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
<Icon icon="FileText" />
|
|
358
|
-
<Icon icon="FileText" />
|
|
359
|
-
</Col>
|
|
182
|
+
response = morphik.query("Explain the advantage of Retrieval Augmented Generation.")
|
|
183
|
+
print(response.completion)
|
|
360
184
|
```
|
|
361
185
|
|
|
362
|
-
|
|
363
|
-
<Icon icon="FileText" />
|
|
364
|
-
<Icon icon="FileText" />
|
|
365
|
-
</Col>
|
|
366
|
-
|
|
367
|
-
<br />
|
|
368
|
-
<br />
|
|
369
|
-
<br />
|
|
370
|
-
|
|
371
|
-
### Latex
|
|
372
|
-
|
|
373
|
-
```mdx
|
|
374
|
-
<Latex>
|
|
375
|
-
E = mc^2
|
|
376
|
-
</Latex>
|
|
377
|
-
```
|
|
186
|
+
This sends a natural language query routed to the Morphik Agent that returns composed answers referencing documents.
|
|
378
187
|
|
|
379
|
-
|
|
380
|
-
E = mc^2
|
|
381
|
-
</Latex>
|
|
188
|
+
---
|
|
382
189
|
|
|
383
|
-
|
|
384
|
-
<br />
|
|
385
|
-
<br />
|
|
190
|
+
## 10. Next Steps & Further Reading
|
|
386
191
|
|
|
387
|
-
|
|
192
|
+
- Explore [Multimodal Search & Retrieval guide](/guides/core-workflows/multimodal-search) to understand how retrieval integrates with chat.
|
|
193
|
+
- Learn about [Building Knowledge Graphs](/guides/knowledge-graphs/build-knowledge-graph) to enhance entity-level understanding.
|
|
194
|
+
- Review [Cache-Augmented Generation](/guides/integrations-and-caching/cache-augmentation) to accelerate response times via document caching.
|
|
195
|
+
- Deep dive into Morphik Console features in [Using the Morphik Console](/getting-started/first-steps-and-validation/using-the-morphik-console).
|
|
196
|
+
- Consult the [Agent code & tools description](/core/agent.py) for advanced customization.
|
|
388
197
|
|
|
389
|
-
|
|
390
|
-
| Property | Description |
|
|
391
|
-
| -------- | ------------------------------------- |
|
|
392
|
-
| Name | Full name of user |
|
|
393
|
-
| Age | Reported age |
|
|
394
|
-
| Joined | Whether the user joined the community |
|
|
395
|
-
```
|
|
198
|
+
---
|
|
396
199
|
|
|
397
|
-
|
|
398
|
-
| -------- | ------------------------------------- |
|
|
399
|
-
| Name | Full name of user |
|
|
400
|
-
| Age | Reported age |
|
|
401
|
-
| Joined | Whether the user joined the community |
|
|
200
|
+
## 11. Summary
|
|
402
201
|
|
|
202
|
+
By following this guide, you will have enabled a robust conversational AI interface backed by Morphik’s multimodal document understanding and knowledge graph capabilities. This conversational workflow transforms your static documents into interactive assistants that can support research, customer support, and knowledge discovery efficiently.
|
|
403
203
|
|
|
404
|
-
|
|
204
|
+
---
|
|
405
205
|
|
|
406
|
-
|
|
407
|
-
<Steps>
|
|
408
|
-
<Step title="First Step">
|
|
409
|
-
This is the first step in the process.
|
|
410
|
-
</Step>
|
|
411
|
-
<Step title="Second Step">
|
|
412
|
-
This is the second step in the process.
|
|
413
|
-
</Step>
|
|
414
|
-
</Steps>
|
|
415
|
-
```
|
|
206
|
+
## References and Links
|
|
416
207
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
</Step>
|
|
424
|
-
</Steps>
|
|
425
|
-
|
|
426
|
-
### Icons
|
|
427
|
-
|
|
428
|
-
```mdx
|
|
429
|
-
<Col rows={2}>
|
|
430
|
-
<Icon icon="Code" />
|
|
431
|
-
<Icon icon="FileText" />
|
|
432
|
-
<Icon icon="CheckCircle" />
|
|
433
|
-
</Col>
|
|
434
|
-
```
|
|
208
|
+
- [Morphik Console Guide](https://morphik.ai/docs/getting-started/first-steps-and-validation/using-the-morphik-console)
|
|
209
|
+
- [Morphik Python SDK](https://morphik.ai/docs/sdks/python/README)
|
|
210
|
+
- [Multimodal Search Guide](https://morphik.ai/docs/guides/core-workflows/multimodal-search)
|
|
211
|
+
- [Knowledge Graph Guide](https://morphik.ai/docs/guides/knowledge-graphs/build-knowledge-graph)
|
|
212
|
+
- [Cache Augmented Generation Guide](https://morphik.ai/docs/guides/integrations-and-caching/cache-augmentation)
|
|
213
|
+
- [Morphik Agent Source Code](https://github.com/morphik-org/morphik-core/blob/main/core/agent.py)
|
|
435
214
|
|
|
436
|
-
<
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
<Icon icon="CheckCircle" />
|
|
440
|
-
</Row>
|
|
215
|
+
<Tip>
|
|
216
|
+
Engage with the Morphik Discord community for live support and tips on using conversational AI effectively.
|
|
217
|
+
</Tip>
|
package/package.json
CHANGED
package/src/plugins/sanitize.ts
CHANGED
|
@@ -42,7 +42,37 @@ function isInsideCodeBlock(code: string, idx: number): boolean {
|
|
|
42
42
|
return codeBlockMatches ? codeBlockMatches.length % 2 === 1 : false;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
//
|
|
45
|
+
// Helper: checks if a known component tag has a matching closing tag
|
|
46
|
+
function hasMatchingClosingTag(code: string, tagName: string, openingTagOffset: number): boolean {
|
|
47
|
+
// Simple approach: look for the next occurrence of either an opening or closing tag of the same type
|
|
48
|
+
const afterOpening = code.slice(openingTagOffset + `<${tagName}>`.length);
|
|
49
|
+
|
|
50
|
+
// Find the first occurrence of either opening or closing tag
|
|
51
|
+
const nextOpeningMatch = afterOpening.match(new RegExp(`<${tagName}>`, 'i'));
|
|
52
|
+
const nextClosingMatch = afterOpening.match(new RegExp(`</${tagName}>`, 'i'));
|
|
53
|
+
|
|
54
|
+
// If no closing tag found at all
|
|
55
|
+
if (!nextClosingMatch) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const nextOpeningIndex = nextOpeningMatch ? nextOpeningMatch.index! : Infinity;
|
|
60
|
+
const nextClosingIndex = nextClosingMatch ? nextClosingMatch.index! : Infinity;
|
|
61
|
+
|
|
62
|
+
// If the closing tag comes before any other opening tag, this tag is properly closed
|
|
63
|
+
if (nextClosingIndex < nextOpeningIndex) {
|
|
64
|
+
// Check if the closing tag is inside a code block
|
|
65
|
+
const closingTagOffset = openingTagOffset + `<${tagName}>`.length + nextClosingIndex;
|
|
66
|
+
if (isInsideCodeBlock(code, closingTagOffset)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return false; // Another opening tag comes before the closing tag, so this one is not properly closed
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Allow any <[a-z][a-z0-9]*> tag inside code blocks to be left as-is (not parsed as JSX).
|
|
46
76
|
export function preprocessMdxTags() {
|
|
47
77
|
return {
|
|
48
78
|
name: 'preprocess-mdx-tags',
|
|
@@ -60,12 +90,25 @@ export function preprocessMdxTags() {
|
|
|
60
90
|
if (isInsideCodeBlock(processed, offset)) {
|
|
61
91
|
return match;
|
|
62
92
|
}
|
|
63
|
-
|
|
93
|
+
|
|
94
|
+
// If known component, check if it has a closing tag
|
|
64
95
|
if (KNOWN_COMPONENTS.includes(tag)) {
|
|
96
|
+
// If it doesn't have a matching closing tag, treat it as text
|
|
97
|
+
if (!hasMatchingClosingTag(processed, tag, offset)) {
|
|
98
|
+
return `\`<${tag}>\``;
|
|
99
|
+
}
|
|
100
|
+
// Otherwise, leave as-is for proper JSX parsing
|
|
65
101
|
return match;
|
|
66
102
|
}
|
|
67
|
-
|
|
68
|
-
|
|
103
|
+
|
|
104
|
+
// If already inside backticks, do not wrap again
|
|
105
|
+
// Find the start of the line up to the match
|
|
106
|
+
const before = processed.slice(0, offset);
|
|
107
|
+
// Count the number of backticks before this tag
|
|
108
|
+
const backtickMatches = before.match(/`+/g);
|
|
109
|
+
// If the number of backticks is odd, we're inside a backtick span
|
|
110
|
+
const insideBackticks = backtickMatches ? backtickMatches.reduce((acc, s) => acc + s.length, 0) % 2 === 1 : false;
|
|
111
|
+
if (insideBackticks) {
|
|
69
112
|
return match;
|
|
70
113
|
}
|
|
71
114
|
// Otherwise, wrap in backticks to prevent JSX parsing
|