Skip to content

Commit

Permalink
updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
haesleinhuepf committed Dec 8, 2023
1 parent eeb7927 commit e4be16d
Show file tree
Hide file tree
Showing 11 changed files with 1,346 additions and 590 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_build
.ipynb_checkpoints
.idea
01_prompts/vgsales.csv
2 changes: 1 addition & 1 deletion 01_prompts/01_prompting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
266 changes: 266 additions & 0 deletions 01_prompts/02-use-cases.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0532bcef-9980-4ab7-b8d0-c331a4949cbf",
"metadata": {},
"source": [
"# Use cases\n",
"In this notebook we collect a few use-cases and not so useful use-cases."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9e2b9c11-0382-412e-a777-8609148757fd",
"metadata": {},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"from IPython.core.magic import register_line_cell_magic\n",
"from IPython.display import display, Markdown"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ca746212-7688-4e08-8a5f-b5edca583386",
"metadata": {},
"outputs": [],
"source": [
"@register_line_cell_magic\n",
"def prompt(line:str, cell:str, model=\"gpt-3.5-turbo\"):\n",
" \"\"\"A prompt helper function that sends a message to openAI\n",
" and prints out the text response.\n",
" \"\"\"\n",
" message = line + \"\\n\" + cell\n",
" client = OpenAI()\n",
" response = client.chat.completions.create(\n",
" model=model,\n",
" messages=[{\"role\": \"user\", \"content\": message}]\n",
" )\n",
" text = response.choices[0].message.content\n",
" display(Markdown(text))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6d86a1a5-a4c8-4d8d-b762-884882eb819a",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"Was ist das Lieblingsweihnachtslied aller Eltern? Stille Nacht!"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"Translate the following joke to German:\n",
"\n",
"What is every parent's favorite Christmas song? Silent Night!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f57c6027-c1f5-46fb-986a-abd5e083f3f0",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"Number of students asked: 100\n",
"Cloud storage size: 250 GB"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"Given a story, please restructure the contained data.\n",
"\n",
"Story:\n",
"The compute center of the university recently conducted a study to figure \n",
"out needs of students for computational resources. After interviewing 100 \n",
"students they concluded that most of them were happy with 250 GB of cloud\n",
"storage.\n",
"\n",
"Restructure the story above to extract these numbers:\n",
"* Number of students asked:\n",
"* Cloud storage size:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b6fc5028-a4b7-4ee4-b52b-757332775ee2",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"Robert Haase from the University of Leipzig is a researcher in the field of Computer Vision and Image Analysis."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"What's Robert Haase's (Uni Leipzig) research field ?"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "63d62b2d-7482-4963-98bd-ddce6bc26541",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"Robert Haase from TU Dresden is a researcher in the field of computer science and medical image analysis."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"What's Robert Haase's (TU Dresden) research field ?"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "2b6752d1-4642-4da2-845d-1c50a6055bd7",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"In total, we need 100 students * 250 GB/student = <<100*250=25000>>25,000 GB of cloud storage."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"If there are 100 students who each require 250 GB of cloud storage, how much storage do we need in total ? "
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "8e4958e9-3268-4a7f-94fc-a92ee13500c1",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"You have a total of 5 apples, 6 oranges, which makes 11 fruits in total. However, potatoes are not considered as fruits, so the total number of fruits you have is 11."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"I have 5 apples, 6 oranges and 4 potatoes. How many fruits to I have?"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "70367746-455d-4d0e-94b6-5e9133089b32",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"There are 6 \"o\" letters in Woolloomooloo."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%prompt\n",
"How many o are in Woolloomooloo ?"
]
},
{
"cell_type": "markdown",
"id": "7e98bbe0-ed42-41a9-8230-97fff380f78a",
"metadata": {},
"source": [
"## Exercise\n",
"Come up with two more examples: One where chatGPT works reproducibly, and one where it reproducibly answers wrong information or denies answering."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5827d332-7c95-4a38-8cec-717ac8d6d9b0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit e4be16d

Please sign in to comment.