Update expandTask to use streaming API calls to Claude
This commit is contained in:
@@ -769,31 +769,61 @@ Then continue with Subtask ${nextSubtaskId + 1}, and so on.
|
|||||||
|
|
||||||
log('info', "Calling Claude to generate subtasks...");
|
log('info', "Calling Claude to generate subtasks...");
|
||||||
|
|
||||||
const response = await anthropic.messages.create({
|
// Start loading indicator
|
||||||
max_tokens: CONFIG.maxTokens,
|
const loadingIndicator = startLoadingIndicator("Waiting for Claude to generate subtasks...");
|
||||||
model: CONFIG.model,
|
|
||||||
temperature: CONFIG.temperature,
|
let fullResponse = '';
|
||||||
messages: [
|
let streamingInterval = null;
|
||||||
{
|
|
||||||
role: "user",
|
try {
|
||||||
content: prompt
|
const stream = await anthropic.messages.create({
|
||||||
|
max_tokens: CONFIG.maxTokens,
|
||||||
|
model: CONFIG.model,
|
||||||
|
temperature: CONFIG.temperature,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: prompt
|
||||||
|
}
|
||||||
|
],
|
||||||
|
system: "You are a helpful assistant that generates detailed subtasks for software development tasks. Your subtasks should be specific, actionable, and help accomplish the main task. Format each subtask with a title, description, dependencies, and acceptance criteria.",
|
||||||
|
stream: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update loading indicator to show streaming progress
|
||||||
|
let dotCount = 0;
|
||||||
|
streamingInterval = setInterval(() => {
|
||||||
|
readline.cursorTo(process.stdout, 0);
|
||||||
|
process.stdout.write(`Receiving streaming response from Claude${'.'.repeat(dotCount)}`);
|
||||||
|
dotCount = (dotCount + 1) % 4;
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
// Process the stream
|
||||||
|
for await (const chunk of stream) {
|
||||||
|
if (chunk.type === 'content_block_delta' && chunk.delta.text) {
|
||||||
|
fullResponse += chunk.delta.text;
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
system: "You are a helpful assistant that generates detailed subtasks for software development tasks. Your subtasks should be specific, actionable, and help accomplish the main task. Format each subtask with a title, description, dependencies, and acceptance criteria."
|
|
||||||
});
|
clearInterval(streamingInterval);
|
||||||
|
|
||||||
log('info', "Received response from Claude API!");
|
// Stop loading indicator
|
||||||
|
stopLoadingIndicator(loadingIndicator);
|
||||||
// Extract the text content from the response
|
log('info', "Received complete response from Claude API!");
|
||||||
const textContent = response.content[0].text;
|
|
||||||
|
// Log the first part of the response for debugging
|
||||||
// Log the first part of the response for debugging
|
log('debug', "Response preview:", fullResponse.substring(0, 200) + "...");
|
||||||
log('debug', "Response preview:", textContent.substring(0, 200) + "...");
|
|
||||||
|
// Parse the subtasks from the text response
|
||||||
// Parse the subtasks from the text response
|
const subtasks = parseSubtasksFromText(fullResponse, nextSubtaskId, numSubtasks);
|
||||||
const subtasks = parseSubtasksFromText(textContent, nextSubtaskId, numSubtasks);
|
|
||||||
|
return subtasks;
|
||||||
return subtasks;
|
} catch (error) {
|
||||||
|
if (streamingInterval) clearInterval(streamingInterval);
|
||||||
|
stopLoadingIndicator(loadingIndicator);
|
||||||
|
log('error', "Error during streaming response:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user