Wajahat698 commited on
Commit
92c205a
·
verified ·
1 Parent(s): f001ea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -30
app.py CHANGED
@@ -1229,17 +1229,18 @@ def cache_response(query, response, ttl=3600):
1229
 
1230
 
1231
  tavily_tool = TavilySearchResults(
1232
- search_depth="intermediate",
 
 
 
1233
  include_answer=True,
1234
- include_raw_content=False,
1235
- include_images=False,
1236
  # include_domains=[...],
1237
- # exclude_domains=[...],
1238
  # name="...", # overwrite default tool name
1239
  # description="...", # overwrite default tool description
1240
  # args_schema=..., # overwrite default args_schema: BaseModel
1241
- )
1242
- # Compile all tool functions into a list
1243
  tools = [
1244
  knowledge_base_tool, # Tool for querying the knowledge base and retrieving responses
1245
  tavily_tool,
@@ -2158,31 +2159,36 @@ def handle_prompt(prompt):
2158
  add_dot_typing_animation()
2159
  display_typing_indicator()
2160
  cleaned_text = ""
2161
- base_instructions = """
2162
- *Be overly specific with details such as $dollar amounts, awards, people's names, and program titles*
2163
- 1. **Focus on Knowledge Base Data**:
2164
- - When asked using uploaded documents, files or using knowledgebase files, prioritize information fetch everything asked from there.
 
 
 
 
 
 
 
 
 
 
2165
 
2166
- 2. **Eliminate Flowery Language and AI Jargon**:
2167
- - Avoid unnecessary technical terms and complex vocabulary.
2168
-
2169
- 3. **Provide Accurate, Factual Information with Valid Sources**:
2170
- - When information is not available in the knowledgebase, search on Google.
2171
- - Always include accurate and verifiable source links in your responses.for knowledgebase data also sources should be googled.
2172
 
2173
- 4. **Content Guidelines**:
2174
- - Do **not** use trust bucket names (e.g., Stability Trust, Benefit Trust etc.) in content.
2175
- - Strictly avoid mentioning them in your responses.
2176
-
2177
- """
2178
 
2179
 
2180
 
2181
  # Check if user request includes blog, article, or newsletter
2182
  if any(keyword in prompt.lower() for keyword in ["blog", "write","article","annual report","report", "newsletter","website introduction"]):
2183
  appended_instructions = (
2184
- "Craft a flawless, engaging, and fluid compelling copy using *non-flowery language* that reads as though written by a professional copywriter having 25 years of experience. "
2185
- "Do not use AI jargon, vague phrases, or formal language. Follow these enhanced guidelines to ensure a polished, publication-ready copy with a 10/10 quality: "
2186
  "1. **Interconnected Structure**: Ensure all sections and ideas flow seamlessly with logical transitions between paragraphs. Build a cohesive narrative where every part supports the overall theme, reinforcing the message at every step. "
2187
  "3. **Seamless Integration of TrustBuilders®**: Naturally incorporate TrustBuilders® into the narrative without isolating or explicitly listing them in the main body. Instead, weave them fluidly into sentences to build credibility and trust while maintaining the content’s readability and engagement. "
2188
  "4. **Human Tone**: Write in a relatable, conversational tone that engages the reader and feels natural. Avoid repetitive phrasing, overly technical explanations, or mechanical structures. Use active voice consistently, ensuring the tone is both approachable and professional."
@@ -2191,14 +2197,13 @@ def handle_prompt(prompt):
2191
  "7. **Purpose-Driven Impact**: Clearly define and achieve the content’s purpose—whether to inform, persuade, or inspire action. Ensure every paragraph serves the overall objective while reinforcing the key message. "
2192
  "8. **Polished Presentation**: Ensure the final output is refined, professional, and suitable for publication. The copy should demonstrate mastery of language and content design, leaving no room for ambiguity or errors. "
2193
  "dont give source link in content"
2194
- "Dont mention trust bucket names literally"
2195
  "1. ##List of TrustBuilders Used: Provide trustbuilders used followed by *Source links always*"
2196
  " 2. ##Heuristics and Creative Techniques :"
2197
  " -List them in a footnote-style small heading."
2198
  " Use the following structure:"
2199
  " -Heuristics: Mention names only like examples (e.g., social proof, authority, commitment)."
2200
  " -Creative Techniques: Mention names onlyexamples (list only relevant marketing techniques without additional details)."
2201
- "The final output must not include AI jargons. *With every paragraph give a creative headline that summarises the content give sub-headlines with each paragraph like example headline: We Empower or Similar Phrases*. Avoid mentioning trustbucket names."
2202
  "MOST IMPORTANT RULE. IN EVERY PARAGRAPH Strengthen the connections between sections to ensure smoother flow and SHOULD BE DEEPLY INTERCONNECTED WITH EACH OTHER TO CREATE A SEAMLESS FLOW, MAKING THE CONTENT READ LIKE A SINGLE CONTENT RATHER THAN DISJOINTED PARAGRAPHS OR INDEPENDENT BLOG SECTIONS. EACH SECTION MUST LOGICALLY TRANSITION INTO THE NEXT, ENSURING THAT THE TOPIC REMAINS CONSISTENT AND RELEVANT THROUGHOUT. BY MAINTAINING A COHESIVE STRUCTURE, THE ARTICLE WILL ENGAGE READERS MORE EFFECTIVELY, HOLDING THEIR ATTENTION AND CONVEYING THE INTENDED MESSAGE WITH CLARITY AND IMPACT."
2203
  )
2204
  else:
@@ -2211,23 +2216,25 @@ def handle_prompt(prompt):
2211
  "chat_history": st.session_state.chat_history
2212
  })
