-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9badd2b
commit d64e0a4
Showing
3 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import openai" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from dotenv import dotenv_values\n", | ||
"config = dotenv_values(\".env\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"openai.api_key = config[\"OPENAI_API_KEY\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"reply = openai.ChatCompletion.create(\n", | ||
" model=\"gpt-3.5-turbo\",\n", | ||
" messages=[\n", | ||
" { \"role\": \"user\", \"content\": \"tell me a joke\" }\n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(reply.choices[O].message.content)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# https://platform.openai.com/docs/guides/chat/chat-vs-completions\n", | ||
"\n", | ||
"openai.ChatCompletion.create(\n", | ||
" model=\"gpt-3.5-turbo\",\n", | ||
" messages=[\n", | ||
" # {\"role\": \"system\", \"content\": \"You are a helpful assistant that translates English to French.\"},\n", | ||
" # {\"role\": \"user\", \"content\": 'Translate the following English text to French: \"I want a dog\"'}\n", | ||
" {\"role\": \"user\", \"content\": 'Translate the following English text to French: \"I want a dog\"'}\n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"openai.ChatCompletion.create(\n", | ||
" model=\"gpt-3.5-turbo\",\n", | ||
" messages=[\n", | ||
" {\"role\": \"system\", \"content\": \"You are a helpful assistant that classifies the sentiment in text as either positive, neutral, or negative.\"},\n", | ||
" {\"role\": \"user\", \"content\": 'Classify the sentiment in the following text: \"I really love chicken biryani\"'},\n", | ||
" {\"role\": \"assistant\", \"content\": \"Positive\" },\n", | ||
" {\"role\": \"user\", \"content\": 'Classify the sentiment in the following text: \"I have a complicated relationship with cat\"'},\n", | ||
" ]\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from IPython.display import Markdown, display\n", | ||
"import json\n", | ||
"\n", | ||
"def display_colors(colors):\n", | ||
" display(Markdown(\" \".join(\n", | ||
" f'<span style=\"color: {color}\">{chr(9608) * 4}</span>'\n", | ||
" for color in colors\n", | ||
" )))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_and_render_colors(query):\n", | ||
" messages = [\n", | ||
" { \"role\": \"system\", \"content\": \"You are a color palette generating assistant that responds to text prompts for color palettes. You should generate color palettes that fit the theme, mood, or instructions in the prompt. The palettes should be between 2 and 8 colors.\" },\n", | ||
" { \"role\": \"user\", \"content\": \"Convert the following verbal description of a color palette into a list of colors: The Meditation\" },\n", | ||
" { \"role\": \"assistant\", \"content\": '[\"#594F4F\", \"#A1887F\", \"#BCAAA4\", \"#81C784\", \"#455A64\"]' },\n", | ||
" { \"role\": \"user\", \"content\": \"Convert the following verbal description of a color palette into a list of colors: The Mediterranean Sea\" },\n", | ||
" { \"role\": \"assistant\", \"content\": '[\"#1A237E\", \"#1565C0\", \"#1E88E5\", \"#90CAF9\", \"#E1F5FE\"]' },\n", | ||
" { \"role\": \"user\", \"content\": f\"Convert the following verbal description of a color palette into a list of colors: {query}\"}\n", | ||
" ]\n", | ||
"\n", | ||
" response = openai.ChatCompletion.create(\n", | ||
" model=\"gpt-3.5-turbo\",\n", | ||
" messages=messages,\n", | ||
" max_tokens=100 # default to infinite, provide it!\n", | ||
" )\n", | ||
"\n", | ||
" colors = json.loads(response[\"choices\"][0].message.content)\n", | ||
" display_colors(colors)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/markdown": [ | ||
"<span style=\"color: #4285F4\">████</span> <span style=\"color: #DB4437\">████</span> <span style=\"color: #F4B400\">████</span> <span style=\"color: #0F9D58\">████</span>" | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.Markdown object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"get_and_render_colors(\"4 google brand colors\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"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.10.5" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters