-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_aiml_TexttoEmail.py
57 lines (48 loc) · 1.6 KB
/
streamlit_aiml_TexttoEmail.py
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
import openai
from openai import OpenAI
import streamlit as st
from langchain import PromptTemplate
template = """
Below is an email that may be poorly worded.
Your goal is to:
- Properly format the email
Please start the email with a warm introduction. Add the introduction if you need to.
Below is the email:
EMAIL: {email}
RESPONSE:
"""
prompt = PromptTemplate(
input_variables=["email"],
template=template,
)
#api_key="c45e8e03e070469bbea48b070fd8eaf1"
st.markdown("## Enter Your Text To Convert to Email")
## Define Client for OpenAI
client = OpenAI(
#api_key=st.text_input(label="API Key ", type="password", placeholder="Ex: sk-2Cb8un4...", key="api_key_input"),
api_key="c45e8e03e070469bbea48b070fd8eaf1",
base_url="https://api.aimlapi.com",
)
input_text = st.text_area(label="Type your text here", placeholder="Your Text to Email...", key="email_input")
if len(input_text.split(" ")) > 700:
st.write("Please enter a shorter text up to a max of 700 words")
st.stop()
if input_text:
# if not api_key:
# st.warning('Enter your API Key.)', icon="🔥")
# st.stop()
prompt_with_template = prompt.format(email=input_text)
response = client.chat.completions.create(
model="gpt-4",
messages=[{
"role": "system",
"content": "You are an Email assistant who knows everything.",
},
{
"role": "user",
"content": prompt_with_template
}
],
)
message =response.choices[0].message.content
st.write(message)