2213
  full_response = output["output"]
 
 
2214
 
2215
- cleaned_text = clean_text(full_response)
2216
- formatted_text = clean_and_format_markdown(cleaned_text)
2217
 
2218
  trust_tip, suggestion = get_trust_tip_and_suggestion()
2219
- combined_text = f"{formatted_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
2220
 
2221
  with response_placeholder:
2222
  with st.chat_message("assistant"):
2223
- st.write(combined_text)
2224
 
2225
 
2226
  except Exception as e:
2227
  logging.error(f"Error generating response: {e}")
2228
  st.error("An error occurred while generating the response. Please try again.")
2229
 
2230
- st.session_state.chat_history.append({"role": "assistant", "content": combined_text})
2231
  copy_to_clipboard(combined_text)
2232
  st.session_state["handled"] = True # Mark as handled
2233
 
 
1229
 
1230
 
1231
  tavily_tool = TavilySearchResults(
1232
+ max_results=10,
1233
+ search_depth="advanced",
1234
+ topic="news",
1235
+ days=1,
1236
  include_answer=True,
1237
+ include_raw_content=True,
 
1238
  # include_domains=[...],
1239
+ exclude_domains=['example.com'],
1240
  # name="...", # overwrite default tool name
1241
  # description="...", # overwrite default tool description
1242
  # args_schema=..., # overwrite default args_schema: BaseModel
1243
+ )# Compile all tool functions into a list
 
