Spaces:
Paused
Paused
jpfearnworks
commited on
Commit
·
2fbdd0c
1
Parent(s):
26d2488
Resolve issue with key logic
Browse files- Dockerfile +1 -1
- modules/knowledge_retrieval/base/router_chain.py +2 -1
- modules/knowledge_retrieval/component.py +3 -3
- modules/knowledge_retrieval/destination_chain.py +8 -2
- modules/knowledge_retrieval/knowledge_router.py +8 -4
- modules/reasoning/component.py +0 -2
- modules/settings/component.py +2 -1
- modules/settings/user_settings.py +1 -0
- server.py +1 -1
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 --port 7000
|
modules/knowledge_retrieval/base/router_chain.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from modules.base.chain import IChain
|
|
|
2 |
from typing import Dict , Any, Callable
|
3 |
import os
|
4 |
|
@@ -22,7 +23,7 @@ class RouterChain(IChain):
|
|
22 |
question: str
|
23 |
usage: str
|
24 |
llm: Any
|
25 |
-
api_key: str
|
26 |
|
27 |
def add_chain(self, domain: str, chain: IChain) -> None:
|
28 |
self.destination_chains[domain] = chain
|
|
|
1 |
from modules.base.chain import IChain
|
2 |
+
from modules.settings.user_settings import UserSettings
|
3 |
from typing import Dict , Any, Callable
|
4 |
import os
|
5 |
|
|
|
23 |
question: str
|
24 |
usage: str
|
25 |
llm: Any
|
26 |
+
api_key: str
|
27 |
|
28 |
def add_chain(self, domain: str, chain: IChain) -> None:
|
29 |
self.destination_chains[domain] = chain
|
modules/knowledge_retrieval/component.py
CHANGED
@@ -4,12 +4,12 @@ import gradio as gr
|
|
4 |
import os
|
5 |
|
6 |
|
7 |
-
def determine_and_execute(question: str, temperature: float
|
8 |
settings = UserSettings.get_instance()
|
9 |
-
|
10 |
config = get_knowledge_domain_router_config(temperature=temperature)
|
11 |
config.temperature = temperature
|
12 |
-
determiner = KnowledgeDomainRouter(
|
13 |
determine_output, execute_output = determiner.determine_and_execute(question=question)
|
14 |
return determine_output, execute_output
|
15 |
|
|
|
4 |
import os
|
5 |
|
6 |
|
7 |
+
def determine_and_execute(question: str, temperature: float):
|
8 |
settings = UserSettings.get_instance()
|
9 |
+
|
10 |
config = get_knowledge_domain_router_config(temperature=temperature)
|
11 |
config.temperature = temperature
|
12 |
+
determiner = KnowledgeDomainRouter(config=config, question=question, display=print)
|
13 |
determine_output, execute_output = determiner.determine_and_execute(question=question)
|
14 |
return determine_output, execute_output
|
15 |
|
modules/knowledge_retrieval/destination_chain.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from modules.base.chain import IChain
|
2 |
from modules.base.llm_chain_config import LLMChainConfig
|
3 |
from modules.knowledge_retrieval.base.knowledge_domain import KnowledgeDomain
|
|
|
4 |
from typing import Dict , Any, Callable
|
5 |
import os
|
6 |
|
@@ -21,7 +22,7 @@ class DestinationChain(IChain):
|
|
21 |
DestinationChain class will return a response generated by the KnowledgeDomain.
|
22 |
"""
|
23 |
knowledge_domain: KnowledgeDomain
|
24 |
-
api_key: str
|
25 |
llm: Any
|
26 |
display: Callable
|
27 |
usage: str
|
@@ -33,7 +34,12 @@ class DestinationChainStrategy(DestinationChain):
|
|
33 |
"""Base class for Chain Strategies"""
|
34 |
|
35 |
def __init__(self, config: LLMChainConfig, display: Callable, knowledge_domain: KnowledgeDomain, usage: str):
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens)
|
38 |
|
39 |
self.usage = config.usage
|
|
|
1 |
from modules.base.chain import IChain
|
2 |
from modules.base.llm_chain_config import LLMChainConfig
|
3 |
from modules.knowledge_retrieval.base.knowledge_domain import KnowledgeDomain
|
4 |
+
from modules.settings.user_settings import UserSettings
|
5 |
from typing import Dict , Any, Callable
|
6 |
import os
|
7 |
|
|
|
22 |
DestinationChain class will return a response generated by the KnowledgeDomain.
|
23 |
"""
|
24 |
knowledge_domain: KnowledgeDomain
|
25 |
+
api_key: str
|
26 |
llm: Any
|
27 |
display: Callable
|
28 |
usage: str
|
|
|
34 |
"""Base class for Chain Strategies"""
|
35 |
|
36 |
def __init__(self, config: LLMChainConfig, display: Callable, knowledge_domain: KnowledgeDomain, usage: str):
|
37 |
+
settings = UserSettings.get_instance()
|
38 |
+
api_key = settings.get_api_key()
|
39 |
+
print("Api key")
|
40 |
+
print(api_key)
|
41 |
+
super().__init__(api_key=api_key, knowledge_domain=knowledge_domain, llm=config.llm_class, display=display, usage=usage)
|
42 |
+
|
43 |
self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens)
|
44 |
|
45 |
self.usage = config.usage
|
modules/knowledge_retrieval/knowledge_router.py
CHANGED
@@ -9,11 +9,14 @@ from modules.knowledge_retrieval.destination_chain import DestinationChainStrate
|
|
9 |
from langchain import PromptTemplate, LLMChain
|
10 |
|
11 |
import pprint
|
|
|
12 |
from typing import Callable, Dict, Optional, Tuple
|
13 |
import re
|
14 |
|
15 |
class KnowledgeDomainRouter(RouterChain):
|
16 |
-
def __init__(self,
|
|
|
|
|
17 |
chains : Dict[int, DestinationChainStrategy] = {
|
18 |
1: BusinessChain(config=get_business_chain_config(), display=display),
|
19 |
2: FamilyChain(config=get_family_chain_config(), display=display),
|
@@ -36,11 +39,12 @@ class KnowledgeDomainRouter(RouterChain):
|
|
36 |
|
37 |
The number and name of the selected strategy is...
|
38 |
"""
|
39 |
-
|
40 |
-
super().__init__(
|
|
|
41 |
print("Creating Knowledge Domain Router with config: ")
|
42 |
# pprint.pprint(config)
|
43 |
-
self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens, api_key=api_key)
|
44 |
self.question: str = question
|
45 |
|
46 |
def run(self, question: str) -> str:
|
|
|
9 |
from langchain import PromptTemplate, LLMChain
|
10 |
|
11 |
import pprint
|
12 |
+
from modules.settings.user_settings import UserSettings
|
13 |
from typing import Callable, Dict, Optional, Tuple
|
14 |
import re
|
15 |
|
16 |
class KnowledgeDomainRouter(RouterChain):
|
17 |
+
def __init__(self, config: LLMChainConfig, question: str, display: Callable):
|
18 |
+
settings = UserSettings.get_instance()
|
19 |
+
|
20 |
chains : Dict[int, DestinationChainStrategy] = {
|
21 |
1: BusinessChain(config=get_business_chain_config(), display=display),
|
22 |
2: FamilyChain(config=get_family_chain_config(), display=display),
|
|
|
39 |
|
40 |
The number and name of the selected strategy is...
|
41 |
"""
|
42 |
+
api_key = settings.get_api_key()
|
43 |
+
super().__init__(api_key=api_key, template = template, destination_chains=chains, usage=config.usage, llm=config.llm_class, question=question)
|
44 |
+
self.api_key = settings.get_api_key()
|
45 |
print("Creating Knowledge Domain Router with config: ")
|
46 |
# pprint.pprint(config)
|
47 |
+
self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens, api_key=self.api_key)
|
48 |
self.question: str = question
|
49 |
|
50 |
def run(self, question: str) -> str:
|
modules/reasoning/component.py
CHANGED
@@ -1,8 +1,6 @@
|
|
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):
|
|
|
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 |
|
5 |
|
6 |
def determine_and_execute(question, temperature):
|
modules/settings/component.py
CHANGED
@@ -8,7 +8,8 @@ def set_api_key(key: str):
|
|
8 |
|
9 |
def create_settings_ui():
|
10 |
settings = UserSettings.get_instance()
|
11 |
-
|
|
|
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])
|
|
|
8 |
|
9 |
def create_settings_ui():
|
10 |
settings = UserSettings.get_instance()
|
11 |
+
api_key_default = settings.get_api_key()
|
12 |
+
api_key = gr.Textbox(label="You OpenAI API key", type="password")
|
13 |
set_status = gr.Text()
|
14 |
key_button = gr.Button(label="Set Key")
|
15 |
key_button.click(set_api_key, outputs=[set_status], inputs=[api_key])
|
modules/settings/user_settings.py
CHANGED
@@ -16,6 +16,7 @@ class UserSettings:
|
|
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
|
|
|
16 |
|
17 |
def set_api_key(self, api_key):
|
18 |
self.api_key = api_key
|
19 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
20 |
|
21 |
def get_api_key(self):
|
22 |
return self.api_key
|
server.py
CHANGED
@@ -30,7 +30,7 @@ if __name__ == "__main__":
|
|
30 |
args = parser.parse_args()
|
31 |
|
32 |
port = args.port
|
33 |
-
settings = UserSettings
|
34 |
if openai_api_key:
|
35 |
settings.set_api_key(openai_api_key)
|
36 |
create_interface()
|
|
|
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()
|