Spaces:
Paused
Paused
jpfearnworks
commited on
Commit
·
26d2488
1
Parent(s):
3514c82
Decouple api key setting from router modules
Browse files- Dockerfile +1 -1
- modules/knowledge_retrieval/component.py +6 -5
- modules/reasoning/component.py +7 -5
- modules/settings/__init__.py +0 -0
- modules/settings/component.py +14 -0
- modules/settings/user_settings.py +21 -0
- server.py +15 -4
Dockerfile
CHANGED
@@ -15,4 +15,4 @@ ENV PATH="/root/.local/bin:${PATH}"
|
|
15 |
EXPOSE 8501
|
16 |
EXPOSE 7000
|
17 |
|
18 |
-
CMD python server.py
|
|
|
15 |
EXPOSE 8501
|
16 |
EXPOSE 7000
|
17 |
|
18 |
+
CMD python server.py
|
modules/knowledge_retrieval/component.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
from modules.knowledge_retrieval.knowledge_router import KnowledgeDomainRouter, get_knowledge_domain_router_config
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
-
|
5 |
|
6 |
def determine_and_execute(question: str, temperature: float, api_key = "" ):
|
7 |
-
|
|
|
8 |
config = get_knowledge_domain_router_config(temperature=temperature)
|
9 |
config.temperature = temperature
|
10 |
determiner = KnowledgeDomainRouter(api_key=api_key, config=config, question=question, display=print)
|
@@ -15,7 +17,6 @@ examples = [["""When is my grandmothers birthday?""", 0.6], ["What was my tax bu
|
|
15 |
|
16 |
def create_knowledge_router_ui(cache_examples=False):
|
17 |
with gr.Row():
|
18 |
-
api_key = gr.Textbox(label="You OpenAI API key", type="password")
|
19 |
question = gr.Textbox(label="Enter your question here:")
|
20 |
temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
|
21 |
with gr.Column():
|
@@ -23,6 +24,6 @@ def create_knowledge_router_ui(cache_examples=False):
|
|
23 |
reasoning = gr.Textbox(label="Reasoning")
|
24 |
|
25 |
generate_button = gr.Button(label="Generate")
|
26 |
-
generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature
|
27 |
-
gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature
|
28 |
|
|
|
1 |
from modules.knowledge_retrieval.knowledge_router import KnowledgeDomainRouter, get_knowledge_domain_router_config
|
2 |
+
from modules.settings.user_settings import UserSettings
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
+
|
6 |
|
7 |
def determine_and_execute(question: str, temperature: float, api_key = "" ):
|
8 |
+
settings = UserSettings.get_instance()
|
9 |
+
api_key = settings.get_api_key()
|
10 |
config = get_knowledge_domain_router_config(temperature=temperature)
|
11 |
config.temperature = temperature
|
12 |
determiner = KnowledgeDomainRouter(api_key=api_key, config=config, question=question, display=print)
|
|
|
17 |
|
18 |
def create_knowledge_router_ui(cache_examples=False):
|
19 |
with gr.Row():
|
|
|
20 |
question = gr.Textbox(label="Enter your question here:")
|
21 |
temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
|
22 |
with gr.Column():
|
|
|
24 |
reasoning = gr.Textbox(label="Reasoning")
|
25 |
|
26 |
generate_button = gr.Button(label="Generate")
|
27 |
+
generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature])
|
28 |
+
gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature], outputs=[reasoning_strategy, reasoning])
|
29 |
|
modules/reasoning/component.py
CHANGED
@@ -1,11 +1,13 @@
|
|
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 |
-
|
|
|
9 |
config = get_reasoning_router_config(temperature=temperature)
|
10 |
config.temperature = temperature
|
11 |
determiner = ReasoningRouter(api_key=api_key, config=config, question=question, display=print)
|
@@ -21,7 +23,7 @@ Where is the ball?""", 0.6], ["Given the task of building a house in the middle
|
|
21 |
|
22 |
def create_reasoning_router_ui(cache_examples=False):
|
23 |
with gr.Row():
|
24 |
-
|
25 |
question = gr.Textbox(label="Enter your question here:")
|
26 |
temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
|
27 |
with gr.Column():
|
@@ -29,6 +31,6 @@ def create_reasoning_router_ui(cache_examples=False):
|
|
29 |
reasoning = gr.Textbox(label="Reasoning")
|
30 |
|
31 |
generate_button = gr.Button(label="Generate")
|
32 |
-
generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature
|
33 |
-
gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature
|
34 |
|
|
|
1 |
from modules.reasoning.reasoning_router import ReasoningRouter, get_reasoning_router_config
|
2 |
+
from modules.settings.user_settings import UserSettings
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
6 |
|
7 |
|
8 |
+
def determine_and_execute(question, temperature):
|
9 |
+
settings = UserSettings.get_instance()
|
10 |
+
api_key = settings.get_api_key()
|
11 |
config = get_reasoning_router_config(temperature=temperature)
|
12 |
config.temperature = temperature
|
13 |
determiner = ReasoningRouter(api_key=api_key, config=config, question=question, display=print)
|
|
|
23 |
|
24 |
def create_reasoning_router_ui(cache_examples=False):
|
25 |
with gr.Row():
|
26 |
+
|
27 |
question = gr.Textbox(label="Enter your question here:")
|
28 |
temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
|
29 |
with gr.Column():
|
|
|
31 |
reasoning = gr.Textbox(label="Reasoning")
|
32 |
|
33 |
generate_button = gr.Button(label="Generate")
|
34 |
+
generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature])
|
35 |
+
gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature], outputs=[reasoning_strategy, reasoning])
|
36 |
|
modules/settings/__init__.py
ADDED
File without changes
|
modules/settings/component.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from modules.settings.user_settings import UserSettings
|
3 |
+
|
4 |
+
def set_api_key(key: str):
|
5 |
+
UserSettings.get_instance().set_api_key(key)
|
6 |
+
return "API key set"
|
7 |
+
|
8 |
+
|
9 |
+
def create_settings_ui():
|
10 |
+
settings = UserSettings.get_instance()
|
11 |
+
api_key = gr.Textbox(label="You OpenAI API key", type="password", default=settings.get_api_key())
|
12 |
+
set_status = gr.Text()
|
13 |
+
key_button = gr.Button(label="Set Key")
|
14 |
+
key_button.click(set_api_key, outputs=[set_status], inputs=[api_key])
|
modules/settings/user_settings.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
class UserSettings:
|
4 |
+
__instance = None
|
5 |
+
|
6 |
+
def __init__(self):
|
7 |
+
if UserSettings.__instance is not None:
|
8 |
+
raise Exception("UserSettings is a singleton class. Use UserSettings.get_instance() to get the instance.")
|
9 |
+
self.api_key = None
|
10 |
+
|
11 |
+
@staticmethod
|
12 |
+
def get_instance():
|
13 |
+
if UserSettings.__instance is None:
|
14 |
+
UserSettings.__instance = UserSettings()
|
15 |
+
return UserSettings.__instance
|
16 |
+
|
17 |
+
def set_api_key(self, api_key):
|
18 |
+
self.api_key = api_key
|
19 |
+
|
20 |
+
def get_api_key(self):
|
21 |
+
return self.api_key
|
server.py
CHANGED
@@ -1,14 +1,15 @@
|
|
|
|
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 |
from modules.knowledge_retrieval.component import create_knowledge_router_ui
|
|
|
|
|
6 |
load_dotenv(find_dotenv())
|
7 |
|
8 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
def create_interface():
|
13 |
title: str = "Prompt Strategy Demo"
|
14 |
description: str = "AI Agents Sandbox"
|
@@ -17,9 +18,19 @@ def create_interface():
|
|
17 |
create_reasoning_router_ui()
|
18 |
with gr.Tab("Knowledge Domains"):
|
19 |
create_knowledge_router_ui()
|
|
|
|
|
20 |
|
21 |
interface.queue()
|
22 |
-
interface.launch()
|
23 |
|
24 |
if __name__ == "__main__":
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
from dotenv import load_dotenv, find_dotenv
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
from modules.reasoning.component import create_reasoning_router_ui
|
6 |
from modules.knowledge_retrieval.component import create_knowledge_router_ui
|
7 |
+
from modules.settings.component import create_settings_ui
|
8 |
+
from modules.settings.user_settings import UserSettings
|
9 |
load_dotenv(find_dotenv())
|
10 |
|
11 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
12 |
|
|
|
|
|
13 |
def create_interface():
|
14 |
title: str = "Prompt Strategy Demo"
|
15 |
description: str = "AI Agents Sandbox"
|
|
|
18 |
create_reasoning_router_ui()
|
19 |
with gr.Tab("Knowledge Domains"):
|
20 |
create_knowledge_router_ui()
|
21 |
+
with gr.Tab("Settings"):
|
22 |
+
create_settings_ui()
|
23 |
|
24 |
interface.queue()
|
25 |
+
interface.launch(server_name="0.0.0.0", server_port=port)
|
26 |
|
27 |
if __name__ == "__main__":
|
28 |
+
parser = argparse.ArgumentParser()
|
29 |
+
parser.add_argument("--port", type=int, help="Port number to run the server on")
|
30 |
+
args = parser.parse_args()
|
31 |
+
|
32 |
+
port = args.port
|
33 |
+
settings = UserSettings().get_instance()
|
34 |
+
if openai_api_key:
|
35 |
+
settings.set_api_key(openai_api_key)
|
36 |
+
create_interface()
|