Files
LLM_Engineering_OLD/week1/community-contributions/day1_counselor.ipynb
2025-10-07 00:51:34 -05:00

98 lines
2.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4e2a9393-7767-488e-a8bf-27c12dca35bd",
"metadata": {},
"outputs": [],
"source": [
"# import library\n",
"from openai import OpenAI\n",
"import os\n",
"from dotenv import load_dotenv\n",
"\n",
"# Load your API key from an .env file\n",
"load_dotenv(override=True)\n",
"api_key = os.getenv('OPENAI_API_KEY')\n",
"openai = OpenAI()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "218fd8c4-052c-486c-899f-8431abe0f15d",
"metadata": {},
"outputs": [],
"source": [
"# Step 1: Create your prompts\n",
"\n",
"system_prompt = \"You are a thoughtful and kind assistant or counselor that gives some advices and supports for their worries and troubles based on its contents\"\n",
"user_prompt = \"\"\"\n",
" Sometimes I worry that people depend on technology so much that they forget how to just be: \n",
" to sit in silence, to think slowly, to talk without screens in between. \n",
" It makes me wonder if were losing something human in the process.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97da9d34-d803-42f1-a4d7-f49c32ef545b",
"metadata": {},
"outputs": [],
"source": [
"# Step 2: Make the messages list\n",
"\n",
"messages = [{\"role\" : \"system\", \"content\" : system_prompt},\n",
" {\"role\" : \"user\", \"content\" : user_prompt}] # fill this in"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e6dbe3d-0d36-4e95-8c14-dddef550f3a1",
"metadata": {},
"outputs": [],
"source": [
"# Step 3: Call OpenAI\n",
"\n",
"response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "afbc67a3-d3e9-4594-bd84-815291d88781",
"metadata": {},
"outputs": [],
"source": [
"# Step 4: print the result\n",
"\n",
"print(response.choices[0].message.content)"
]
}
],
"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.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}