Kye Gomez commited on
Commit
e9cd720
·
unverified ·
2 Parent(s): 1bfac5a 41923e4

Merge branch 'main' into main

Browse files
Files changed (6) hide show
  1. README.md +99 -0
  2. agents.py +3 -2
  3. app.py +13 -10
  4. helpers.py +156 -0
  5. requirements.txt +1 -0
  6. test_func.py +24 -0
README.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Search Arena
2
+
3
+ **Search Arena** is a comprehensive platform designed to rigorously evaluate and compare search-based web agents. Leveraging a variety of metrics, Search Arena ensures that users can identify the most effective solutions for their needs.
4
+
5
+ ## Key Features
6
+
7
+ - **Output Evaluations:** Analyze the quality and relevance of search results.
8
+ - **Perplexity:** Measure the predictive uncertainty of language models used by the agents.
9
+ - **Exa (Exhaustiveness Analysis):** Assess the breadth and depth of search coverage.
10
+ - **Multi-Agent Comparison:** Compare multiple agents side-by-side.
11
+ - **Customizable Benchmarks:** Define specific benchmarks and criteria for evaluation.
12
+ - **User Feedback Integration:** Incorporate user feedback to improve agent performance.
13
+ - **Performance Metrics:** Detailed reports on response time, precision, recall, and F1 score.
14
+
15
+ ## Benefits
16
+
17
+ - **Enhanced Decision-Making:** Make informed decisions with clear, data-driven evaluations.
18
+ - **Optimization:** Help developers optimize their search agents.
19
+ - **Innovation:** Foster innovation by promoting the best-performing search technologies.
20
+
21
+ ## Getting Started
22
+
23
+ Follow these steps to set up the project on your local machine.
24
+
25
+ ### Prerequisites
26
+
27
+ - Git
28
+ - Python 3.x
29
+ - Virtualenv (optional but recommended)
30
+
31
+ ### Installation
32
+
33
+ 1. **Clone the Repository:**
34
+
35
+ ```bash
36
+ git clone https://github.com/leowalker89/SearchArena
37
+ ```
38
+
39
+ 2. **Navigate to the Project Directory:**
40
+
41
+ ```bash
42
+ cd search-arena
43
+ ```
44
+
45
+ 3. **Create a Virtual Environment:**
46
+
47
+ ```bash
48
+ python -m venv env
49
+ ```
50
+
51
+ 4. **Activate the Virtual Environment:**
52
+
53
+ - On Windows:
54
+
55
+ ```bash
56
+ .\env\Scripts\activate
57
+ ```
58
+
59
+ - On macOS and Linux:
60
+
61
+ ```bash
62
+ source env/bin/activate
63
+ ```
64
+
65
+ 5. **Install the Required Dependencies:**
66
+
67
+ ```bash
68
+ pip install -r requirements.txt
69
+ ```
70
+
71
+ ### Running the Project
72
+
73
+ 1. **Start the Development Server:**
74
+
75
+ ```bash
76
+ streamlit run app.py
77
+ ```
78
+
79
+ 2. **Open your Browser:**
80
+
81
+ Navigate to `http://localhost:5000` to view the platform.
82
+
83
+ ### Usage
84
+
85
+ - Follow the on-screen instructions to evaluate and compare search-based web agents.
86
+ - Customize benchmarks and criteria as needed.
87
+ - Analyze detailed reports and visualizations to make informed decisions.
88
+
89
+ ### Contributing
90
+
91
+ We welcome contributions! Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
92
+
93
+ ### License
94
+
95
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
96
+
97
+ ### Contact
98
+
99
+ If you have any questions, feel free to open an issue or contact us at [[email protected]](mailto:[email protected]).
agents.py CHANGED
@@ -32,6 +32,7 @@ class Perplexity(BaseLLM):
32
  A class to interact with the Perplexity API using OpenAI's interface.
33
  """
34
 
 
35
  def __init__(self, api_key: str = perplexity_api_key(), *args, **kwargs):
36
  """
