-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (46 loc) · 1.53 KB
/
main.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
58
59
60
61
from langchain import PromptTemplate
from langchain.llms import OpenAI
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/socials')
def lang_socials():
data = request.json
tone = data['tone']
dialect = data['dialect']
sentence = data['sentence']
template = """
Below is a sentence that could be bad.
Your goal is to:
- To make it a social media post to
- Convert the input text to a specified tone
- Convert the input text to a specified dialect
Here are some Tone example
- If aggressive the post will sound aggressive
- If calm the post will sound calm
- If cool the post will sound cool
- If scary the post will sound scary
Dialects can be any languages such as English, Filipino etc..
Below is the post, tone, and dialect:
TONE: {tone}
DIALECT: {dialect}
POST: {sentence}
YOUR {dialect} RESPONSE:
"""
prompt = PromptTemplate(
input_variables=["tone", "dialect", "sentence"],
template=template,
)
llm = load_LLM()
send_prompt = prompt.format(tone=tone, dialect=dialect, sentence=sentence)
results = llm(send_prompt)
response = {
'status_code' : 200,
'result' : results
}
return jsonify(response)
def load_LLM():
# Make sure your openai_api_key is set as an environment variable
llm = OpenAI(temperature=.7, openai_api_key='sk-')
return llm
if __name__ == '__main__':
app.run()