tanhm07@hotmail.com commited on
Commit ·
f2dc38c
1
Parent(s): d6ce871
llm
Browse files- app.py +39 -4
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def run_agent(system_prompt, email):
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
with gr.Blocks() as demo:
|
| 7 |
with gr.Row():
|
| 8 |
with gr.Column():
|
| 9 |
gr.Markdown("## Agent Builder")
|
| 10 |
-
system_prompt = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
with gr.Column():
|
| 13 |
gr.Markdown("## Email Input")
|
| 14 |
-
email = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
with gr.Column():
|
| 17 |
gr.Markdown("## Output")
|
| 18 |
-
output = gr.
|
| 19 |
|
| 20 |
run_btn = gr.Button("Run Agent")
|
| 21 |
run_btn.click(run_agent, inputs=[system_prompt, email], outputs=output)
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
|
| 5 |
+
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
| 6 |
+
|
| 7 |
+
FORMAT_INSTRUCTION = """
|
| 8 |
+
Please format your response exactly as:
|
| 9 |
+
|
| 10 |
+
Intent:
|
| 11 |
+
Priority:
|
| 12 |
+
Owner:
|
| 13 |
+
Action Required:
|
| 14 |
+
Reasoning:
|
| 15 |
+
Draft Reply:
|
| 16 |
+
"""
|
| 17 |
|
| 18 |
def run_agent(system_prompt, email):
|
| 19 |
+
try:
|
| 20 |
+
response = client.chat.completions.create(
|
| 21 |
+
model="gpt-4o-mini",
|
| 22 |
+
messages=[
|
| 23 |
+
{"role": "system", "content": system_prompt},
|
| 24 |
+
{"role": "user", "content": email + "\n\n" + FORMAT_INSTRUCTION},
|
| 25 |
+
],
|
| 26 |
+
temperature=0.4,
|
| 27 |
+
)
|
| 28 |
+
return response.choices[0].message.content
|
| 29 |
+
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error: {str(e)}"
|
| 32 |
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
with gr.Row():
|
| 35 |
with gr.Column():
|
| 36 |
gr.Markdown("## Agent Builder")
|
| 37 |
+
system_prompt = gr.Textbox(
|
| 38 |
+
label="System Prompt",
|
| 39 |
+
lines=15,
|
| 40 |
+
value="You are an assistant that processes emails."
|
| 41 |
+
)
|
| 42 |
|
| 43 |
with gr.Column():
|
| 44 |
gr.Markdown("## Email Input")
|
| 45 |
+
email = gr.Textbox(
|
| 46 |
+
label="Email",
|
| 47 |
+
lines=15,
|
| 48 |
+
value="We have not received our shipment and this is causing major delays. Please respond urgently."
|
| 49 |
+
)
|
| 50 |
|
| 51 |
with gr.Column():
|
| 52 |
gr.Markdown("## Output")
|
| 53 |
+
output = gr.Markdown()
|
| 54 |
|
| 55 |
run_btn = gr.Button("Run Agent")
|
| 56 |
run_btn.click(run_agent, inputs=[system_prompt, email], outputs=output)
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
gradio
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
openai
|