anirudh248 commited on
Commit
c18178e
·
verified ·
1 Parent(s): f5a37d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -52,16 +52,21 @@ llm = HuggingFacePipeline(pipeline=hf_pipeline)
52
  # ==========================================
53
  # 3. Setup RAG Chain
54
  # ==========================================
 
55
  prompt_template = """
56
- You are an expert in Unified Power Format (UPF). Generate a precise and complete UPF code block based on the following power intent. Use the retrieved context as a reference. The code must be correct and adhere to UPF 3.0 standards.
57
 
58
- Context:
59
  {context}
60
 
61
- Power Intent Description:
62
  {input}
63
 
64
- Generate only the UPF code. Do not include introductory text.
 
 
 
 
65
  """
66
  prompt = PromptTemplate.from_template(prompt_template)
67
  document_chain = create_stuff_documents_chain(llm, prompt)
@@ -79,9 +84,6 @@ def generate_upf_code(power_intent_description):
79
  def user_interaction(user_message, history):
80
  history = history or []
81
  response = generate_upf_code(user_message)
82
-
83
- if "```" not in response:
84
- response = f"```tcl\n{response}\n```"
85
 
86
  history.append({"role": "user", "content": user_message})
87
  history.append({"role": "assistant", "content": response})
@@ -93,9 +95,9 @@ with gr.Blocks() as interface:
93
  chatbot = gr.Chatbot(label="Chat History", elem_id="chatbot")
94
 
95
  with gr.Row():
96
- user_input = gr.Textbox(show_label=False, placeholder="Enter power intent...", lines=3)
97
 
98
- send_button = gr.Button("Generate UPF Code", variant="primary")
99
 
100
  send_button.click(fn=user_interaction, inputs=[user_input, chatbot], outputs=[chatbot, user_input])
101
  user_input.submit(fn=user_interaction, inputs=[user_input, chatbot], outputs=[chatbot, user_input])
 
52
  # ==========================================
53
  # 3. Setup RAG Chain
54
  # ==========================================
55
+
56
  prompt_template = """
57
+ You are a highly capable AI assistant. You possess specialized expertise in Unified Power Format (UPF) and power intent design, but you are also a helpful general conversationalist.
58
 
59
+ Context (Reference UPF examples, if relevant):
60
  {context}
61
 
62
+ User's Input:
63
  {input}
64
 
65
+ Instructions:
66
+ 1. If the User's Input is asking to generate UPF code or discuss power intent, act as an expert UPF engineer. Use the Context above to generate precise, complete UPF 3.0 code. Enclose the code cleanly in ```tcl ... ``` blocks.
67
+ 2. If the User's Input is a general question, a greeting, or unrelated to UPF, respond normally as a helpful AI assistant and ignore the UPF context.
68
+
69
+ Response:
70
  """
71
  prompt = PromptTemplate.from_template(prompt_template)
72
  document_chain = create_stuff_documents_chain(llm, prompt)
 
84
  def user_interaction(user_message, history):
85
  history = history or []
86
  response = generate_upf_code(user_message)
 
 
 
87
 
88
  history.append({"role": "user", "content": user_message})
89
  history.append({"role": "assistant", "content": response})
 
95
  chatbot = gr.Chatbot(label="Chat History", elem_id="chatbot")
96
 
97
  with gr.Row():
98
+ user_input = gr.Textbox(show_label=False, placeholder="Enter a general question or a UPF power intent...", lines=3)
99
 
100
+ send_button = gr.Button("Generate Response", variant="primary")
101
 
102
  send_button.click(fn=user_interaction, inputs=[user_input, chatbot], outputs=[chatbot, user_input])
103
  user_input.submit(fn=user_interaction, inputs=[user_input, chatbot], outputs=[chatbot, user_input])