Skip to content
Snippets Groups Projects
Unverified Commit 89336e4d authored by Marcus Schiesser's avatar Marcus Schiesser Committed by GitHub
Browse files

feat: add deno jupyter examples (#428)

parent a94f7473
No related branches found
No related tags found
No related merge requests found
.ipynb_checkpoints/
# Jupyter examples
## Preparation
1. Install Deno, e.g. on macOS:
```
brew install deno
```
2. Install Jupyter
```
pip3 install jupyterlab
```
3. Install Deno kernel
```
deno jupyter --unstable --install
```
4. Run Jupyter
```
jupyter lab
```
## Run examples
Then you can open in Jupyter any of the examples in this directory.
%% Cell type:code id:8be89595-8885-4d5e-b1da-1df04eda5c7a tags:
``` typescript
import {
Document,
SimpleNodeParser
} from "npm:llamaindex";
```
%% Cell type:code id:65de03f9-455a-4c59-9089-093cb6998af7 tags:
``` typescript
const nodeParser = new SimpleNodeParser();
const nodes = nodeParser.getNodesFromDocuments([
new Document({ text: "I am 10 years old. John is 20 years old." }),
]);
console.log(nodes);
```
%% Output
[
TextNode {
id_: "1b2ab25e-562a-4821-bdde-860bd23121c1",
metadata: {},
excludedEmbedMetadataKeys: [],
excludedLlmMetadataKeys: [],
relationships: {
SOURCE: {
nodeId: "0cb8de0e-845f-4e73-a7bd-f04426aacfed",
metadata: {},
hash: "jatVVXETDFjV2fV1/fbTrdpY6ZGnSYekq9m1X/Ff1qs="
}
},
hash: "zVyeDsfMwWH1CqK2269o5uzGWl/DpIWO4ZcVCuyENi4=",
text: "I am 10 years old. John is 20 years old.",
metadataSeparator: "\n"
}
]
%% Cell type:code id:fc0ec12f-2062-47af-916d-7c77ca39433a tags:
``` typescript
```
%% Cell type:code id:8be89595-8885-4d5e-b1da-1df04eda5c7a tags:
``` typescript
import {
Document,
VectorStoreIndex
} from "npm:llamaindex";
```
%% Cell type:code id:65de03f9-455a-4c59-9089-093cb6998af7 tags:
``` typescript
// Create Document object with essay
const resp = await fetch('https://raw.githubusercontent.com/run-llama/LlamaIndexTS/main/packages/core/examples/abramov.txt');
const text = await resp.text();
const document = new Document({ text });
// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.fromDocuments([document]);
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query: "What did the author do in college?",
});
// Output response
console.log(response.toString());
```
%% Output
In college, the author studied subjects such as linear algebra and physics, but did not find them particularly interesting. They also slacked off and skipped lectures, leading to gaps in their knowledge. They had a negative experience with their English classes and became resentful and suspicious of higher education. They eventually dropped out of college and did not return until five years later to pick up their papers.
%% Cell type:code id:fc0ec12f-2062-47af-916d-7c77ca39433a tags:
``` typescript
```
%% Cell type:code id:68bdd292-5cf7-46e0-8646-51be1f070ad6 tags:
``` typescript
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment