Last active
January 14, 2025 20:09
-
-
Save jamessdixon/cf5861f476137b1f743e44efdc42e018 to your computer and use it in GitHub Desktop.
prompt_generation
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"import os \n", | |
"import base64\n", | |
"from openai import AzureOpenAI " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\"Close-up image of a residential water pipe showing common types of damage. The pipe may have visible cracks, rust, corrosion, or small punctures, with water leaking or dripping from the affected area. The background includes a typical household setting, such as a basement or under-sink cabinet, with additional plumbing components or tools visible in soft focus. The image is well-lit to emphasize the texture and extent of the damage on the pipe surface.\"\n" | |
] | |
} | |
], | |
"source": [ | |
"endpoint = \"https://XXXXX.openai.azure.com/\"\n", | |
"deployment = \"gpt-4o\"\n", | |
"subscription_key = \"XXXXX\" \n", | |
"\n", | |
"client = AzureOpenAI( \n", | |
" azure_endpoint=endpoint, \n", | |
" api_key=subscription_key, \n", | |
" api_version=\"2024-05-01-preview\", \n", | |
")\n", | |
" \n", | |
"chat_prompt = [\n", | |
" {\n", | |
" \"role\": \"system\",\n", | |
" \"content\": [\n", | |
" {\n", | |
" \"type\": \"text\",\n", | |
" \"text\": \"You are an AI assistant that helps people create prompts that can be fed into a large vision model\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"role\": \"user\",\n", | |
" \"content\": [\n", | |
" {\n", | |
" \"type\": \"text\",\n", | |
" \"text\": \"Create a prompt for a residental water pipe with common damage\"\n", | |
" }\n", | |
" ]\n", | |
" },\n", | |
" {\n", | |
" \"role\": \"assistant\",\n", | |
" \"content\": [\n", | |
" {\n", | |
" \"type\": \"text\",\n", | |
" \"text\": \"\\\"Photograph of a residential water pipe installed in a typical household setting. The pipe is visibly damaged, showing common issues such as rust, corrosion, cracks, or small leaks with water droplets forming or dripping. The background includes a basement or utility room environment, with tools or other plumbing fixtures nearby for context. The scene is well-lit, focusing on the damaged area of the pipe for clarity and detail.\\\"\"\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"] \n", | |
" \n", | |
"messages = chat_prompt \n", | |
"completion = client.chat.completions.create( \n", | |
" model=deployment, \n", | |
" messages=messages, \n", | |
" max_tokens=800, \n", | |
" temperature=0.7, \n", | |
" top_p=0.95, \n", | |
" frequency_penalty=0, \n", | |
" presence_penalty=0, \n", | |
" stop=None, \n", | |
" stream=False\n", | |
")\n", | |
"\n", | |
"\n", | |
"data = json.loads(completion.to_json())\n", | |
"content = data['choices'][0][\"message\"][\"content\"]\n", | |
"print(content)\n", | |
" " | |
] | |
} | |
], | |
"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.11.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment