SolshineMisfit commited on
Commit
ad924eb
·
verified ·
1 Parent(s): ae7a494

Added perplexity search tool

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -7,16 +7,39 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ @weave.op()
11
+ def tracked_perplexity_call(prompt: str, system_messages: str, model_name: str = "sonar-pro", assistant_meta: bool = False):
12
+ """Enhanced Perplexity API call with explicit model tracking."""
13
+ client = OpenAI(api_key=os.getenv("PERPLEXITY_API_KEY"), base_url="https://api.perplexity.ai")
14
+ system_message = Perplex_Assistant_Prompt
15
+ if assistant_meta:
16
+ system_message += f"\n\n{system_messages}"
17
+
18
+ # Minimal parameters for Perplexity
19
+ return client.chat.completions.create(
20
+ model=model_name,
21
+ messages=[
22
+ {"role": "system", "content": system_message},
23
+ {"role": "user", "content": prompt},
24
+ ],
25
+ stream=False,
26
+ ).choices[0].message.content
27
+
28
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
29
  @tool
30
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
31
  #Keep this format for the description / args / args description but feel free to modify the tool
32
+ """A tool that accesses Perplexity Sonar to search the web when the answer requires or would benefit from a real world web reference.
33
  Args:
34
+ arg1: User Prompt
35
+ arg2: Details on the desired web search results as system message for sonar web search
36
  """
37
+ try:
38
+ sonar_response = tracked_perplexity_call(arg1, arg2)
39
+ return sonar_response
40
+ except Exception as e:
41
+ return f"Error using Sonar Websearch tool '{arg1} {arg2}': {str(e)}"
42
+
43
 
44
  @tool
45
  def get_current_time_in_timezone(timezone: str) -> str: