shukdevdatta123 commited on
Commit
c48ed59
·
verified ·
1 Parent(s): ab59bbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -5,24 +5,23 @@ import streamlit as st
5
  def generate_email(api_key, email_type, details):
6
  openai.api_key = api_key # Set OpenAI API key provided by the user
7
 
8
- prompt = f"""
9
- I need to write a professional email for the following situation:
10
- Email Type: {email_type}
11
- Details: {details}
12
- Please generate the body of the email, including suggestions for the subject line and sign-off. Ensure the email tone is professional and polite.
13
- """
14
 
15
  try:
16
- # Request to OpenAI API
17
- response = openai.Completion.create(
18
- engine="gpt-4o", # Using OpenAI's GPT-3 model (adjust for specific LLM as needed)
19
- prompt=prompt,
20
  max_tokens=1200,
21
  temperature=0.7
22
  )
23
 
24
  # Return the generated email content
25
- return response.choices[0].text.strip()
26
  except Exception as e:
27
  return f"Error: {str(e)}"
28
 
 
5
  def generate_email(api_key, email_type, details):
6
  openai.api_key = api_key # Set OpenAI API key provided by the user
7
 
8
+ # Define the conversation in the chat-based format
9
+ messages = [
10
+ {"role": "system", "content": "You are a helpful assistant that writes professional emails."},
11
+ {"role": "user", "content": f"I need to write a professional email for the following situation:\nEmail Type: {email_type}\nDetails: {details}\nPlease generate the body of the email, including suggestions for the subject line and sign-off. Ensure the email tone is professional and polite."}
12
+ ]
 
13
 
14
  try:
15
+ # Request to OpenAI API (using chat/completions endpoint)
16
+ response = openai.ChatCompletion.create(
17
+ model="gpt-4o", # You can replace this with any other chat-based model like `gpt-4`
18
+ messages=messages,
19
  max_tokens=1200,
20
  temperature=0.7
21
  )
22
 
23
  # Return the generated email content
24
+ return response.choices[0].message['content'].strip()
25
  except Exception as e:
26
  return f"Error: {str(e)}"
27