fix: update all examples to use stream() instead of receive()
- dungeon-master, economics-seminar, research-team all updated - Also improved tool output display in dungeon-master 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com>
This commit is contained in:
@@ -191,14 +191,17 @@ export async function chat(
|
||||
let response = '';
|
||||
const printer = onOutput || createStreamPrinter();
|
||||
|
||||
for await (const msg of session.receive()) {
|
||||
let lastToolName = '';
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
printer(msg.content);
|
||||
} else if (msg.type === 'tool_call') {
|
||||
console.log(`\n${COLORS.system}[Using ${msg.name}...]${COLORS.reset}`);
|
||||
} else if (msg.type === 'tool_result') {
|
||||
console.log(`${COLORS.system}[Done]${COLORS.reset}\n`);
|
||||
lastToolName = '';
|
||||
} else if (msg.type === 'tool_call' && 'toolName' in msg) {
|
||||
if (msg.toolName !== lastToolName) {
|
||||
console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`);
|
||||
lastToolName = msg.toolName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ Be aggressive. Be dismissive. Show intellectual contempt if warranted. You've se
|
||||
await session.send(prompt);
|
||||
|
||||
let response = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
onOutput(msg.content);
|
||||
@@ -215,7 +215,7 @@ Keep it to 2-3 brutal sentences.`;
|
||||
await session.send(prompt);
|
||||
|
||||
let response = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
onOutput(msg.content);
|
||||
|
||||
@@ -172,7 +172,7 @@ Start by announcing your chosen topic, then research it, then present.`;
|
||||
await session.send(prompt);
|
||||
|
||||
let response = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
onOutput(msg.content);
|
||||
@@ -208,7 +208,7 @@ Please respond to this question. Be direct, cite evidence where relevant, and de
|
||||
await session.send(prompt);
|
||||
|
||||
let response = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
onOutput(msg.content);
|
||||
|
||||
@@ -241,7 +241,7 @@ app.post('/research', async (req, res) => {
|
||||
await researcher.send(`Research: ${query}`);
|
||||
|
||||
let result = '';
|
||||
for await (const msg of researcher.receive()) {
|
||||
for await (const msg of researcher.stream()) {
|
||||
if (msg.type === 'assistant') result += msg.content;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ Confirm when complete.`;
|
||||
let success = false;
|
||||
let response = '';
|
||||
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
process.stdout.write('.'); // Progress indicator
|
||||
@@ -229,7 +229,7 @@ Update your memory with insights, then summarize your reflection.`;
|
||||
await session.send(prompt);
|
||||
|
||||
let reflection = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
reflection += msg.content;
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ Find at least ${config.sourcesCount} high-quality sources, then confirm completi
|
||||
let success = false;
|
||||
let response = '';
|
||||
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
process.stdout.write('.'); // Progress indicator
|
||||
@@ -229,7 +229,7 @@ Update your memory blocks with any insights, then summarize your reflection.`;
|
||||
await session.send(prompt);
|
||||
|
||||
let reflection = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
reflection += msg.content;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ Write the complete report to the output file, then confirm completion.`;
|
||||
let success = false;
|
||||
let response = '';
|
||||
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
response += msg.content;
|
||||
process.stdout.write('.'); // Progress indicator
|
||||
@@ -264,7 +264,7 @@ Update your memory blocks, then summarize your reflection.`;
|
||||
await session.send(prompt);
|
||||
|
||||
let reflection = '';
|
||||
for await (const msg of session.receive()) {
|
||||
for await (const msg of session.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
reflection += msg.content;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ async function main() {
|
||||
);
|
||||
|
||||
let researcherResponse = '';
|
||||
for await (const msg of researcher.receive()) {
|
||||
for await (const msg of researcher.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
researcherResponse += msg.content;
|
||||
process.stdout.write('.');
|
||||
@@ -100,7 +100,7 @@ async function main() {
|
||||
);
|
||||
|
||||
let analystResponse = '';
|
||||
for await (const msg of analyst.receive()) {
|
||||
for await (const msg of analyst.stream()) {
|
||||
if (msg.type === 'assistant') {
|
||||
analystResponse += msg.content;
|
||||
process.stdout.write('.');
|
||||
|
||||
Reference in New Issue
Block a user