Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
LlamaIndexTS
Commits
d1db2189
Unverified
Commit
d1db2189
authored
1 month ago
by
Marcus Schiesser
Committed by
GitHub
1 month ago
Browse files
Options
Downloads
Patches
Plain Diff
docs: update starter to ask for api key (#1661)
parent
2c5b4030
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/starter.ts
+12
-2
12 additions, 2 deletions
examples/starter.ts
with
12 additions
and
2 deletions
examples/starter.ts
+
12
−
2
View file @
d1db2189
...
@@ -3,6 +3,18 @@ import fs from "node:fs/promises";
...
@@ -3,6 +3,18 @@ import fs from "node:fs/promises";
import
{
createInterface
}
from
"
node:readline/promises
"
;
import
{
createInterface
}
from
"
node:readline/promises
"
;
async
function
main
()
{
async
function
main
()
{
const
rl
=
createInterface
({
input
:
process
.
stdin
,
output
:
process
.
stdout
});
if
(
!
process
.
env
.
OPENAI_API_KEY
)
{
console
.
log
(
"
OpenAI API key not found in environment variables.
"
);
console
.
log
(
"
You can get an API key at https://platform.openai.com/account/api-keys
"
,
);
process
.
env
.
OPENAI_API_KEY
=
await
rl
.
question
(
"
Please enter your OpenAI API key:
"
,
);
}
const
path
=
"
node_modules/llamaindex/examples/abramov.txt
"
;
const
path
=
"
node_modules/llamaindex/examples/abramov.txt
"
;
const
essay
=
await
fs
.
readFile
(
path
,
"
utf-8
"
);
const
essay
=
await
fs
.
readFile
(
path
,
"
utf-8
"
);
const
document
=
new
Document
({
text
:
essay
,
id_
:
path
});
const
document
=
new
Document
({
text
:
essay
,
id_
:
path
});
...
@@ -10,8 +22,6 @@ async function main() {
...
@@ -10,8 +22,6 @@ async function main() {
const
index
=
await
VectorStoreIndex
.
fromDocuments
([
document
]);
const
index
=
await
VectorStoreIndex
.
fromDocuments
([
document
]);
const
queryEngine
=
index
.
asQueryEngine
();
const
queryEngine
=
index
.
asQueryEngine
();
const
rl
=
createInterface
({
input
:
process
.
stdin
,
output
:
process
.
stdout
});
console
.
log
(
console
.
log
(
"
Try asking a question about the essay: https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/examples/abramov.txt
"
,
"
Try asking a question about the essay: https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/examples/abramov.txt
"
,
"
\n
Example: When did the author graduate from high school?
"
,
"
\n
Example: When did the author graduate from high school?
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment