Completion from messages
Browse files
app.py
CHANGED
|
@@ -8,29 +8,38 @@ _ = load_dotenv(find_dotenv())
|
|
| 8 |
|
| 9 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 10 |
|
| 11 |
-
def
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
response = openai.ChatCompletion.create(
|
| 14 |
model=model,
|
| 15 |
messages=messages,
|
| 16 |
-
temperature=
|
|
|
|
| 17 |
)
|
| 18 |
return response.choices[0].message["content"]
|
| 19 |
|
| 20 |
-
def greet(company, solution, target_customer, problem, features):
|
| 21 |
pitch = f"""My company, {company} is developing {solution} to help {target_customer} {problem} with {features}"""
|
| 22 |
-
|
|
|
|
| 23 |
Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
|
| 24 |
-
following
|
| 25 |
-
State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
|
| 26 |
Give a score for the product.
|
| 27 |
|
| 28 |
Format your response as a JSON object with \
|
| 29 |
'solution', 'problem', 'features', 'target_customer', 'fg_will_use', 'reason_to_use', 'fg_will_pay', 'reason_to_pay', 'score' as the keys.
|
| 30 |
-
|
| 31 |
-
Text sample: '''{pitch}'''
|
| 32 |
"""
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
return json.dumps(response)
|
| 35 |
|
| 36 |
iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Company"), gr.Textbox(label="Solution"), gr.Textbox(label="Customer"), gr.Textbox(label="Problem"), gr.Textbox(label="Feature")], outputs="json")
|
|
|
|
| 8 |
|
| 9 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 10 |
|
| 11 |
+
def get_completion_from_messages(messages,
|
| 12 |
+
model="gpt-3.5-turbo",
|
| 13 |
+
temperature=0,
|
| 14 |
+
max_tokens=500):
|
| 15 |
response = openai.ChatCompletion.create(
|
| 16 |
model=model,
|
| 17 |
messages=messages,
|
| 18 |
+
temperature=temperature, # this is the degree of randomness of the model's output
|
| 19 |
+
max_tokens=max_tokens, # the maximum number of tokens the model can ouptut
|
| 20 |
)
|
| 21 |
return response.choices[0].message["content"]
|
| 22 |
|
| 23 |
+
def greet(company, solution, target_customer, problem, features, customer_persona="the target customer"):
|
| 24 |
pitch = f"""My company, {company} is developing {solution} to help {target_customer} {problem} with {features}"""
|
| 25 |
+
|
| 26 |
+
sys_setup = f"""
|
| 27 |
Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
|
| 28 |
+
following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
|
|
|
|
| 29 |
Give a score for the product.
|
| 30 |
|
| 31 |
Format your response as a JSON object with \
|
| 32 |
'solution', 'problem', 'features', 'target_customer', 'fg_will_use', 'reason_to_use', 'fg_will_pay', 'reason_to_pay', 'score' as the keys.
|
|
|
|
|
|
|
| 33 |
"""
|
| 34 |
+
messages = [
|
| 35 |
+
{'role':'system',
|
| 36 |
+
'content':"You are " + customer_persona + "."},
|
| 37 |
+
{'role':'system',
|
| 38 |
+
'content': sys_setup},
|
| 39 |
+
{'role':'user',
|
| 40 |
+
'content':pitch},
|
| 41 |
+
]
|
| 42 |
+
response = get_completion_from_messages(messages, temperature=1)
|
| 43 |
return json.dumps(response)
|
| 44 |
|
| 45 |
iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Company"), gr.Textbox(label="Solution"), gr.Textbox(label="Customer"), gr.Textbox(label="Problem"), gr.Textbox(label="Feature")], outputs="json")
|