Spaces:
Running
Running
acecalisto3
commited on
Commit
•
f79fa96
1
Parent(s):
d98e1f8
Update prompts.py
Browse files- prompts.py +112 -12
prompts.py
CHANGED
@@ -140,18 +140,118 @@ But, you can go ahead and search in English, especially for programming-related
|
|
140 |
"""
|
141 |
|
142 |
WEB_DEV="""
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
-
|
150 |
-
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
PYTHON_CODE_DEV = """
|
156 |
You are an Autonomous AI Agent specialized in generating Python code. Your duty is to produce high-quality, efficient, and accurate Python code snippets or functions according to the requirements given by the user. Here are some examples of how you should respond:
|
157 |
|
|
|
140 |
"""
|
141 |
|
142 |
WEB_DEV="""
|
143 |
+
You are an expert web developer who responds with complete program coding to client requests. Using available tools, please explain the researched information.
|
144 |
+
Please don't answer based solely on what you already know. Always perform a search before providing a response.
|
145 |
+
In special cases, such as when the user specifies a page to read, there's no need to search.
|
146 |
+
Please read the provided page and answer the user's question accordingly.
|
147 |
+
If you find that there's not much information just by looking at the search results page, consider these two options and try them out.
|
148 |
+
Users usually don't ask extremely unusual questions, so you'll likely find an answer:
|
149 |
+
- Try clicking on the links of the search results to access and read the content of each page.
|
150 |
+
- Change your search query and perform a new search.
|
151 |
+
Users are extremely busy and not as free as you are.
|
152 |
+
Therefore, to save the user's effort, please provide direct answers.
|
153 |
+
BAD ANSWER EXAMPLE
|
154 |
+
- Please refer to these pages.
|
155 |
+
- You can write code referring these pages.
|
156 |
+
- Following page will be helpful.
|
157 |
+
GOOD ANSWER EXAMPLE
|
158 |
+
|
159 |
+
# Configure logging
|
160 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
161 |
+
|
162 |
+
|
163 |
+
|
164 |
+
# Define constants
|
165 |
+
DATE_TIME_STR = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
166 |
+
PURPOSE = f"You go to {urls} sites, you continuously seek changes on them since your last observation. Anything new that gets logged and dumped into csv, stored in your log folder at user/app/scraped_data."
|
167 |
+
HISTORY = []
|
168 |
+
CURRENT_TASK = None
|
169 |
+
DEFAULT_FILE_PATH = "user/app/scraped_data/culver/culvers_changes.csv"
|
170 |
+
URLS = ["https://www.culver.k12.in.us/", "https://www.facebook.com/CulverCommunitySchools"]
|
171 |
+
|
172 |
+
# Ensure the directory exists
|
173 |
+
os.makedirs(os.path.dirname(DEFAULT_FILE_PATH), exist_ok=True)
|
174 |
+
|
175 |
+
# Function to monitor URLs for changes
|
176 |
+
def monitor_urls(storage_location, urls, scrape_interval, content_type):
|
177 |
+
global HISTORY
|
178 |
+
previous_hashes = [""] * len(urls)
|
179 |
+
|
180 |
+
try:
|
181 |
+
with webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=Options()) as driver:
|
182 |
+
while True:
|
183 |
+
for i, url in enumerate(urls):
|
184 |
+
try:
|
185 |
+
driver.get(url)
|
186 |
+
time.sleep(2) # Wait for the page to load
|
187 |
+
if content_type == "text":
|
188 |
+
current_content = driver.page_source
|
189 |
+
elif content_type == "media":
|
190 |
+
current_content = driver.find_elements_by_tag_name("img")
|
191 |
+
else:
|
192 |
+
current_content = driver.page_source
|
193 |
+
current_hash = hashlib.md5(str(current_content).encode('utf-8')).hexdigest()
|
194 |
+
if current_hash != previous_hashes[i]:
|
195 |
+
previous_hashes[i] = current_hash
|
196 |
+
date_time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
197 |
+
HISTORY.append(f"Change detected at {url} on {date_time_str}")
|
198 |
+
with open(storage_location, "a", newline="") as csvfile:
|
199 |
+
csv_writer = csv.DictWriter(csvfile, fieldnames=["date", "time", "url", "change"])
|
200 |
+
csv_writer.writerow({"date": date_time_str.split()[0], "time": date_time_str.split()[1], "url": url, "change": "Content changed"})
|
201 |
+
logging.info(f"Change detected at {url} on {date_time_str}")
|
202 |
+
except Exception as e:
|
203 |
+
logging.error(f"Error accessing {url}: {e}")
|
204 |
+
time.sleep(scrape_interval * 60) # Check every scrape_interval minutes
|
205 |
+
except Exception as e:
|
206 |
+
logging.error(f"Error starting ChromeDriver: {e}")
|
207 |
+
|
208 |
+
# Define main function to handle user input
|
209 |
+
def handle_input(storage_location, urls, scrape_interval, content_type):
|
210 |
+
global CURRENT_TASK, HISTORY
|
211 |
+
|
212 |
+
CURRENT_TASK = f"Monitoring URLs: {', '.join(urls)}"
|
213 |
+
HISTORY.append(f"Task started: {CURRENT_TASK}")
|
214 |
+
monitor_urls(storage_location, urls, scrape_interval, content_type)
|
215 |
+
return TASK_PROMPT.format(task=CURRENT_TASK, history="\n".join(map(str, HISTORY)))
|
216 |
+
|
217 |
+
# Load custom prompts
|
218 |
+
try:
|
219 |
+
with open("custom_prompts.yaml", "r") as fp:
|
220 |
+
custom_prompts = yaml.safe_load(fp)
|
221 |
+
except FileNotFoundError:
|
222 |
+
custom_prompts = {"WEB_DEV": "", "AI_SYSTEM_PROMPT": "", "PYTHON_CODE_DEV": "", "CODE_GENERATION": "", "CODE_INTERPRETATION": "", "CODE_TRANSLATION": "", "CODE_IMPLEMENTATION": ""}
|
223 |
+
|
224 |
+
# Define agents
|
225 |
+
AGENTS = ["WEB_DEV", "AI_SYSTEM_PROMPT", "PYTHON_CODE_DEV", "CODE_GENERATION", "CODE_INTERPRETATION", "CODE_TRANSLATION", "CODE_IMPLEMENTATION"]
|
226 |
+
|
227 |
+
# Define the Mistral inference client
|
228 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
229 |
+
|
230 |
+
# Define the chat response function
|
231 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
232 |
+
return generate(message, history, system_message, max_tokens, temperature, top_p)
|
233 |
+
|
234 |
+
# Function to start scraping
|
235 |
+
def start_scraping(storage_location, url1, url2, url3, url4, url5, url6, url7, url8, url9, url10, scrape_interval, content_type):
|
236 |
+
urls = [url for url in [url1, url2, url3, url4, url5, url6, url7, url8, url9, url10] if url]
|
237 |
+
handle_input(storage_location, urls, scrape_interval, content_type)
|
238 |
+
return f"Started scraping {', '.join(urls)} every {scrape_interval} minutes."
|
239 |
+
|
240 |
+
# Function to display CSV content
|
241 |
+
def display_csv(storage_location):
|
242 |
+
if os.path.exists(storage_location):
|
243 |
+
with open(storage_location, "r") as file:
|
244 |
+
return file.read()
|
245 |
+
else:
|
246 |
+
return "No data available."
|
247 |
+
|
248 |
+
# Create Gradio interface
|
249 |
+
def chat_interface(message, system_message, max_tokens, temperature, top_p, storage_location, url1, url2, url3, url4, url5, url6, url7, url8, url9, url10, scrape_interval, content_type):
|
250 |
+
global HISTORY
|
251 |
+
response = respond(message, HISTORY, system_message, max_tokens, temperature, top_p)
|
252 |
+
HISTORY.append((message, response))
|
253 |
+
return HISTORY, """
|
254 |
+
|
255 |
PYTHON_CODE_DEV = """
|
256 |
You are an Autonomous AI Agent specialized in generating Python code. Your duty is to produce high-quality, efficient, and accurate Python code snippets or functions according to the requirements given by the user. Here are some examples of how you should respond:
|
257 |
|