37
  Initialize the Perplexity class with an API key.
@@ -322,11 +323,11 @@ task = "What is the swarmms framework"
322
 
323
  # Run all of the agents
324
  agents = [
325
- Perplexity,
326
  ExaAgent,
327
  # ResearchAgent,
328
  TavilyWrapper,
329
- # YouSearchAgent,
330
  ]
331
 
332
  # Run each agent with the given task
 
32
  A class to interact with the Perplexity API using OpenAI's interface.
33
  """
34
 
35
+
36
  def __init__(self, api_key: str = perplexity_api_key(), *args, **kwargs):
37
  """
38
  Initialize the Perplexity class with an API key.
 
323
 
324
  # Run all of the agents
325
  agents = [
326
+ # Perplexity,
327
  ExaAgent,
328
  # ResearchAgent,
329
  TavilyWrapper,
330
+ YouSearchAgent,
331
  ]
332
 
333
  # Run each agent with the given task
app.py CHANGED
@@ -1,14 +1,20 @@
1
  import streamlit as st
 
 
2
 
3
  # Set Streamlit to wide mode
4
  st.set_page_config(layout="wide")
5
 
6
  # Define the function to process the question
7
  def ProcessQuestion(question):
8
- # Placeholder for the actual implementation
9
- # This should return answers from two models, A and B
10
- answer_a = "Answer from Model A"
11
- answer_b = "Answer from Model B"
 
 
 
 
12
  return answer_a, answer_b
13
 
14
  # Initialize session state if not already done
@@ -18,8 +24,6 @@ if 'answer_a' not in st.session_state:
18
  st.session_state['answer_a'] = ""
19
  if 'answer_b' not in st.session_state:
20
  st.session_state['answer_b'] = ""
21
- if 'selected_model' not in st.session_state:
22
- st.session_state['selected_model'] = ""
23
  if 'question' not in st.session_state:
24
  st.session_state['question'] = ""
25
 
@@ -46,24 +50,23 @@ if submit_button:
46
  # Save answers and state to session state
47
  st.session_state['answer_a'] = answer_a
48
  st.session_state['answer_b'] = answer_b
49
- # st.session_state['selected_model'] = selected_model
50
  st.session_state['question'] = question
51
  st.session_state['results_displayed'] = True
52
  else:
53
  st.error("Your question exceeds the 1,000 character limit. Please shorten your question.")
54
  else:
55
- st.error("Please enter a question and select a model.")
56
 
57
  # Display results if available in session state
58
  if st.session_state['results_displayed']:
59
  col1, col2 = st.columns(2)
60
 
61
  with col1:
62
- st.write(f"### Output A from {st.session_state['selected_model']}")
63
  st.write(st.session_state['answer_a'])
64
 
65
  with col2:
66
- st.write(f"### Output B from {st.session_state['selected_model']}")
67
  st.write(st.session_state['answer_b'])
68
 
69
  feedback_col = st.columns([1, 1, 1, 1])
 
1
  import streamlit as st
2
+ import random
3
+ from helpers import query_you_com, query_tavily, query_perplexity
4
 
5
  # Set Streamlit to wide mode
6
  st.set_page_config(layout="wide")
7
 
8
  # Define the function to process the question
9
  def ProcessQuestion(question):
10
+ # Randomly select two out of the three functions
11
+ functions = [query_you_com, query_tavily, query_perplexity]
12
+ selected_functions = random.sample(functions, 2)
13
+
14
+ # Get answers from the selected functions
15
+ answer_a = selected_functions[0](question)
16
+ answer_b = selected_functions[1](question)
17
+
18
  return answer_a, answer_b
19
 
20
  # Initialize session state if not already done
 
24
  st.session_state['answer_a'] = ""
25
  if 'answer_b' not in st.session_state:
26
  st.session_state['answer_b'] = ""
 
 
27
  if 'question' not in st.session_state:
28
  st.session_state['question'] = ""
29
 
 
50
  # Save answers and state to session state
51
  st.session_state['answer_a'] = answer_a
52
  st.session_state['answer_b'] = answer_b
 
53
  st.session_state['question'] = question
54
  st.session_state['results_displayed'] = True
55
  else:
56
  st.error("Your question exceeds the 1,000 character limit. Please shorten your question.")
57
  else:
58
+ st.error("Please enter a question.")
59
 
60
  # Display results if available in session state
61
  if st.session_state['results_displayed']:
62
  col1, col2 = st.columns(2)
63
 
64
  with col1:
65
+ st.write("### Output A")
66
  st.write(st.session_state['answer_a'])
67
 
68
  with col2:
69
+ st.write("### Output B")
70
  st.write(st.session_state['answer_b'])
71
 
72
  feedback_col = st.columns([1, 1, 1, 1])
helpers.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from dotenv import load_dotenv
3
+ import os
4
+
5
+ # Load environment variables from .env file
6
+ load_dotenv()
7
+
8
+ # Get API keys from environment variables
9
+ YOU_COM_API_KEY = os.getenv('YOU_API_KEY')
10
+ TAVILY_API_KEY = os.getenv('TAVILY_API_KEY')
11
+ PERPLEXITY_API_KEY = os.getenv('PPLX_API_KEY')
12
+ BRAVE_API_KEY = os.getenv('BRAVESEARCH_API_KEY')
13
+
14
+ def query_you_com(query):
15
+ headers = {"X-API-Key": YOU_COM_API_KEY}
16
+ params = {"query": query}
17
+ try:
18
+ response = requests.get(
19
+ "https://api.ydc-index.io/rag", # Verify the correctness of the API endpoint
20
+ params=params,
21
+ headers=headers,
22
+ )
23
+ response.raise_for_status() # Raises an HTTPError if the response code was unsuccessful
24
+ resp = response.json()
25
+ return resp['answer']
26
+ except requests.exceptions.HTTPError as http_err:
27
+ return f"HTTP error occurred: {http_err}"
28
+ except Exception as err:
29
+ return f"An error occurred: {err}"
30
+
31
+
32
+ def query_tavily(query):
33
+ payload = {
34
+ "api_key": TAVILY_API_KEY,
35
+ "query": query,
36
+ "search_depth": "basic",
37
+ "include_answer": True,
38
+ "include_images": False,
39
+ "include_raw_content": False,
40
+ "max_results": 1,
41
+ "include_domains": [],
42
+ "exclude_domains": []
43
+ }
44
+ response = requests.post("https://api.tavily.com/search", json=payload)
45
+ if response.status_code == 200:
46
+ resp = response.json()
47
+ return resp['answer']
48
+ else:
49
+ return f"Request failed with status code: {response.status_code}"
50
+
51
+ def query_perplexity(query):
52
+ url = 'https://api.perplexity.ai/chat/completions'
53
+ headers = {
54
+ 'Accept': 'application/json',
55
+ 'Content-Type': 'application/json',
56
+ 'Authorization': f'Bearer {PERPLEXITY_API_KEY}'
57
+ }
58
+ data = {
59
+ "model": "llama-3-sonar-large-32k-online",
60
+ "stream": False,
61
+ "max_tokens": 1024,
62
+ "frequency_penalty": 1,
63
+ "temperature": 0.0,
64
+ "messages": [
65
+ {
66
+ "role": "system",
67
+ "content": "Be precise and concise in your responses."
68
+ },
69
+ {
70
+ "role": "user",
71
+ "content": query
72
+ }
73
+ ]
74
+ }
75
+ response = requests.post(url, headers=headers, json=data)
76
+ if response.status_code == 200:
77
+ result = response.json()
78
+ return result['choices'][0]['message']['content']
79
+ else:
80
+ return f"Request failed with status code: {response.status_code}"
81
+
82
+ # def query_brave(query):
83
+ # headers = {"X-API-Key": BRAVE_API_KEY}
84
+ # params = {
85
+ # "q": query,
86
+ # "count": 1,
87
+ # "summary": True
88
+ # }
89
+ # response = requests.get("https://api.search.brave.com/res/v1/web/search", params=params, headers=headers)
90
+ # if response.status_code == 200:
91
+ # return response.json().get("summary", "No summary available.")
92
+ # else:
93
+ # return f"Request failed with status code: {response}"
94
+
95
+
96
+ # def brave_search_summarization(query):
97
+ # # Endpoint for web search with summary
98
+ # web_search_url = "https://api.search.brave.com/res/v1/web/search"
99
+ # summarizer_url = "https://api.search.brave.com/res/v1/summarizer/search"
100
+
101
+ # # Headers for the requests
102
+ # headers = {
103
+ # "Accept": "application/json",
104
+ # "Accept-Encoding": "gzip",
105
+ # "X-Subscription-Token": BRAVE_API_KEY
106
+ # }
107
+
108
+ # # Parameters for the initial web search request
109
+ # web_search_params = {
110
+ # "q": query,
111
+ # "summary": 1
112
+ # }
113
+
114
+ # # Make the initial request to the web search endpoint
115
+ # web_search_response = requests.get(web_search_url, headers=headers, params=web_search_params)
116
+
117
+ # # Check if the request was successful
118
+ # if web_search_response.status_code != 200:
119
+ # raise Exception(f"Web search request failed with status code {web_search_response.status_code}")
120
+
121
+ # web_search_data = web_search_response.json()
122
+
123
+ # # Extract the summarizer key from the response
124
+ # summarizer_key = web_search_data.get('summarizer', {}).get('key')
125
+ # if not summarizer_key:
126
+ # raise Exception("No summarizer key found in the web search response")
127
+
128
+ # # Parameters for the summarizer request
129
+ # summarizer_params = {
130
+ # "key": summarizer_key,
131
+ # "entity_info": 1
132
+ # }
133
+
134
+ # # Make the request to the summarizer endpoint
135
+ # summarizer_response = requests.get(summarizer_url, headers=headers, params=summarizer_params)
136
+
137
+ # # Check if the request was successful
138
+ # if summarizer_response.status_code != 200:
139
+ # raise Exception(f"Summarizer request failed with status code {summarizer_response.status_code}")
140
+
141
+ # summarizer_data = summarizer_response.json()
142
+
143
+ # # Return the summarized content
144
+ # return summarizer_data
145
+
146
+ def ProcessQuestion(question, model):
147
+ if model == "You.com":
148
+ return query_you_com(question)
149
+ elif model == "Tavily.com":
150
+ return query_tavily(question)
151
+ elif model == "Perplexity.ai":
152
+ return query_perplexity(question)
153
+ elif model == "Brave.com":
154
+ return query_brave(question)
155
+ else:
156
+ return "Model not supported"
requirements.txt CHANGED
@@ -2,3 +2,4 @@ swarms
2
  exa_py
3
  tavily-python
4
  openai
 
 
2
  exa_py
3
  tavily-python
4
  openai
5
+ exa_py
test_func.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from helpers import query_you_com, query_tavily, query_perplexity #, brave_search_summarization,
2
+
3
+ def test_queries():
4
+ test_query = "How is the weather in Palo Alto, CA?"
5
+
6
+ print("Testing You.com API:")
7
+ # you_com_result = query_you_com(test_query)
8
+ you_com_result = query_you_com(test_query)
9
+ print(you_com_result['answer'])
10
+
11
+ print("\nTesting Tavily.com API:")
12
+ tavily_result = query_tavily(test_query)
13
+ print(tavily_result['answer'])
14
+
15
+ print("\nTesting Perplexity.ai API:")
16
+ perplexity_result = query_perplexity(test_query)
17
+ print(perplexity_result)
18
+
19
+ # print("\nTesting Brave.com API:")
20
+ # brave_result = brave_search_summarization(test_query)
21
+ # print(brave_result)
22
+
23
+ if __name__ == "__main__":
24
+ test_queries()