Minor refinements and more comments

This commit is contained in:
Edward Donner
2025-02-10 06:40:21 -05:00
parent 103c770fb3
commit d7834d0033
7 changed files with 367 additions and 285 deletions

View File

@@ -300,6 +300,7 @@
"source": [
"# Claude 3.5 Sonnet again\n",
"# Now let's add in streaming back results\n",
"# If the streaming looks strange, then please see the note below this cell!\n",
"\n",
"result = claude.messages.stream(\n",
" model=\"claude-3-5-sonnet-latest\",\n",
@@ -316,6 +317,27 @@
" print(text, end=\"\", flush=True)"
]
},
{
"cell_type": "markdown",
"id": "dd1e17bc-cd46-4c23-b639-0c7b748e6c5a",
"metadata": {},
"source": [
"## A rare problem with Claude streaming on some Windows boxes\n",
"\n",
"2 students have noticed a strange thing happening with Claude's streaming into Jupyter Lab's output -- it sometimes seems to swallow up parts of the response.\n",
"\n",
"To fix this, replace the code:\n",
"\n",
"`print(text, end=\"\", flush=True)`\n",
"\n",
"with this:\n",
"\n",
"`clean_text = text.replace(\"\\n\", \" \").replace(\"\\r\", \" \")` \n",
"`print(clean_text, end=\"\", flush=True)`\n",
"\n",
"And it should work fine!"
]
},
{
"cell_type": "code",
"execution_count": null,