Spaces:
Sleeping
Sleeping
Commit ·
d2e8f40
1
Parent(s): 71d9455
updated tavily web search functionality
Browse files- core_logic.py +15 -7
core_logic.py
CHANGED
|
@@ -112,12 +112,20 @@ def chat_function(message, history):
|
|
| 112 |
{
|
| 113 |
"role": "system",
|
| 114 |
"content": (
|
| 115 |
-
"You are a
|
| 116 |
-
"
|
| 117 |
-
"
|
| 118 |
-
"
|
| 119 |
-
"
|
| 120 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
)
|
| 122 |
},
|
| 123 |
{"role": "user", "content": user_text}
|
|
@@ -130,7 +138,7 @@ def chat_function(message, history):
|
|
| 130 |
# Strip away any lingering quotes, backticks, or markdown syntax characters
|
| 131 |
optimized_query = re.sub(r"[`'\"\\n\-*#\[\]]", "", raw_query)
|
| 132 |
|
| 133 |
-
print(f"
|
| 134 |
print(f"\nOptimized Search Query: '{optimized_query}'") # Debug log for the optimized query
|
| 135 |
|
| 136 |
# Executing clean, highly target web search under the 400-character cap
|
|
|
|
| 112 |
{
|
| 113 |
"role": "system",
|
| 114 |
"content": (
|
| 115 |
+
"You are a search query optimizer tool. Your ONLY job is to take the user's long request and turn it into a short, effective, plain-text, respecting Tavily Web Search's less than 400 characters limitation, web search query for finding relevant technical programming documentation. \n"
|
| 116 |
+
"You will distill the user's request down to its core essence, extracting the most important keywords and concepts while stripping away any unnecessary fluff or filler words. The goal is to create a concise search query that captures the main intent of the user's request while being optimized for search engine algorithms. \n\n"
|
| 117 |
+
"Critical Rules:\n"
|
| 118 |
+
"1. Do NOT answer the user's prompt. \n"
|
| 119 |
+
"2. Do NOT write code blocks, code explanations, tasks, or JSON data structures. \n"
|
| 120 |
+
"3. Your entire output must be a single sentence under 50 characters. \n"
|
| 121 |
+
"4. If the user provides a code file or raw data logs, ignore the text content and generate a query searching for the underlying concept (e.g., "Scapy network sniffing documentation python"). \n"
|
| 122 |
+
"5. Output ONLY raw keywords.\n"
|
| 123 |
+
"6. NEVER use markdown, backticks, or code blocks.\n"
|
| 124 |
+
"7. NEVER wrap your output in single or double quotes.\n"
|
| 125 |
+
"8. Maximum 5 words, under 50 characters total."
|
| 126 |
+
|
| 127 |
+
"User Input to convert: \n"
|
| 128 |
+
{user_text}
|
| 129 |
)
|
| 130 |
},
|
| 131 |
{"role": "user", "content": user_text}
|
|
|
|
| 138 |
# Strip away any lingering quotes, backticks, or markdown syntax characters
|
| 139 |
optimized_query = re.sub(r"[`'\"\\n\-*#\[\]]", "", raw_query)
|
| 140 |
|
| 141 |
+
print(f"\nlen optimized_query: {len(optimized_query)}") # Debug log for query length
|
| 142 |
print(f"\nOptimized Search Query: '{optimized_query}'") # Debug log for the optimized query
|
| 143 |
|
| 144 |
# Executing clean, highly target web search under the 400-character cap
|