Spaces:
Paused
Paused
jpfearnworks
commited on
Commit
Β·
9d0c72d
1
Parent(s):
040f332
Decouple components from interface, adds tabs
Browse files- Dockerfile +2 -2
- README.MD +1 -1
- {src β modules}/__init__.py +0 -0
- modules/domains/__init__.py +0 -0
- {src β modules}/reasoning/__init__.py +3 -2
- {src β modules}/reasoning/chain_of_thought.py +0 -0
- modules/reasoning/component.py +32 -0
- src/reasoning/react.py β modules/reasoning/re_act.py +8 -8
- {src β modules}/reasoning/reasoning_router.py +2 -2
- {src β modules}/reasoning/reasoning_strategy.py +0 -0
- {src β modules}/reasoning/tree_of_thought.py +0 -0
- server.py +24 -0
- src/main.py +0 -26
- src/streamlit_main.py +0 -30
Dockerfile
CHANGED
@@ -8,11 +8,11 @@ RUN pip install -r requirements.txt
|
|
8 |
|
9 |
COPY . .
|
10 |
|
11 |
-
WORKDIR /app/
|
12 |
|
13 |
ENV PATH="/root/.local/bin:${PATH}"
|
14 |
|
15 |
EXPOSE 8501
|
16 |
EXPOSE 7000
|
17 |
|
18 |
-
CMD python
|
|
|
8 |
|
9 |
COPY . .
|
10 |
|
11 |
+
WORKDIR /app/
|
12 |
|
13 |
ENV PATH="/root/.local/bin:${PATH}"
|
14 |
|
15 |
EXPOSE 8501
|
16 |
EXPOSE 7000
|
17 |
|
18 |
+
CMD python server.py
|
README.MD
CHANGED
@@ -4,7 +4,7 @@ Heavily inspired by examples and code across the AI Open Source community but wi
|
|
4 |
|
5 |
## UI
|
6 |
Front end for templates currently uses streamlit, however display for each agent example will be heavily decoupled from deployment avenue.
|
7 |
-
Strategies for jupyter,
|
8 |
|
9 |
## Modules
|
10 |
|
|
|
4 |
|
5 |
## UI
|
6 |
Front end for templates currently uses streamlit, however display for each agent example will be heavily decoupled from deployment avenue.
|
7 |
+
Strategies for jupyter, gradio, and react will be prioritized in general at this time.
|
8 |
|
9 |
## Modules
|
10 |
|
{src β modules}/__init__.py
RENAMED
File without changes
|
modules/domains/__init__.py
ADDED
File without changes
|
{src β modules}/reasoning/__init__.py
RENAMED
@@ -1,5 +1,6 @@
|
|
1 |
-
from .
|
2 |
from .tree_of_thought import TreeOfThoughtStrategy, get_tot_config
|
3 |
from .chain_of_thought import ChainOfThoughtStrategy, get_cot_confg
|
4 |
from .reasoning_router import ReasoningRouter, get_reasoning_router_config
|
5 |
-
from .reasoning_strategy import ReasoningStrategy, ReasoningConfig, get_reasoning_config
|
|
|
|
1 |
+
from .re_act import ReActStrategy, get_re_act_config
|
2 |
from .tree_of_thought import TreeOfThoughtStrategy, get_tot_config
|
3 |
from .chain_of_thought import ChainOfThoughtStrategy, get_cot_confg
|
4 |
from .reasoning_router import ReasoningRouter, get_reasoning_router_config
|
5 |
+
from .reasoning_strategy import ReasoningStrategy, ReasoningConfig, get_reasoning_config
|
6 |
+
from .component import create_reasoning_router_ui
|
{src β modules}/reasoning/chain_of_thought.py
RENAMED
File without changes
|
modules/reasoning/component.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from modules.reasoning.reasoning_router import ReasoningRouter, get_reasoning_router_config
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
5 |
+
|
6 |
+
|
7 |
+
def determine_and_execute(question, temperature):
|
8 |
+
config = get_reasoning_router_config(temperature=temperature)
|
9 |
+
config.temperature = temperature
|
10 |
+
determiner = ReasoningRouter(api_key=openai_api_key, config=config, question=question, display=print)
|
11 |
+
determine_output, execute_output = determiner.determine_and_execute()
|
12 |
+
return determine_output, execute_output
|
13 |
+
|
14 |
+
examples = [["""Bob is in the living room.
|
15 |
+
He walks to the kitchen, carrying a cup.
|
16 |
+
He puts a ball in the cup and carries the cup to the bedroom.
|
17 |
+
He turns the cup upside down, then walks to the garden.
|
18 |
+
He puts the cup down in the garden, then walks to the garage.
|
19 |
+
Where is the ball?""", 0.6], ["Given the task of building a house in the middle of a river, what are three strategies I could use to mitigate risk of flooding?", 0.6 ]]
|
20 |
+
|
21 |
+
def create_reasoning_router_ui(cache_examples=False):
|
22 |
+
with gr.Row():
|
23 |
+
question = gr.Textbox(label="Enter your question here:")
|
24 |
+
temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
|
25 |
+
with gr.Column():
|
26 |
+
reasoning_strategy = gr.Textbox(label="Reasoning Strategy")
|
27 |
+
reasoning = gr.Textbox(label="Reasoning")
|
28 |
+
|
29 |
+
generate_button = gr.Button(label="Generate")
|
30 |
+
generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature])
|
31 |
+
gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature], outputs=[reasoning_strategy, reasoning])
|
32 |
+
|
src/reasoning/react.py β modules/reasoning/re_act.py
RENAMED
@@ -6,7 +6,7 @@ from langchain.agents.react.base import DocstoreExplorer
|
|
6 |
from typing import Callable, Optional
|
7 |
import pprint
|
8 |
|
9 |
-
class
|
10 |
def __init__(self, config: ReasoningConfig, display: Callable):
|
11 |
super().__init__(config=config, display=display)
|
12 |
print("Creating reAct strategy with config: ",)
|
@@ -29,18 +29,18 @@ class ReactStrategy(ReasoningStrategy):
|
|
29 |
description="Lookup a term in the docstore.",
|
30 |
)
|
31 |
]
|
32 |
-
|
33 |
agent_executor = AgentExecutor.from_agent_and_tools(
|
34 |
-
agent=
|
35 |
tools=tools,
|
36 |
verbose=True,
|
37 |
)
|
38 |
-
|
39 |
-
print(
|
40 |
-
self.display(
|
41 |
-
return
|
42 |
|
43 |
-
def
|
44 |
usage = """
|
45 |
The solution for this problem requires searching for further information online,
|
46 |
generating reasoning traces and task-specific actions in an interleaved manner.
|
|
|
6 |
from typing import Callable, Optional
|
7 |
import pprint
|
8 |
|
9 |
+
class ReActStrategy(ReasoningStrategy):
|
10 |
def __init__(self, config: ReasoningConfig, display: Callable):
|
11 |
super().__init__(config=config, display=display)
|
12 |
print("Creating reAct strategy with config: ",)
|
|
|
29 |
description="Lookup a term in the docstore.",
|
30 |
)
|
31 |
]
|
32 |
+
re_act = initialize_agent(tools, self.llm, agent="react-docstore", verbose=True)
|
33 |
agent_executor = AgentExecutor.from_agent_and_tools(
|
34 |
+
agent=re_act.agent,
|
35 |
tools=tools,
|
36 |
verbose=True,
|
37 |
)
|
38 |
+
response_re_act = agent_executor.run(question)
|
39 |
+
print(response_re_act)
|
40 |
+
self.display(response_re_act)
|
41 |
+
return response_re_act
|
42 |
|
43 |
+
def get_re_act_config(temperature: float = 0.7) -> ReasoningConfig:
|
44 |
usage = """
|
45 |
The solution for this problem requires searching for further information online,
|
46 |
generating reasoning traces and task-specific actions in an interleaved manner.
|
{src β modules}/reasoning/reasoning_router.py
RENAMED
@@ -1,5 +1,5 @@
|
|
1 |
from langchain import PromptTemplate, LLMChain
|
2 |
-
from .
|
3 |
from .tree_of_thought import TreeOfThoughtStrategy, get_tot_config
|
4 |
from .chain_of_thought import ChainOfThoughtStrategy, get_cot_confg
|
5 |
from .reasoning_strategy import ReasoningConfig
|
@@ -28,7 +28,7 @@ class ReasoningRouter:
|
|
28 |
|
29 |
|
30 |
self.strategies = {
|
31 |
-
1:
|
32 |
2: TreeOfThoughtStrategy(get_tot_config(temperature=config.temperature),display=self.display),
|
33 |
3: ChainOfThoughtStrategy(get_cot_confg(temperature=config.temperature),display=self.display)
|
34 |
}
|
|
|
1 |
from langchain import PromptTemplate, LLMChain
|
2 |
+
from .re_act import ReActStrategy, get_re_act_config
|
3 |
from .tree_of_thought import TreeOfThoughtStrategy, get_tot_config
|
4 |
from .chain_of_thought import ChainOfThoughtStrategy, get_cot_confg
|
5 |
from .reasoning_strategy import ReasoningConfig
|
|
|
28 |
|
29 |
|
30 |
self.strategies = {
|
31 |
+
1: ReActStrategy(get_re_act_config(temperature=config.temperature), display=self.display),
|
32 |
2: TreeOfThoughtStrategy(get_tot_config(temperature=config.temperature),display=self.display),
|
33 |
3: ChainOfThoughtStrategy(get_cot_confg(temperature=config.temperature),display=self.display)
|
34 |
}
|
{src β modules}/reasoning/reasoning_strategy.py
RENAMED
File without changes
|
{src β modules}/reasoning/tree_of_thought.py
RENAMED
File without changes
|
server.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv, find_dotenv
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
from modules.reasoning.component import create_reasoning_router_ui
|
5 |
+
load_dotenv(find_dotenv())
|
6 |
+
|
7 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
def create_interface():
|
12 |
+
title: str = "Prompt Strategy Demo"
|
13 |
+
description: str = "AI Agents Sandbox"
|
14 |
+
with gr.Blocks(analytics_enabled=False, capture_session=True, title=title, description=description) as interface:
|
15 |
+
with gr.Tab("Reasoning Router"):
|
16 |
+
create_reasoning_router_ui()
|
17 |
+
with gr.Tab("Knowledge Domains"):
|
18 |
+
gr.Label("Knowledge Domains")
|
19 |
+
interface.queue()
|
20 |
+
interface.launch(server_name="0.0.0.0", server_port=7000)
|
21 |
+
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
create_interface()
|
src/main.py
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
from dotenv import load_dotenv, find_dotenv
|
2 |
-
import os
|
3 |
-
import gradio as gr
|
4 |
-
from reasoning import ReasoningRouter, get_reasoning_router_config
|
5 |
-
load_dotenv(find_dotenv())
|
6 |
-
|
7 |
-
openai_api_key = os.getenv("OPENAI_API_KEY")
|
8 |
-
|
9 |
-
|
10 |
-
def determine_and_execute(question, temperature):
|
11 |
-
config = get_reasoning_router_config(temperature=temperature)
|
12 |
-
config.temperature = temperature
|
13 |
-
determiner = ReasoningRouter(api_key=openai_api_key, config=config, question=question, display=print)
|
14 |
-
determine_output, execute_output = determiner.determine_and_execute()
|
15 |
-
return determine_output, execute_output
|
16 |
-
|
17 |
-
iface = gr.Interface(
|
18 |
-
fn=determine_and_execute,
|
19 |
-
inputs=[gr.components.Textbox(label="Enter your question here:"), gr.components.Slider(minimum=0, maximum=2, default=.7, label="Temperature")],
|
20 |
-
outputs=[gr.components.Textbox(label="Reasoning Strategy"), gr.components.Textbox(label="Reasoning")],
|
21 |
-
title="Prompt Strategy Demo",
|
22 |
-
description="AI Agents Sandbox"
|
23 |
-
)
|
24 |
-
|
25 |
-
if __name__ == "__main__":
|
26 |
-
iface.launch(server_name="0.0.0.0", server_port=7000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/streamlit_main.py
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
from dotenv import load_dotenv, find_dotenv
|
2 |
-
import os
|
3 |
-
import streamlit as st
|
4 |
-
from reasoning import ReasoningRouter, get_reasoning_router_config
|
5 |
-
load_dotenv(find_dotenv())
|
6 |
-
|
7 |
-
|
8 |
-
def run_app():
|
9 |
-
"""
|
10 |
-
Runs the Streamlit application.
|
11 |
-
|
12 |
-
Returns:
|
13 |
-
None
|
14 |
-
"""
|
15 |
-
openai_api_key = os.getenv("OPENAI_API_KEY")
|
16 |
-
|
17 |
-
col1, col2 = st.columns([1, 3])
|
18 |
-
with col1:
|
19 |
-
st.text("AI Agents Sandbox")
|
20 |
-
with col2:
|
21 |
-
st.title("Prompt Strategy Demo")
|
22 |
-
question = st.text_area('Enter your question here:', height=200)
|
23 |
-
config = get_reasoning_router_config()
|
24 |
-
if question:
|
25 |
-
determiner = ReasoningRouter(api_key=openai_api_key, config=config, question=question,display=st.write)
|
26 |
-
determiner.determine_and_execute()
|
27 |
-
|
28 |
-
if __name__ == "__main__":
|
29 |
-
run_app()
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|