1244
  tools = [
1245
  knowledge_base_tool, # Tool for querying the knowledge base and retrieving responses
1246
  tavily_tool,
 
2159
  add_dot_typing_animation()
2160
  display_typing_indicator()
2161
  cleaned_text = ""
2162
+ base_instructions="""
2163
+ Avoid Flowery language and ai words.Always include alof of data of numbers,names,dollars, programs ,awards and action when finding trustbuilders from internet.*
2164
+
2165
+ 1. **Adhere to Uploaded Document's Style**:
2166
+ - When asked uploaded files or document means knowledgebase.
2167
+ - Use the uploaded document as a primary guide for writing style, tone, and structure. Just directly give response.
2168
+ - Match formatting such as headings, subheadings, and paragraph styles. If the uploaded document lacks headings, Strictly do not include them in the response.
2169
+
2170
+ 2. **Prioritize Knowledge Base and Internet Sources**:
2171
+ - Use uploaded documents or knowledge base files as the primary source.
2172
+ - Perform a Google search to retrieve valid and correct internet links for references, ensuring only accurate and verified source links are used.
2173
+
2174
+ 3. **Avoid Flowery Language and AI Jargon**:
2175
+ - Use clear, professional language without exaggerated or vague expressions. Avoid jargon like "beacon," "realm," "exemplifies," etc.
2176
 
2177
+ 4. **Ensure Accuracy**:
2178
+ - Provide only verifiable and accurate information. Do not include placeholders, fabricated URLs, or vague references.
 
 
 
 
2179
 
2180
+ - Give output in proper formatting.
2181
+ - Response in same language in which asked.
2182
+ -Use google to provide correct sources links containing the trustbuilder text information.
2183
+ """
 
2184
 
2185
 
2186
 
2187
  # Check if user request includes blog, article, or newsletter
2188
  if any(keyword in prompt.lower() for keyword in ["blog", "write","article","annual report","report", "newsletter","website introduction"]):
2189
  appended_instructions = (
2190
+ "Craft a flawless, engaging, and fluid compelling copy using *non-flowery language* that reads as though written by a professional copywriter having 25 years of experience. "
2191
+ "Do not use AI jargon, vague phrases, or formal language.Donot mention trustbucket names in the headings and content. Follow these enhanced guidelines to ensure a polished, publication-ready copy with a 10/10 quality: "
2192
  "1. **Interconnected Structure**: Ensure all sections and ideas flow seamlessly with logical transitions between paragraphs. Build a cohesive narrative where every part supports the overall theme, reinforcing the message at every step. "
2193
  "3. **Seamless Integration of TrustBuilders®**: Naturally incorporate TrustBuilders® into the narrative without isolating or explicitly listing them in the main body. Instead, weave them fluidly into sentences to build credibility and trust while maintaining the content’s readability and engagement. "
2194
  "4. **Human Tone**: Write in a relatable, conversational tone that engages the reader and feels natural. Avoid repetitive phrasing, overly technical explanations, or mechanical structures. Use active voice consistently, ensuring the tone is both approachable and professional."
 
2197
  "7. **Purpose-Driven Impact**: Clearly define and achieve the content’s purpose—whether to inform, persuade, or inspire action. Ensure every paragraph serves the overall objective while reinforcing the key message. "
2198
  "8. **Polished Presentation**: Ensure the final output is refined, professional, and suitable for publication. The copy should demonstrate mastery of language and content design, leaving no room for ambiguity or errors. "
2199
  "dont give source link in content"
 
2200
  "1. ##List of TrustBuilders Used: Provide trustbuilders used followed by *Source links always*"
2201
  " 2. ##Heuristics and Creative Techniques :"
2202
  " -List them in a footnote-style small heading."
2203
  " Use the following structure:"
2204
  " -Heuristics: Mention names only like examples (e.g., social proof, authority, commitment)."
2205
  " -Creative Techniques: Mention names onlyexamples (list only relevant marketing techniques without additional details)."
2206
+ "The final output must not include AI jargons. *With every paragraph give a creative headline that summarises the content give sub-headlines with each paragraph like example headline: Drive,empower use similar words but no driving, empowering etc *. Avoid mentioning trustbucket names."
2207
  "MOST IMPORTANT RULE. IN EVERY PARAGRAPH Strengthen the connections between sections to ensure smoother flow and SHOULD BE DEEPLY INTERCONNECTED WITH EACH OTHER TO CREATE A SEAMLESS FLOW, MAKING THE CONTENT READ LIKE A SINGLE CONTENT RATHER THAN DISJOINTED PARAGRAPHS OR INDEPENDENT BLOG SECTIONS. EACH SECTION MUST LOGICALLY TRANSITION INTO THE NEXT, ENSURING THAT THE TOPIC REMAINS CONSISTENT AND RELEVANT THROUGHOUT. BY MAINTAINING A COHESIVE STRUCTURE, THE ARTICLE WILL ENGAGE READERS MORE EFFECTIVELY, HOLDING THEIR ATTENTION AND CONVEYING THE INTENDED MESSAGE WITH CLARITY AND IMPACT."
2208
  )
2209
  else:
 
2216
  "chat_history": st.session_state.chat_history
2217
  })
2218
  full_response = output["output"]
2219
+ import html
2220
+ escaped_text = full_response.replace("$", "\$")
2221
 
2222
+ #cleaned_text = clean_text(full_response)
2223
+ #formatted_text = clean_and_format_markdown(cleaned_text)
2224
 
2225
  trust_tip, suggestion = get_trust_tip_and_suggestion()
2226
+ combined_text = f"{escaped_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
2227
 
2228
  with response_placeholder:
2229
  with st.chat_message("assistant"):
2230
+ st.markdown(combined_text)
2231
 
2232
 
2233
  except Exception as e:
2234
  logging.error(f"Error generating response: {e}")
2235
  st.error("An error occurred while generating the response. Please try again.")
2236
 
2237
+ st.session_state.chat_history.append({"role": "assistant", "content": escaped_text})
2238
  copy_to_clipboard(combined_text)
2239
  st.session_state["handled"] = True # Mark as handled
2240