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
95b99db1
Commit
95b99db1
authored
1 year ago
by
Elliot Kang
Browse files
Options
Downloads
Patches
Plain Diff
example fix
parent
1b13395e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/simple/llmStream.ts
+6
-13
6 additions, 13 deletions
apps/simple/llmStream.ts
with
6 additions
and
13 deletions
apps/simple/llmStream.ts
+
6
−
13
View file @
95b99db1
import
{
ChatMessage
,
OpenAI
,
SimpleChatEngine
}
from
"
llamaindex
"
;
import
{
ChatMessage
,
OpenAI
,
Anthropic
,
SimpleChatEngine
}
from
"
llamaindex
"
;
import
{
stdin
as
input
,
stdout
as
output
}
from
"
node:process
"
;
import
readline
from
"
node:readline/promises
"
;
...
...
@@ -7,7 +7,8 @@ async function main() {
Where is Istanbul?
`
;
const
llm
=
new
OpenAI
({
model
:
"
gpt-3.5-turbo
"
,
temperature
:
0.1
});
// const llm = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.1 });
const
llm
=
new
Anthropic
();
const
message
:
ChatMessage
=
{
content
:
query
,
role
:
"
user
"
};
var
accumulated_result
:
string
=
""
;
...
...
@@ -20,17 +21,6 @@ Where is Istanbul?
//either an AsyncGenerator or a Response.
// Omitting the streaming flag automatically sets streaming to false
// const stream2 = await llm.chat([message], undefined);
const
stream
=
await
llm
.
complete
(
query
,
undefined
,
true
);
for
await
(
const
part
of
stream
)
{
//This only gives you the string part of a stream
console
.
log
(
part
);
accumulated_result
+=
part
;
}
accumulated_result
=
""
;
const
chatEngine
:
SimpleChatEngine
=
new
SimpleChatEngine
();
const
rl
=
readline
.
createInterface
({
input
,
output
});
...
...
@@ -41,6 +31,9 @@ Where is Istanbul?
break
;
}
//Case 1: .chat(query, undefined, true) => Stream
//Case 2: .chat(query, undefined, false) => Response object
//Case 3: .chat(query, undefined) => Response object
const
chatStream
=
await
chatEngine
.
chat
(
query
,
undefined
,
true
);
for
await
(
const
part
of
chatStream
){
process
.
stdout
.
write
(
part
);
...
...
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