mirror of
https://github.com/james-m-jordan/openai-cookbook.git
synced 2025-05-09 19:32:38 +00:00
simplify pretty print (#575)
This commit is contained in:
parent
5c1d46ade7
commit
9dad13d05b
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "3e67f200",
|
"id": "3e67f200",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -22,6 +23,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "64c85e26",
|
"id": "64c85e26",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -65,6 +67,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "69ee6a93",
|
"id": "69ee6a93",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -119,28 +122,22 @@
|
|||||||
" \"assistant\": \"blue\",\n",
|
" \"assistant\": \"blue\",\n",
|
||||||
" \"function\": \"magenta\",\n",
|
" \"function\": \"magenta\",\n",
|
||||||
" }\n",
|
" }\n",
|
||||||
" formatted_messages = []\n",
|
" \n",
|
||||||
" for message in messages:\n",
|
" for message in messages:\n",
|
||||||
" if message[\"role\"] == \"system\":\n",
|
" if message[\"role\"] == \"system\":\n",
|
||||||
" formatted_messages.append(f\"system: {message['content']}\\n\")\n",
|
" print(colored(f\"system: {message['content']}\\n\", role_to_color[message[\"role\"]]))\n",
|
||||||
" elif message[\"role\"] == \"user\":\n",
|
" elif message[\"role\"] == \"user\":\n",
|
||||||
" formatted_messages.append(f\"user: {message['content']}\\n\")\n",
|
" print(colored(f\"user: {message['content']}\\n\", role_to_color[message[\"role\"]]))\n",
|
||||||
" elif message[\"role\"] == \"assistant\" and message.get(\"function_call\"):\n",
|
" elif message[\"role\"] == \"assistant\" and message.get(\"function_call\"):\n",
|
||||||
" formatted_messages.append(f\"assistant: {message['function_call']}\\n\")\n",
|
" print(colored(f\"assistant: {message['function_call']}\\n\", role_to_color[message[\"role\"]]))\n",
|
||||||
" elif message[\"role\"] == \"assistant\" and not message.get(\"function_call\"):\n",
|
" elif message[\"role\"] == \"assistant\" and not message.get(\"function_call\"):\n",
|
||||||
" formatted_messages.append(f\"assistant: {message['content']}\\n\")\n",
|
" print(colored(f\"assistant: {message['content']}\\n\", role_to_color[message[\"role\"]]))\n",
|
||||||
" elif message[\"role\"] == \"function\":\n",
|
" elif message[\"role\"] == \"function\":\n",
|
||||||
" formatted_messages.append(f\"function ({message['name']}): {message['content']}\\n\")\n",
|
" print(colored(f\"function ({message['name']}): {message['content']}\\n\", role_to_color[message[\"role\"]]))\n"
|
||||||
" for formatted_message in formatted_messages:\n",
|
|
||||||
" print(\n",
|
|
||||||
" colored(\n",
|
|
||||||
" formatted_message,\n",
|
|
||||||
" role_to_color[messages[formatted_messages.index(formatted_message)][\"role\"]],\n",
|
|
||||||
" )\n",
|
|
||||||
" )"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "29d4e02b",
|
"id": "29d4e02b",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -204,6 +201,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "bfc39899",
|
"id": "bfc39899",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -242,6 +240,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "4c999375",
|
"id": "4c999375",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -280,6 +279,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "c14d4762",
|
"id": "c14d4762",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -318,6 +318,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "6172ddac",
|
"id": "6172ddac",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -356,6 +357,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "4b758a0a",
|
"id": "4b758a0a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -364,6 +366,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "412f79ba",
|
"id": "412f79ba",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -434,6 +437,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "3bd70e48",
|
"id": "3bd70e48",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -469,6 +473,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "b4482aee",
|
"id": "b4482aee",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -481,6 +486,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "f7654fef",
|
"id": "f7654fef",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -546,6 +552,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "77e6e5ea",
|
"id": "77e6e5ea",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -570,6 +577,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "ae73c9ee",
|
"id": "ae73c9ee",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -608,6 +616,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "da08c121",
|
"id": "da08c121",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user