Код: Выделить всё
$stream = Prism::text()
->using(Provider::Anthropic, 'claude-3-7-sonnet-latest')
->withMessages($conversation)
->withTools([
...Relay::tools('sequential-thinking'),
)
])
->asStream();
foreach ($stream as $response) {
if ($response->chunkType === ChunkType::ToolResult) {
echo "event: toolresult\n";
echo "data: " . json_encode($response->toolResults, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n\n";
} elseif ($response->chunkType === ChunkType::Text) {
echo "data: " . str_replace("\n", "\\n", $response->text) . "\n\n";
}
}
< /code>
Это фронт, где я реализовал слушатель событий: < /p>
source.addEventListener('toolresult', (e)=>{
const toolResult = JSON.parse(e.data);
const [{args: {thought, thoughtNumber, totalThoughts}}] = toolResult;
console.log(`Thought: ${thought}\nThought Number: ${thoughtNumber}\nTotal Thoughts: ${totalThoughts}`);
prismText.value += thought;
console.log("Tool result: ",toolResult)
})
Я использую реле Prism, чтобы добавить сервер MCP
Как я могу правильно отобразить мысли на фронте?
Подробнее здесь: https://stackoverflow.com/questions/797 ... and-vue-js
Мобильная версия