Spaces:
Running
Running
jianghuyihei
commited on
Commit
•
2b256e9
1
Parent(s):
e3a17c0
fix
Browse files- __pycache__/LLM.cpython-310.pyc +0 -0
- __pycache__/agents.cpython-310.pyc +0 -0
- __pycache__/app.cpython-310.pyc +0 -0
- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +42 -20
- prompts/__pycache__/__init__.cpython-310.pyc +0 -0
- prompts/__pycache__/deep_research_agent_promts.cpython-310.pyc +0 -0
- prompts/__pycache__/juder_prompts.cpython-310.pyc +0 -0
- prompts/__pycache__/review_agent_prompts.cpython-310.pyc +0 -0
- searcher/__pycache__/__init__.cpython-310.pyc +0 -0
- searcher/__pycache__/sementic_search.cpython-310.pyc +0 -0
__pycache__/LLM.cpython-310.pyc
ADDED
Binary file (6.8 kB). View file
|
|
__pycache__/agents.cpython-310.pyc
ADDED
Binary file (8.65 kB). View file
|
|
__pycache__/app.cpython-310.pyc
ADDED
Binary file (11.8 kB). View file
|
|
__pycache__/utils.cpython-310.pyc
ADDED
Binary file (854 Bytes). View file
|
|
app.py
CHANGED
@@ -5,9 +5,11 @@ import markdown
|
|
5 |
import time
|
6 |
from datetime import datetime, timedelta
|
7 |
from apscheduler.schedulers.background import BackgroundScheduler
|
8 |
-
import asyncio
|
9 |
from agents import DeepResearchAgent, get_llms
|
|
|
|
|
10 |
|
|
|
11 |
app = FastAPI()
|
12 |
|
13 |
# 每日最大回复次数
|
@@ -316,6 +318,8 @@ scheduler = BackgroundScheduler()
|
|
316 |
scheduler.add_job(reset_counter, 'cron', hour=0, minute=0)
|
317 |
scheduler.start()
|
318 |
|
|
|
|
|
319 |
@app.get("/", response_class=HTMLResponse)
|
320 |
def form_get():
|
321 |
return Template(html_template).render(idea= "This is a example of the idea geneartion", error=None, reply_count=reply_count)
|
@@ -324,22 +328,40 @@ def form_get():
|
|
324 |
def form_post(topic: str = Form(...)):
|
325 |
global reply_count
|
326 |
start_time = time.time()
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
return Template(html_template).render(idea=
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import time
|
6 |
from datetime import datetime, timedelta
|
7 |
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
8 |
from agents import DeepResearchAgent, get_llms
|
9 |
+
import threading
|
10 |
+
from queue import Queue
|
11 |
|
12 |
+
lock = threading.Lock()
|
13 |
app = FastAPI()
|
14 |
|
15 |
# 每日最大回复次数
|
|
|
318 |
scheduler.add_job(reset_counter, 'cron', hour=0, minute=0)
|
319 |
scheduler.start()
|
320 |
|
321 |
+
request_queue = Queue()
|
322 |
+
|
323 |
@app.get("/", response_class=HTMLResponse)
|
324 |
def form_get():
|
325 |
return Template(html_template).render(idea= "This is a example of the idea geneartion", error=None, reply_count=reply_count)
|
|
|
328 |
def form_post(topic: str = Form(...)):
|
329 |
global reply_count
|
330 |
start_time = time.time()
|
331 |
+
|
332 |
+
# 将请求放入队列
|
333 |
+
request_id = threading.get_ident()
|
334 |
+
request_queue.put(request_id)
|
335 |
+
|
336 |
+
# 等待轮到当前请求
|
337 |
+
while request_queue.queue[0] != request_id:
|
338 |
+
time.sleep(10) # 等待一段时间后再检查
|
339 |
+
# 根据自己的request_id,判断前面还有多少人在排队
|
340 |
+
len = 0
|
341 |
+
for i in request_queue.queue:
|
342 |
+
if i == request_id:
|
343 |
+
break
|
344 |
+
len += 1
|
345 |
+
return Template(html_template).render(idea="", error=f"The server is busy. Please try again later.There are {len}", reply_count=reply_count)
|
346 |
+
|
347 |
+
with lock:
|
348 |
+
start_time = time.time()
|
349 |
+
# 检查是否超过每日最大回复次数
|
350 |
+
if reply_count >= MAX_REPLIES_PER_DAY:
|
351 |
+
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
352 |
+
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count)
|
353 |
+
try:
|
354 |
+
main_llm, cheap_llm = get_llms()
|
355 |
+
deep_research_agent = DeepResearchAgent(llm=main_llm, cheap_llm=cheap_llm, improve_cnt=1, max_chain_length=5, min_chain_length=3, max_chain_numbers=1)
|
356 |
+
print(f"begin to generate idea of topic {topic}")
|
357 |
+
idea, related_experiments, entities, idea_chain, ideas, trend, future, human, year = deep_research_agent.generate_idea_with_chain(topic)
|
358 |
+
idea_md = markdown.markdown(idea)
|
359 |
+
# 更新每日回复次数
|
360 |
+
reply_count += 1
|
361 |
+
end_time = time.time()
|
362 |
+
time_taken = round(end_time - start_time, 2)
|
363 |
+
return Template(html_template).render(idea=idea_md, error=None, reply_count=reply_count, time_taken=time_taken)
|
364 |
+
except Exception as e:
|
365 |
+
end_time = time.time()
|
366 |
+
time_taken = round(end_time - start_time, 2)
|
367 |
+
return Template(html_template).render(idea="", error=str(e), reply_count=reply_count, time_taken=time_taken)
|
prompts/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (247 Bytes). View file
|
|
prompts/__pycache__/deep_research_agent_promts.cpython-310.pyc
ADDED
Binary file (28.1 kB). View file
|
|
prompts/__pycache__/juder_prompts.cpython-310.pyc
ADDED
Binary file (4.74 kB). View file
|
|
prompts/__pycache__/review_agent_prompts.cpython-310.pyc
ADDED
Binary file (4.13 kB). View file
|
|
searcher/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (221 Bytes). View file
|
|
searcher/__pycache__/sementic_search.cpython-310.pyc
ADDED
Binary file (11.5 kB). View file
|
|