Spaces:
Sleeping
Sleeping
File size: 2,289 Bytes
5fdb69e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "ce3db287-8661-4649-a599-cba0edd115b1",
"metadata": {},
"outputs": [],
"source": [
"\n",
"import os\n",
"import requests\n",
"from dotenv import load_dotenv\n",
"from bs4 import BeautifulSoup\n",
"from IPython.display import Markdown, display\n",
"from openai import OpenAI\n",
"\n",
"openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n",
"system_prompt = \"You are an assistant that analyzes the contents of an email\"\n",
"user_prompt = \"Provide a short subject line which aligns with the body of the email\"\n",
"email_content = \"\"\"\n",
"From: [email protected]\n",
"To: [email protected]\n",
"Subject: \n",
"\n",
"Hi Team,\n",
"\n",
"This email provides an update on Project Alpha. We've successfully completed Phase 1, which involved, and would like to thank all the \n",
"team for the great work, and looking forward to the same energy and rigor for Phase 2 too. \n",
"\n",
"Keep up the good work!! \n",
"\n",
"Thanks,\n",
"James\n",
"\"\"\"\n",
"\n",
"# Step 2: Make the messages list\n",
"\n",
"messages = [\n",
" {\"role\": \"system\", \"content\": system_prompt},\n",
" {\"role\": \"user\", \"content\": user_prompt+email_content}\n",
"]\n",
"\n",
"# Step 3: Call OpenAI\n",
"\n",
"#response =\n",
"response = openai.chat.completions.create(model=\"llama3.2\", messages=messages)\n",
"\n",
"# Step 4: print the result\n",
"print(response.choices[0].message.content)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "526b87f1-aa38-44d4-9609-292a4f4d72a9",
"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.11.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|