Lasdw commited on
Commit
ea37944
·
1 Parent(s): ebbb043

updated session memory 3

Browse files
Files changed (2) hide show
  1. agent.py +2 -2
  2. app.py +5 -5
agent.py CHANGED
@@ -58,7 +58,7 @@ load_dotenv()
58
  #Give preference to using Tavily Search and Wikipedia Search before using web_search or webpage_scrape. When Web_search does not return a result, use Tavily Search.
59
 
60
  SYSTEM_PROMPT = """ You are a genuis deep reseach assistant called TurboNerd, made by Vividh Mahajan (@Lasdw). Answer the following questions as best you can. If it is a basic question, answer it using your internal knowledge. If it is a complex question that requires facts, use the tools to answer it DO NOT rely on your internal knowledge unless the tools fail to provide a result:
61
- For simple questions, you can use your internal knowledge and answer directly.
62
 
63
  The way you use the tools is by specifying a json blob.
64
  Specifically, this json should have an `action` key (with the name of the tool to use) and an `action_input` key (with the input to the tool going here).
@@ -66,7 +66,7 @@ Specifically, this json should have an `action` key (with the name of the tool t
66
  The only values that should be in the "action" field are:
67
  python_code: Execute Python code. Use this tool to calculate math problems. make sure to use prints to be able to view the final result. args: {"code": {"type": "string"}}
68
  wikipedia_search: Search Wikipedia for information about a specific topic. Optionally specify the number of results to return, args: {"query": {"type": "string"}, "num_results": {"type": "integer", "optional": true}}
69
- tavily_search: Search the web using Tavily. Optionally specify search_depth as 'basic' or 'comprehensive'. DO NOT use Tavily Search for basic questions that you can answer using your internal knowledge especially if the question is not about factual information. args: {"query": {"type": "string"}, "search_depth": {"type": "string", "optional": true}}
70
  arxiv_search: Search ArXiv for publications,news and other resources. Optionally specify max_results to control the number of papers returned, args: {"query": {"type": "string"}, "max_results": {"type": "integer", "optional": true}}
71
  webpage_scrape: Scrape a specific webpage, args: {"url": {"type": "string"}}
72
  supabase_operation: Perform database operations, args: {"operation_type": {"type": "string"}, "table": {"type": "string"}, "data": {"type": "object", "optional": true}, "filters": {"type": "object", "optional": true}}
 
58
  #Give preference to using Tavily Search and Wikipedia Search before using web_search or webpage_scrape. When Web_search does not return a result, use Tavily Search.
59
 
60
  SYSTEM_PROMPT = """ You are a genuis deep reseach assistant called TurboNerd, made by Vividh Mahajan (@Lasdw). Answer the following questions as best you can. If it is a basic question, answer it using your internal knowledge. If it is a complex question that requires facts, use the tools to answer it DO NOT rely on your internal knowledge unless the tools fail to provide a result:
61
+ For simple questions, you can use your internal knowledge and answer directly. If you do not understand the question, ask for clarification after trying to answer the question yourself.
62
 
63
  The way you use the tools is by specifying a json blob.
64
  Specifically, this json should have an `action` key (with the name of the tool to use) and an `action_input` key (with the input to the tool going here).
 
66
  The only values that should be in the "action" field are:
67
  python_code: Execute Python code. Use this tool to calculate math problems. make sure to use prints to be able to view the final result. args: {"code": {"type": "string"}}
68
  wikipedia_search: Search Wikipedia for information about a specific topic. Optionally specify the number of results to return, args: {"query": {"type": "string"}, "num_results": {"type": "integer", "optional": true}}
69
+ tavily_search: Search the web using Tavily. Optionally specify search_depth as 'basic' or 'comprehensive'. DO NOT use Tavily Search for basic questions that you can answer using your internal knowledge especially if the question is not about factual information. DO NOT use Tavily Search for clarifiction. args: {"query": {"type": "string"}, "search_depth": {"type": "string", "optional": true}}
70
  arxiv_search: Search ArXiv for publications,news and other resources. Optionally specify max_results to control the number of papers returned, args: {"query": {"type": "string"}, "max_results": {"type": "integer", "optional": true}}
71
  webpage_scrape: Scrape a specific webpage, args: {"url": {"type": "string"}}
72
  supabase_operation: Perform database operations, args: {"operation_type": {"type": "string"}, "table": {"type": "string"}, "data": {"type": "object", "optional": true}, "filters": {"type": "object", "optional": true}}
app.py CHANGED
@@ -42,7 +42,7 @@ def format_history_for_agent(history: list) -> str:
42
  formatted_history += f"{role.upper()}: {content}\n"
43
  return formatted_history
44
 
45
- def chat_with_agent(question: str, file_uploads, history: list) -> tuple:
46
  """
47
  Handle chat interaction with TurboNerd agent, now with file upload support.
48
  """
@@ -50,8 +50,8 @@ def chat_with_agent(question: str, file_uploads, history: list) -> tuple:
50
  return history, "", "Remaining queries this hour: 5/5"
51
 
52
  try:
53
- # Use a session-based identifier for rate limiting and history
54
- session_id = str(id(history)) # Use the history object's ID as a unique session identifier
55
  print(f"Using session ID: {session_id}")
56
 
57
  # Initialize or get session history
@@ -371,13 +371,13 @@ with gr.Blocks(title="TurboNerd Agent🤓") as demo:
371
  # Chat interface event handlers
372
  submit_btn.click(
373
  fn=chat_with_agent,
374
- inputs=[question_input, file_upload, chatbot],
375
  outputs=[chatbot, question_input, remaining_queries]
376
  )
377
 
378
  question_input.submit(
379
  fn=chat_with_agent,
380
- inputs=[question_input, file_upload, chatbot],
381
  outputs=[chatbot, question_input, remaining_queries]
382
  )
383
 
 
42
  formatted_history += f"{role.upper()}: {content}\n"
43
  return formatted_history
44
 
45
+ def chat_with_agent(question: str, file_uploads, history: list, request: gr.Request) -> tuple:
46
  """
47
  Handle chat interaction with TurboNerd agent, now with file upload support.
48
  """
 
50
  return history, "", "Remaining queries this hour: 5/5"
51
 
52
  try:
53
+ # Get session ID from Gradio request
54
+ session_id = request.session_hash if request else str(id(history))
55
  print(f"Using session ID: {session_id}")
56
 
57
  # Initialize or get session history
 
371
  # Chat interface event handlers
372
  submit_btn.click(
373
  fn=chat_with_agent,
374
+ inputs=[question_input, file_upload, chatbot, gr.Request()],
375
  outputs=[chatbot, question_input, remaining_queries]
376
  )
377
 
378
  question_input.submit(
379
  fn=chat_with_agent,
380
+ inputs=[question_input, file_upload, chatbot, gr.Request()],
381
  outputs=[chatbot, question_input, remaining_queries]
382
  )
383