"system_prompt = \"You are a coding tutor. If the user asks you a question, answer it to the point. If you are asked to create a code snippet, generate the code in Python and then explain it shortly.\""
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 53,
"id": "3f0d0137-52b0-47a8-81a8-11a90a010798",
"id": "58f098cb-4b4e-4394-b0b5-29db88e9101c",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# here is the question; type over this to ask something new\n",
" How can I display python code properly while streaming the answer from openai? Create a code snippet for this. The streaming should happen in the code canvas.\n"
]
}
],
"source": [
"# here is the question; type over this to ask something new\n",
"question = input()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "2bc093fa-b2ff-47e9-8ea8-e41499385116",
"metadata": {},
"outputs": [],
"source": [
"# question = \"\"\"How can I display python code properly while streaming the answer from openai? Create a code snippet for this. The streaming should happen in the code canvas.\"\"\""
"To display Python code properly with OpenAI's chat interface, you'll need to use the `code` formatting in the response format provided by the API endpoint. \n",
"\n",
"Here's an example of how you can modify the API request URL to include the formatted code:\n",
"However, the most convenient way to display the code is by using the `code` directive directly in your chat prompt. OpenAI will automatically format and highlight your code."