Created
January 13, 2024 17:12
-
-
Save lucasastorian/4305a54afd7508540de6b4a99648e659 to your computer and use it in GitHub Desktop.
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
| import os | |
| import json | |
| import openai | |
| openai.api_key = os.environ['OPENAI_API_KEY'] | |
| # My Details | |
| NAME = "Lucas Astorian" | |
| FIRST_NAME = "Lucas" | |
| EMAIL = "lucas@distcorp.com" | |
| # Email details | |
| SUBJECT = "Lucas—I'm trying to land on top of your inbox!" | |
| SENDER = """John Williams <john.williams@megacorp.com""" | |
| CONTENT = """Hi Lucas, | |
| I'm reaching out to identify the person for custom software development needs at DistCorp. | |
| Our expertise covers the software development cycle, from ideation to architecture to launch. | |
| Our team excels in creating solutions using the technology stacks your company typically employs. | |
| Could we arrange a brief call to explore collaboration? If not the right contact, kindly direct me. | |
| Thank you, | |
| John Williams | |
| Manager Customer Success""" | |
| # Format the email | |
| formatted_email = f"""Subject: {SUBJECT}\n From: {SENDER}\n\n {CONTENT}""" | |
| # System prompt | |
| system_prompt = f"""You are the personal assistant of {NAME} <{EMAIL}>. {FIRST_NAME} has just received | |
| an email from {SENDER}, and you've been tasked with deciding whether {FIRST_NAME} | |
| needs to respond to this email. Respond 'Yes' if {FIRST_NAME} needs to respond | |
| to the email and 'No' if they don't. Respond in Valid JSON. | |
| """ | |
| # Function | |
| function = { | |
| 'name': 'EmailRequiresResponse', | |
| 'description': f"Decide whether the email from {SENDER} requires a response", | |
| 'parameters': { | |
| 'title': f"EmailRequiresResponse", | |
| 'description': f"Decide whether the email from {SENDER} requires a response", | |
| 'type': 'object', | |
| 'properties': { | |
| 'respond': {'title': 'Respond', | |
| 'description': f"Specify whether {FIRST_NAME} needs to respond to the email from {SENDER} with 'Yes' or 'No'.", | |
| 'type': 'string', 'enum': ['Yes', 'No']}, | |
| }, | |
| 'required': ['respond'], | |
| }, | |
| } | |
| messages = [{"role": "system", "content": system_prompt}, | |
| {"role": "user", "name": "John", "content": formatted_email}] | |
| response = openai.chat.completions.create(model="gpt-3.5-turbo-1106", | |
| messages=messages, | |
| temperature=0.25, | |
| tools=[{"type": "function", "function": function}], | |
| tool_choice={"type": "function", "function": {"name": function['name']}}, | |
| response_format={"type": "json_object"}, | |
| timeout=60) | |
| arguments = json.loads(chat_completion.choices[0].message.tool_calls[0].function.arguments) | |
| respond = arguments['respond'] | |
| respond |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment