Bhanu-Chander-ABB commited on
Commit
0b83ba2
·
1 Parent(s): 5062b5a

prompt change

Browse files
Files changed (1) hide show
  1. app.py +33 -12
app.py CHANGED
@@ -15,6 +15,7 @@ import base64
15
  from langchain_openai import ChatOpenAI
16
  import fitz
17
  import yt_dlp
 
18
 
19
  ## # Load environment variables from .env file
20
  # --- Constants ---
@@ -29,7 +30,7 @@ OPENAI_MODEL = os.getenv ('OPENAI_MODEL')
29
  ########## ----- DEFINING TOOLS -----##########
30
 
31
  # --- TOOL 1: Web Search Tool (DuckDuckGo) ---
32
- '''
33
  @tool
34
  def search_tool(query: str) -> str:
35
  """Answer general knowledge or current events queries using DuckDuckGo."""
@@ -44,7 +45,7 @@ def search_tool(query: str) -> str:
44
  return "no_answer"
45
  except Exception:
46
  return "error"
47
- '''
48
  # when you use the @tool decorator from langchain.tools, the tool.name and tool.description are automatically extracted from your function
49
  # tool.name is set to the function name (e.g., `search_tool`), and
50
  # tool.description is set to the docstring of the function (the triple-quoted string right under def ...) (e.g., "Answer general knowledge or current events queries using DuckDuckGo.").
@@ -354,6 +355,10 @@ def python_excel_audio_video_attached_file_tool(input_str: str) -> str:
354
  import pandas as pd
355
 
356
  try:
 
 
 
 
357
  data = json.loads(input_str)
358
  file_bytes = base64.b64decode(data["file_bytes"])
359
  filename = data["filename"]
@@ -654,23 +659,24 @@ def audio_video_url_transcript_tool(youtube_url: str) -> str:
654
  # tools_list = get_all_tools()
655
  tools_list = [
656
  python_excel_audio_video_attached_file_tool,
657
- # search_tool,
 
 
 
658
  get_weather,
659
  calculator,
660
  convert_units,
661
  get_time,
662
  get_date,
663
- wikipedia_summary,
664
  dictionary_lookup,
665
  currency_convert,
666
  image_caption,
667
  ocr_image,
668
  classify_image,
669
- # web_scrape_tool,
 
670
  audio_to_text,
671
- python_executor,
672
- search_and_extract_research_paper_info,
673
- sports_awards_historicalfacts_tool,
674
  audio_video_url_transcript_tool
675
  ]
676
 
@@ -688,6 +694,20 @@ If you are asked for a number, don't use comma to write your number neither use
688
  If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
689
  If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
690
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
691
  You also have access to a set of tools, which you can use to answer the question. The available tools with their descriptions are:
692
  {tool_descriptions}
693
 
@@ -695,14 +715,15 @@ If there is a file (image, audio, or video) attached to the question, you should
695
  - For audio or video attachments, the process_attachment tool will transcribe the audio and return the transcript, which you can use to answer the question.
696
  - For image attachments, the process_attachment tool will return a base64 encoded string of the image. You can use this encoded information to provide answer.
697
 
698
- If the question is related to sports, awards, historical facts or similar topic that can be answered from wikipedia, you should use the 'sports_awards_historicalfacts_tool' or if the question is similar or related that can be searched in wikipedia, use the more specific tool 'wikipedia_summary' to fetch relevant page information and answer from it.
699
  In general, you must use tools only if needed for the question and only if the question can be answered by one of the provided tools. Otherwise provide the answer based on your knowledge. You must not use multiple tools in a single call. Don't hallucinate.
700
- If you cannot answer, respond with "no_answer".
701
 
702
- If your final answer is something like 'there were 5 studio albums published between 2000 and 2009' then modify YOUR FINAL ANSWER as: '5'
703
- If your final answer is something like 'b, e' then YOUR FINAL ANSWER be: 'b, e'
704
 
705
  """
 
 
 
706
 
707
  # system_prompt = f"""
708
  # You are an intelligent assistant with access to the following tools:
 
15
  from langchain_openai import ChatOpenAI
16
  import fitz
17
  import yt_dlp
18
+ import re
19
 
20
  ## # Load environment variables from .env file
21
  # --- Constants ---
 
30
  ########## ----- DEFINING TOOLS -----##########
31
 
32
  # --- TOOL 1: Web Search Tool (DuckDuckGo) ---
33
+
34
  @tool
35
  def search_tool(query: str) -> str:
36
  """Answer general knowledge or current events queries using DuckDuckGo."""
 
45
  return "no_answer"
46
  except Exception:
47
  return "error"
48
+
49
  # when you use the @tool decorator from langchain.tools, the tool.name and tool.description are automatically extracted from your function
50
  # tool.name is set to the function name (e.g., `search_tool`), and
51
  # tool.description is set to the docstring of the function (the triple-quoted string right under def ...) (e.g., "Answer general knowledge or current events queries using DuckDuckGo.").
 
355
  import pandas as pd
356
 
357
  try:
358
+ # Extract only the JSON object from the input string
359
+ match = re.search(r'(\{.*\})', input_str, re.DOTALL)
360
+ if match:
361
+ input_str = match.group(1)
362
  data = json.loads(input_str)
363
  file_bytes = base64.b64decode(data["file_bytes"])
364
  filename = data["filename"]
 
659
  # tools_list = get_all_tools()
660
  tools_list = [
661
  python_excel_audio_video_attached_file_tool,
662
+ wikipedia_summary,
663
+ sports_awards_historicalfacts_tool,
664
+ search_and_extract_research_paper_info,
665
+ python_executor,
666
  get_weather,
667
  calculator,
668
  convert_units,
669
  get_time,
670
  get_date,
 
671
  dictionary_lookup,
672
  currency_convert,
673
  image_caption,
674
  ocr_image,
675
  classify_image,
676
+ search_tool,
677
+ web_scrape_tool,
678
  audio_to_text,
679
+ # sports_awards_historicalfacts_tool,
 
 
680
  audio_video_url_transcript_tool
681
  ]
682
 
 
694
  If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
695
  If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
696
 
697
+ For each question, follow this format:
698
+
699
+ Question: the input question you must answer
700
+ Thought: your reasoning about what to do next
701
+ Action: the action to take, must be one of the tools. If no relevant tools, answer the question directly.
702
+ Action Input: the input to the action
703
+ Observation: the result of the action
704
+ ... (repeat Thought/Action/Action Input/Observation as needed)
705
+ Final Answer: the answer to the original question, as concise as possible (number, short string, or comma-separated list, no extra explanation).
706
+
707
+ Rules for YOUR FINAL ANSWER:
708
+ If the questions is about 'how many' or 'how many times' or 'how many years' or 'how many people' or 'how many items' or 'how many albums' or 'how many songs' (basically needing quantitative reply), then YOUR FINAL ANSWER should be a number.
709
+ If the question is about 'what', 'who', 'where', 'when', 'which', 'why', 'how' or similar, then YOUR FINAL ANSWER should be a short string or a comma separated list of strings.
710
+
711
  You also have access to a set of tools, which you can use to answer the question. The available tools with their descriptions are:
712
  {tool_descriptions}
713
 
 
715
  - For audio or video attachments, the process_attachment tool will transcribe the audio and return the transcript, which you can use to answer the question.
716
  - For image attachments, the process_attachment tool will return a base64 encoded string of the image. You can use this encoded information to provide answer.
717
 
718
+ If the question is related to sports, awards, historical facts or similar topic that can be answered from wikipedia, you should use the 'sports_awards_historicalfacts_tool' or if the question is similar or related that can be searched in wikipedia, use the more specific tool 'wikipedia_summary' to fetch relevant page information and answer from it.
719
  In general, you must use tools only if needed for the question and only if the question can be answered by one of the provided tools. Otherwise provide the answer based on your knowledge. You must not use multiple tools in a single call. Don't hallucinate.
 
720
 
721
+ If after 3 to 4 iterations also a tool usage is not useful then try to answer directly based on your knowledge. If you cannot answer, respond with "no_answer".
 
722
 
723
  """
724
+ # If your final answer is something like 'there were 5 studio albums published between 2000 and 2009' then modify YOUR FINAL ANSWER as: '5'
725
+ # If your final answer is something like 'b, e' then YOUR FINAL ANSWER be: 'b, e'
726
+
727
 
728
  # system_prompt = f"""
729
  # You are an intelligent assistant with access to the following tools: