Spaces:
Running
Running
Add datetime to log
#2
by
riversky
- opened
- .github/workflows/sync-to-hf.yaml +1 -2
- LICENSE +0 -21
- README-main.md +1 -103
- README.md +2 -2
- autoagents/agents/search.py +11 -12
- autoagents/models/custom.py +0 -33
- autoagents/spaces/app.py +11 -25
- autoagents/tools/tools.py +4 -5
- autoagents/utils/constants.py +8 -16
- autoagents/utils/logger.py +1 -1
- requirements.txt +2 -2
- setup.py +0 -7
- test.py +15 -23
.github/workflows/sync-to-hf.yaml
CHANGED
@@ -14,8 +14,7 @@ jobs:
|
|
14 |
with:
|
15 |
fetch-depth: 0
|
16 |
lfs: true
|
17 |
-
ref: hf-active
|
18 |
- name: Push to hub
|
19 |
env:
|
20 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
21 |
-
run: git push https://omkarenator:$HF_TOKEN@huggingface.co/spaces/AutoLLM/AutoAgents
|
|
|
14 |
with:
|
15 |
fetch-depth: 0
|
16 |
lfs: true
|
|
|
17 |
- name: Push to hub
|
18 |
env:
|
19 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
20 |
+
run: git push https://omkarenator:$HF_TOKEN@huggingface.co/spaces/AutoLLM/AutoAgents main
|
LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
MIT License
|
2 |
-
|
3 |
-
Copyright (c) 2023 AutoLLM
|
4 |
-
|
5 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
-
of this software and associated documentation files (the "Software"), to deal
|
7 |
-
in the Software without restriction, including without limitation the rights
|
8 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
-
copies of the Software, and to permit persons to whom the Software is
|
10 |
-
furnished to do so, subject to the following conditions:
|
11 |
-
|
12 |
-
The above copyright notice and this permission notice shall be included in all
|
13 |
-
copies or substantial portions of the Software.
|
14 |
-
|
15 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
-
SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README-main.md
CHANGED
@@ -1,103 +1 @@
|
|
1 |
-
# AutoAgents
|
2 |
-
|
3 |
-
<p align="center"><img src="https://raw.githubusercontent.com/AutoLLM/AutoAgents/assets/images/logo.png?raw=true" width=400/></p>
|
4 |
-
|
5 |
-
Unlock complex question answering in LLMs with enhanced chain-of-thought reasoning and information-seeking capabilities.
|
6 |
-
|
7 |
-
## 👉 Overview
|
8 |
-
|
9 |
-
The purpose of this project is to extend LLMs ability to answer more complex questions through chain-of-thought reasoning and information-seeking actions.
|
10 |
-
|
11 |
-
We are excited to release the initial version of AutoAgents, a proof-of-concept on what can be achieved with only well-written prompts. This is the initial step towards our first big milestone, releasing and open-sourcing the AutoAgents 7B model!
|
12 |
-
|
13 |
-
Come try out our [Huggingface Space](https://huggingface.co/spaces/AutoLLM/AutoAgents)!
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
## 🤖 The AutoAgents Project
|
18 |
-
|
19 |
-
This project demonstrates LLMs capability to execute a complex user goal: understand a user's goal, generate a plan, use proper tools, and deliver a final result.
|
20 |
-
|
21 |
-
For simplicity, our first attempt starts with a Web Search Agent.
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
## 💫 How it works:
|
26 |
-
|
27 |
-
<p align="left"><img src="https://raw.githubusercontent.com/AutoLLM/AutoAgents/assets/images/agent.png" width=830/></p>
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
## 📔 Examples
|
32 |
-
|
33 |
-
Ask your AutoAgent to do what a real person would do using the internet:
|
34 |
-
|
35 |
-
For example:
|
36 |
-
|
37 |
-
*1. Recommend a kid friendly movie that is playing at a theater near Sunnyvale. Give me the showtimes and a link to purchase the tickets*
|
38 |
-
|
39 |
-
*2. What is the average age of the past three president when they took office*
|
40 |
-
|
41 |
-
*3. What is the mortgage rate right now and how does that compare to the past two years*
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
## 💁 Roadmap
|
46 |
-
|
47 |
-
* ~~HuggingFace Space demo using OpenAI models~~ [LINK](https://huggingface.co/spaces/AutoLLM/AutoAgents)
|
48 |
-
* AutoAgents [7B] Model
|
49 |
-
* Initial Release:
|
50 |
-
* Finetune and release a 7B parameter fine-tuned search model
|
51 |
-
* AutoAgents Dataset
|
52 |
-
* A high-quality dataset for a diverse set of search scenarios (why quality and diversity?<sup>[1](https://arxiv.org/abs/2305.11206)</sup>)
|
53 |
-
* Reduce Model Inference Overhead
|
54 |
-
* Affordance Modeling <sup>[2](https://en.wikipedia.org/wiki/Affordance)</sup>
|
55 |
-
* Extend Support to Additional Tools
|
56 |
-
* Customizable Document Search set (e.g. personal documents)
|
57 |
-
* Support Multi-turn Dialogue
|
58 |
-
* Advanced Flow Control in Plan Execution
|
59 |
-
|
60 |
-
We are actively developing a few interesting things, check back here or follow us on [Twitter](https://twitter.com/AutoLLM) for any new development.
|
61 |
-
|
62 |
-
If you are interested in any other problems, feel free to shoot us an issue.
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
## 🧭 How to use this repo?
|
67 |
-
|
68 |
-
This repo contains the entire code to run the search agent from your local browser. All you need is an OpenAI API key to begin.
|
69 |
-
|
70 |
-
To run the search agent locally:
|
71 |
-
|
72 |
-
1. Clone the repo and change the directory
|
73 |
-
|
74 |
-
```bash
|
75 |
-
git clone https://github.com/AutoLLM/AutoAgents.git
|
76 |
-
cd AutoAgents
|
77 |
-
```
|
78 |
-
|
79 |
-
2. Install the dependencies
|
80 |
-
|
81 |
-
```bash
|
82 |
-
pip install -r requirements.txt
|
83 |
-
```
|
84 |
-
|
85 |
-
3. Install the `autoagents` package
|
86 |
-
|
87 |
-
```bash
|
88 |
-
pip install -e .
|
89 |
-
```
|
90 |
-
|
91 |
-
4. Make sure you have your OpenAI API key set as an environment variable. Alternatively, you can also feed it through the input text-box on the sidebar.
|
92 |
-
|
93 |
-
```bash
|
94 |
-
export OPENAI_API_KEY=sk-xxxxxx
|
95 |
-
```
|
96 |
-
|
97 |
-
5. Run the Streamlit app
|
98 |
-
|
99 |
-
```bash
|
100 |
-
streamlit run autoagents/spaces/app.py
|
101 |
-
```
|
102 |
-
|
103 |
-
This should open a browser window where you can type your search query.
|
|
|
1 |
+
# AutoAgents!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 🐢
|
4 |
colorFrom: green
|
5 |
colorTo: purple
|
@@ -7,7 +7,7 @@ sdk: streamlit
|
|
7 |
sdk_version: 1.21.0
|
8 |
python_version: 3.10.11
|
9 |
app_file: autoagents/spaces/app.py
|
10 |
-
pinned:
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Search Llm
|
3 |
emoji: 🐢
|
4 |
colorFrom: green
|
5 |
colorTo: purple
|
|
|
7 |
sdk_version: 1.21.0
|
8 |
python_version: 3.10.11
|
9 |
app_file: autoagents/spaces/app.py
|
10 |
+
pinned: false
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
autoagents/agents/search.py
CHANGED
@@ -4,7 +4,6 @@ import re
|
|
4 |
from datetime import date
|
5 |
import asyncio
|
6 |
from collections import defaultdict
|
7 |
-
import os
|
8 |
|
9 |
from langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser
|
10 |
from langchain.prompts import StringPromptTemplate
|
@@ -14,7 +13,7 @@ from langchain.schema import AgentAction, AgentFinish
|
|
14 |
from langchain.callbacks import get_openai_callback
|
15 |
from langchain.callbacks.base import AsyncCallbackHandler
|
16 |
from langchain.callbacks.manager import AsyncCallbackManager
|
17 |
-
|
18 |
|
19 |
from autoagents.tools.tools import search_tool, note_tool, rewrite_search_query
|
20 |
from autoagents.utils.logger import InteractionsLogger
|
@@ -78,7 +77,7 @@ class CustomPromptTemplate(StringPromptTemplate):
|
|
78 |
outputs += f"{action.log}\n"
|
79 |
if len(intermediate_steps) > 0:
|
80 |
action, observation = intermediate_steps[-1]
|
81 |
-
|
82 |
if action.tool not in ("Search", "Notepad"):
|
83 |
raise Exception("Invalid tool requested by the model.")
|
84 |
if action.tool == "Notepad":
|
@@ -115,7 +114,9 @@ class CustomPromptTemplate(StringPromptTemplate):
|
|
115 |
kwargs["tool_names"] = ", ".join([tool.name for tool in self.tools])
|
116 |
kwargs["today"] = date.today()
|
117 |
final_prompt = self.template.format(**kwargs)
|
118 |
-
|
|
|
|
|
119 |
return final_prompt
|
120 |
|
121 |
|
@@ -123,8 +124,9 @@ class CustomOutputParser(AgentOutputParser):
|
|
123 |
class Config:
|
124 |
arbitrary_types_allowed = True
|
125 |
ialogger: InteractionsLogger
|
126 |
-
|
127 |
new_action_input: Optional[str]
|
|
|
128 |
action_history = defaultdict(set)
|
129 |
|
130 |
def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]:
|
@@ -152,8 +154,7 @@ class CustomOutputParser(AgentOutputParser):
|
|
152 |
if action_input in self.action_history[action]:
|
153 |
new_action_input = rewrite_search_query(action_input,
|
154 |
self.action_history[action],
|
155 |
-
self.
|
156 |
-
self.ialogger.add_message({"query_rewrite": True})
|
157 |
self.new_action_input = new_action_input
|
158 |
self.action_history[action].add(new_action_input)
|
159 |
return AgentAction(tool=action, tool_input=new_action_input, log=llm_output)
|
@@ -164,10 +165,7 @@ class CustomOutputParser(AgentOutputParser):
|
|
164 |
|
165 |
|
166 |
class ActionRunner:
|
167 |
-
def __init__(self,
|
168 |
-
outputq,
|
169 |
-
llm: BaseLanguageModel,
|
170 |
-
persist_logs: bool = False):
|
171 |
self.ialogger = InteractionsLogger(name=f"{uuid.uuid4().hex[:6]}", persist=persist_logs)
|
172 |
tools = [search_tool, note_tool]
|
173 |
prompt = CustomPromptTemplate(
|
@@ -176,7 +174,7 @@ class ActionRunner:
|
|
176 |
input_variables=["input", "intermediate_steps"],
|
177 |
ialogger=self.ialogger)
|
178 |
|
179 |
-
output_parser = CustomOutputParser(ialogger=self.ialogger,
|
180 |
|
181 |
class MyCustomHandler(AsyncCallbackHandler):
|
182 |
def __init__(self):
|
@@ -222,6 +220,7 @@ class ActionRunner:
|
|
222 |
|
223 |
handler = MyCustomHandler()
|
224 |
|
|
|
225 |
llm_chain = LLMChain(llm=llm, prompt=prompt, callbacks=[handler])
|
226 |
tool_names = [tool.name for tool in tools]
|
227 |
for tool in tools:
|
|
|
4 |
from datetime import date
|
5 |
import asyncio
|
6 |
from collections import defaultdict
|
|
|
7 |
|
8 |
from langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser
|
9 |
from langchain.prompts import StringPromptTemplate
|
|
|
13 |
from langchain.callbacks import get_openai_callback
|
14 |
from langchain.callbacks.base import AsyncCallbackHandler
|
15 |
from langchain.callbacks.manager import AsyncCallbackManager
|
16 |
+
|
17 |
|
18 |
from autoagents.tools.tools import search_tool, note_tool, rewrite_search_query
|
19 |
from autoagents.utils.logger import InteractionsLogger
|
|
|
77 |
outputs += f"{action.log}\n"
|
78 |
if len(intermediate_steps) > 0:
|
79 |
action, observation = intermediate_steps[-1]
|
80 |
+
self.ialogger.add_system({"action": action, "observation": observation})
|
81 |
if action.tool not in ("Search", "Notepad"):
|
82 |
raise Exception("Invalid tool requested by the model.")
|
83 |
if action.tool == "Notepad":
|
|
|
114 |
kwargs["tool_names"] = ", ".join([tool.name for tool in self.tools])
|
115 |
kwargs["today"] = date.today()
|
116 |
final_prompt = self.template.format(**kwargs)
|
117 |
+
if not intermediate_steps:
|
118 |
+
# first iteration
|
119 |
+
self.ialogger.add_system({"prompt": final_prompt})
|
120 |
return final_prompt
|
121 |
|
122 |
|
|
|
124 |
class Config:
|
125 |
arbitrary_types_allowed = True
|
126 |
ialogger: InteractionsLogger
|
127 |
+
api_key: str
|
128 |
new_action_input: Optional[str]
|
129 |
+
|
130 |
action_history = defaultdict(set)
|
131 |
|
132 |
def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]:
|
|
|
154 |
if action_input in self.action_history[action]:
|
155 |
new_action_input = rewrite_search_query(action_input,
|
156 |
self.action_history[action],
|
157 |
+
self.api_key)
|
|
|
158 |
self.new_action_input = new_action_input
|
159 |
self.action_history[action].add(new_action_input)
|
160 |
return AgentAction(tool=action, tool_input=new_action_input, log=llm_output)
|
|
|
165 |
|
166 |
|
167 |
class ActionRunner:
|
168 |
+
def __init__(self, outputq, api_key: str, model_name: str, persist_logs=False):
|
|
|
|
|
|
|
169 |
self.ialogger = InteractionsLogger(name=f"{uuid.uuid4().hex[:6]}", persist=persist_logs)
|
170 |
tools = [search_tool, note_tool]
|
171 |
prompt = CustomPromptTemplate(
|
|
|
174 |
input_variables=["input", "intermediate_steps"],
|
175 |
ialogger=self.ialogger)
|
176 |
|
177 |
+
output_parser = CustomOutputParser(ialogger=self.ialogger, api_key=api_key)
|
178 |
|
179 |
class MyCustomHandler(AsyncCallbackHandler):
|
180 |
def __init__(self):
|
|
|
220 |
|
221 |
handler = MyCustomHandler()
|
222 |
|
223 |
+
llm = ChatOpenAI(openai_api_key=api_key, temperature=0, model_name=model_name)
|
224 |
llm_chain = LLMChain(llm=llm, prompt=prompt, callbacks=[handler])
|
225 |
tool_names = [tool.name for tool in tools]
|
226 |
for tool in tools:
|
autoagents/models/custom.py
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
|
3 |
-
from langchain.llms.base import LLM
|
4 |
-
|
5 |
-
|
6 |
-
class CustomLLM(LLM):
|
7 |
-
@property
|
8 |
-
def _llm_type(self) -> str:
|
9 |
-
return "custom"
|
10 |
-
|
11 |
-
def _call(self, prompt: str, stop=None) -> str:
|
12 |
-
r = requests.post(
|
13 |
-
"http://localhost:8000/v1/chat/completions",
|
14 |
-
json={
|
15 |
-
"model": "283-vicuna-7b",
|
16 |
-
"messages": [{"role": "user", "content": prompt}],
|
17 |
-
"stop": stop
|
18 |
-
},
|
19 |
-
)
|
20 |
-
result = r.json()
|
21 |
-
return result["choices"][0]["message"]["content"]
|
22 |
-
|
23 |
-
async def _acall(self, prompt: str, stop=None) -> str:
|
24 |
-
r = requests.post(
|
25 |
-
"http://localhost:8000/v1/chat/completions",
|
26 |
-
json={
|
27 |
-
"model": "283-vicuna-7b",
|
28 |
-
"messages": [{"role": "user", "content": prompt}],
|
29 |
-
"stop": stop
|
30 |
-
},
|
31 |
-
)
|
32 |
-
result = r.json()
|
33 |
-
return result["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
autoagents/spaces/app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import asyncio
|
3 |
import random
|
4 |
-
from datetime import date, datetime, timezone, timedelta
|
5 |
from ast import literal_eval
|
6 |
|
7 |
import streamlit as st
|
@@ -10,8 +9,6 @@ import openai
|
|
10 |
from autoagents.utils.constants import MAIN_HEADER, MAIN_CAPTION, SAMPLE_QUESTIONS
|
11 |
from autoagents.agents.search import ActionRunner
|
12 |
|
13 |
-
from langchain.chat_models import ChatOpenAI
|
14 |
-
|
15 |
|
16 |
async def run():
|
17 |
output_acc = ""
|
@@ -45,14 +42,13 @@ async def run():
|
|
45 |
)
|
46 |
|
47 |
# Ask the user to enter their OpenAI API key
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
api_key, api_org = os.getenv("OPENAI_API_KEY"), os.getenv("OPENAI_API_ORG")
|
52 |
with st.sidebar:
|
53 |
model_dict = {
|
54 |
"gpt-3.5-turbo": "GPT-3.5-turbo",
|
55 |
-
"gpt-4": "GPT-4 (
|
56 |
}
|
57 |
st.radio(
|
58 |
"OpenAI model",
|
@@ -61,29 +57,22 @@ async def run():
|
|
61 |
format_func=lambda x: model_dict[x],
|
62 |
)
|
63 |
|
64 |
-
time_zone = str(datetime.now(timezone(timedelta(0))).astimezone().tzinfo)
|
65 |
-
st.markdown(f"**The system time zone is {time_zone} and the date is {date.today()}**")
|
66 |
-
|
67 |
st.markdown("**Example Queries:**")
|
68 |
for q in SAMPLE_QUESTIONS:
|
69 |
st.markdown(f"*{q}*")
|
70 |
|
71 |
-
if not
|
72 |
st.warning(
|
73 |
"API key required to try this app. The API key is not stored in any form. [This](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key) might help."
|
74 |
)
|
75 |
-
elif api_org and st.session_state.model_name == "gpt-4":
|
76 |
-
st.warning(
|
77 |
-
"The free API key does not support GPT-4. Please switch to GPT-3.5-turbo or input your own API key."
|
78 |
-
)
|
79 |
else:
|
80 |
outputq = asyncio.Queue()
|
81 |
-
runner = ActionRunner(
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
|
88 |
async def cleanup(e):
|
89 |
st.error(e)
|
@@ -111,9 +100,6 @@ async def run():
|
|
111 |
if isinstance(output, Exception):
|
112 |
if isinstance(output, openai.error.AuthenticationError):
|
113 |
await cleanup(f"AuthenticationError: Invalid OpenAI API key.")
|
114 |
-
elif isinstance(output, openai.error.InvalidRequestError) \
|
115 |
-
and output._message == "The model: `gpt-4` does not exist":
|
116 |
-
await cleanup(f"The free API key does not support GPT-4. Please switch to GPT-3.5-turbo or input your own API key.")
|
117 |
elif isinstance(output, openai.error.OpenAIError):
|
118 |
await cleanup(output)
|
119 |
elif isinstance(output, RuntimeWarning):
|
|
|
1 |
import os
|
2 |
import asyncio
|
3 |
import random
|
|
|
4 |
from ast import literal_eval
|
5 |
|
6 |
import streamlit as st
|
|
|
9 |
from autoagents.utils.constants import MAIN_HEADER, MAIN_CAPTION, SAMPLE_QUESTIONS
|
10 |
from autoagents.agents.search import ActionRunner
|
11 |
|
|
|
|
|
12 |
|
13 |
async def run():
|
14 |
output_acc = ""
|
|
|
42 |
)
|
43 |
|
44 |
# Ask the user to enter their OpenAI API key
|
45 |
+
API_O = st.sidebar.text_input("OpenAI api-key", type="password") or os.getenv(
|
46 |
+
"OPENAI_API_KEY"
|
47 |
+
)
|
|
|
48 |
with st.sidebar:
|
49 |
model_dict = {
|
50 |
"gpt-3.5-turbo": "GPT-3.5-turbo",
|
51 |
+
"gpt-4": "GPT-4 (Recommneded for better quality results)",
|
52 |
}
|
53 |
st.radio(
|
54 |
"OpenAI model",
|
|
|
57 |
format_func=lambda x: model_dict[x],
|
58 |
)
|
59 |
|
|
|
|
|
|
|
60 |
st.markdown("**Example Queries:**")
|
61 |
for q in SAMPLE_QUESTIONS:
|
62 |
st.markdown(f"*{q}*")
|
63 |
|
64 |
+
if not API_O:
|
65 |
st.warning(
|
66 |
"API key required to try this app. The API key is not stored in any form. [This](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key) might help."
|
67 |
)
|
|
|
|
|
|
|
|
|
68 |
else:
|
69 |
outputq = asyncio.Queue()
|
70 |
+
runner = ActionRunner(
|
71 |
+
outputq,
|
72 |
+
api_key=API_O,
|
73 |
+
model_name=st.session_state.model_name,
|
74 |
+
persist_logs=True,
|
75 |
+
) # log to HF-dataset
|
76 |
|
77 |
async def cleanup(e):
|
78 |
st.error(e)
|
|
|
100 |
if isinstance(output, Exception):
|
101 |
if isinstance(output, openai.error.AuthenticationError):
|
102 |
await cleanup(f"AuthenticationError: Invalid OpenAI API key.")
|
|
|
|
|
|
|
103 |
elif isinstance(output, openai.error.OpenAIError):
|
104 |
await cleanup(output)
|
105 |
elif isinstance(output, RuntimeWarning):
|
autoagents/tools/tools.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
-
from duckpy import Client
|
4 |
from langchain import PromptTemplate, OpenAI, LLMChain
|
5 |
from langchain.agents import Tool
|
6 |
-
from
|
|
|
7 |
|
8 |
|
9 |
MAX_SEARCH_RESULTS = 20 # Number of search results to observe at a time
|
@@ -53,12 +51,13 @@ note_tool = Tool(name="Notepad",
|
|
53 |
description=notepad_description)
|
54 |
|
55 |
|
56 |
-
def rewrite_search_query(q: str, search_history,
|
57 |
history_string = '\n'.join(search_history)
|
58 |
template ="""We are using the Search tool.
|
59 |
# Previous queries:
|
60 |
{history_string}. \n\n Rewrite query {action_input} to be
|
61 |
different from the previous ones."""
|
|
|
62 |
prompt = PromptTemplate(template=template,
|
63 |
input_variables=["action_input", "history_string"])
|
64 |
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
|
|
|
|
|
|
|
|
1 |
from langchain import PromptTemplate, OpenAI, LLMChain
|
2 |
from langchain.agents import Tool
|
3 |
+
from duckpy import Client
|
4 |
+
from langchain.chat_models import ChatOpenAI
|
5 |
|
6 |
|
7 |
MAX_SEARCH_RESULTS = 20 # Number of search results to observe at a time
|
|
|
51 |
description=notepad_description)
|
52 |
|
53 |
|
54 |
+
def rewrite_search_query(q: str, search_history, api_key: str) -> str:
|
55 |
history_string = '\n'.join(search_history)
|
56 |
template ="""We are using the Search tool.
|
57 |
# Previous queries:
|
58 |
{history_string}. \n\n Rewrite query {action_input} to be
|
59 |
different from the previous ones."""
|
60 |
+
llm = ChatOpenAI(temperature=0, openai_api_key=api_key)
|
61 |
prompt = PromptTemplate(template=template,
|
62 |
input_variables=["action_input", "history_string"])
|
63 |
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
autoagents/utils/constants.py
CHANGED
@@ -1,21 +1,13 @@
|
|
1 |
MAIN_HEADER = "Web Search Agent"
|
2 |
|
3 |
-
MAIN_CAPTION = """This is a proof-of-concept search
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*DISCLAIMER*: We are collecting search queries, so please refrain from
|
9 |
-
providing any personal information. If you wish to avoid this, you can run the
|
10 |
-
app locally by following the instructions on our
|
11 |
-
[Github](https://github.com/AutoLLM/AutoAgents)."""
|
12 |
|
13 |
SAMPLE_QUESTIONS = [
|
14 |
-
"
|
15 |
-
"
|
16 |
-
"
|
17 |
-
"What is the mortgage rate right now and how does that compare to the past two years?",
|
18 |
-
"What is the weather like in San Francisco today? What about tomorrow?",
|
19 |
-
"When and where is the upcoming concert for Taylor Swift? Share a link to purchase tickets.",
|
20 |
-
"Find me recent studies focusing on hallucination in large language models. Provide the link to each study found.",
|
21 |
]
|
|
|
1 |
MAIN_HEADER = "Web Search Agent"
|
2 |
|
3 |
+
MAIN_CAPTION = """ This is a proof-of-concept search engine built on ReAct-style
|
4 |
+
prompting which acts as a search agent that plans and executes web searches on
|
5 |
+
your behalf. Given a high-level search query the agent tries to come up with a
|
6 |
+
concluding answer based off multiple rounds of searches. You can observe all
|
7 |
+
the intermediate interactions with the search engine below."""
|
|
|
|
|
|
|
|
|
8 |
|
9 |
SAMPLE_QUESTIONS = [
|
10 |
+
"What has David Sacks written about SAAS? Can you provide some links?",
|
11 |
+
"Where is the all-in summit 2023 being held and how much are the tickets?",
|
12 |
+
"Did Stan Druckenmiller buy Nvidia recently?",
|
|
|
|
|
|
|
|
|
13 |
]
|
autoagents/utils/logger.py
CHANGED
@@ -57,4 +57,4 @@ class InteractionsLogger:
|
|
57 |
commit_url = self.repo.push_to_hub()
|
58 |
|
59 |
def add_cost(self, cost):
|
60 |
-
self.messages.append({"metrics": cost})
|
|
|
57 |
commit_url = self.repo.push_to_hub()
|
58 |
|
59 |
def add_cost(self, cost):
|
60 |
+
self.messages.append({"metrics": cost})
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
openai>=0.27.7
|
2 |
-
langchain
|
3 |
duckpy
|
4 |
huggingface_hub
|
5 |
-
pytz
|
|
|
1 |
openai>=0.27.7
|
2 |
+
langchain
|
3 |
duckpy
|
4 |
huggingface_hub
|
5 |
+
pytz
|
setup.py
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
from setuptools import setup, find_packages
|
2 |
-
|
3 |
-
setup(
|
4 |
-
name='autoagents',
|
5 |
-
version='0.1.0',
|
6 |
-
packages=find_packages(include=['autoagents', 'autoagents.*'])
|
7 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.py
CHANGED
@@ -1,22 +1,16 @@
|
|
1 |
import os
|
2 |
import asyncio
|
3 |
-
|
|
|
4 |
from pprint import pprint
|
|
|
5 |
from ast import literal_eval
|
6 |
-
from multiprocessing import Pool, TimeoutError
|
7 |
-
|
8 |
-
from autoagents.agents.search import ActionRunner
|
9 |
-
from langchain.callbacks import get_openai_callback
|
10 |
-
from langchain.chat_models import ChatOpenAI
|
11 |
|
12 |
-
|
13 |
-
async def work(user_input):
|
14 |
outputq = asyncio.Queue()
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
model_name="gpt-3.5-turbo")
|
19 |
-
runner = ActionRunner(outputq, llm=llm)
|
20 |
task = asyncio.create_task(runner.run(user_input, outputq))
|
21 |
|
22 |
while True:
|
@@ -33,11 +27,12 @@ async def work(user_input):
|
|
33 |
break
|
34 |
await task
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
Q = [
|
37 |
-
"list 5 cities and their current populations where Paramore is playing this year.",
|
38 |
-
"Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?",
|
39 |
-
"How many watermelons can fit in a Tesla Model S?",
|
40 |
-
"Recommend me some laptops suitable for UI designers under $2000. Please include brand and price."
|
41 |
"Build me a vacation plan for Rome and Milan this summer for seven days. Include place to visit and hotels to stay. ",
|
42 |
"What is the sum of ages of the wives of Barack Obama and Donald Trump?",
|
43 |
"Who is the most recent NBA MVP? Which team does he play for? What is his season stats?",
|
@@ -49,9 +44,6 @@ Q = [
|
|
49 |
"Who are some top researchers in the field of machine learning systems nowadays?"
|
50 |
]
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
if __name__ == "__main__":
|
56 |
-
with Pool(processes=10) as pool:
|
57 |
-
print(pool.map(main, Q))
|
|
|
1 |
import os
|
2 |
import asyncio
|
3 |
+
from action import ActionRunner
|
4 |
+
from langchain.callbacks import get_openai_callback
|
5 |
from pprint import pprint
|
6 |
+
import pdb
|
7 |
from ast import literal_eval
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
async def main(user_input):
|
|
|
10 |
outputq = asyncio.Queue()
|
11 |
+
|
12 |
+
API_O = os.getenv("OPENAI_API_KEY")
|
13 |
+
runner = ActionRunner(outputq, api_key=API_O, model_name="gpt-3.5-turbo")
|
|
|
|
|
14 |
task = asyncio.create_task(runner.run(user_input, outputq))
|
15 |
|
16 |
while True:
|
|
|
27 |
break
|
28 |
await task
|
29 |
|
30 |
+
|
31 |
+
# "list 5 cities and their current populations where Paramore is playing this year.",
|
32 |
+
# "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?",
|
33 |
+
# "How many watermelons can fit in a Tesla Model S?",
|
34 |
+
# "Recommend me some laptops suitable for UI designers under $2000. Please include brand and price."
|
35 |
Q = [
|
|
|
|
|
|
|
|
|
36 |
"Build me a vacation plan for Rome and Milan this summer for seven days. Include place to visit and hotels to stay. ",
|
37 |
"What is the sum of ages of the wives of Barack Obama and Donald Trump?",
|
38 |
"Who is the most recent NBA MVP? Which team does he play for? What is his season stats?",
|
|
|
44 |
"Who are some top researchers in the field of machine learning systems nowadays?"
|
45 |
]
|
46 |
|
47 |
+
loop = asyncio.new_event_loop()
|
48 |
+
for i in range(len(Q)):
|
49 |
+
loop.run_until_complete(main(Q[i]))
|
|
|
|
|
|