Spaces:
Building
Building
Update chat_handler.py
Browse files- chat_handler.py +7 -21
chat_handler.py
CHANGED
@@ -19,19 +19,7 @@ from session import session_store, Session
|
|
19 |
from llm_interface import LLMInterface, SparkLLM, GPT4oLLM
|
20 |
from config_provider import ConfigProvider
|
21 |
|
22 |
-
# βββββββββββββββββββββββββ
|
23 |
-
# Global config reference
|
24 |
-
cfg = None
|
25 |
-
|
26 |
-
def get_config():
|
27 |
-
"""Always get fresh config"""
|
28 |
-
global cfg
|
29 |
-
cfg = ConfigProvider.get()
|
30 |
-
return cfg
|
31 |
-
|
32 |
-
# Initialize on module load
|
33 |
-
cfg = get_config()
|
34 |
-
|
35 |
# Global LLM instance
|
36 |
llm_provider: Optional[LLMInterface] = None
|
37 |
|
@@ -69,11 +57,7 @@ def initialize_llm(force_reload=False):
|
|
69 |
"""Initialize LLM provider based on work_mode"""
|
70 |
global llm_provider
|
71 |
|
72 |
-
|
73 |
-
if force_reload:
|
74 |
-
cfg = reload_config()
|
75 |
-
else:
|
76 |
-
cfg = get_config()
|
77 |
|
78 |
work_mode = cfg.global_config.work_mode
|
79 |
|
@@ -99,7 +83,8 @@ def initialize_llm(force_reload=False):
|
|
99 |
# βββββββββββββββββββββββββ SPARK βββββββββββββββββββββββββ #
|
100 |
def _get_spark_token() -> Optional[str]:
|
101 |
"""Get Spark token based on work_mode"""
|
102 |
-
cfg =
|
|
|
103 |
work_mode = cfg.global_config.work_mode
|
104 |
|
105 |
if cfg.global_config.is_cloud_mode():
|
@@ -158,7 +143,7 @@ class ChatResponse(BaseModel):
|
|
158 |
async def start_session(req: StartRequest):
|
159 |
"""Create new session"""
|
160 |
try:
|
161 |
-
cfg =
|
162 |
|
163 |
# Validate project exists
|
164 |
project = next((p for p in cfg.projects if p.name == req.project_name and p.enabled), None)
|
@@ -429,6 +414,7 @@ async def _generate_smart_parameter_question(
|
|
429 |
version
|
430 |
) -> str:
|
431 |
"""LLM kullanarak doΔal parametre sorusu ΓΌret"""
|
|
|
432 |
|
433 |
# Config'i al
|
434 |
collection_config = cfg.global_config.parameter_collection_config
|
@@ -659,7 +645,7 @@ async def _execute_api_call(session: Session, intent_config) -> str:
|
|
659 |
session.state = "call_api"
|
660 |
api_name = intent_config.action
|
661 |
|
662 |
-
cfg =
|
663 |
|
664 |
api_config = cfg.get_api(api_name)
|
665 |
|
|
|
19 |
from llm_interface import LLMInterface, SparkLLM, GPT4oLLM
|
20 |
from config_provider import ConfigProvider
|
21 |
|
22 |
+
# βββββββββββββββββββββββββ GLOBAL βββββββββββββββββββββββββ #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Global LLM instance
|
24 |
llm_provider: Optional[LLMInterface] = None
|
25 |
|
|
|
57 |
"""Initialize LLM provider based on work_mode"""
|
58 |
global llm_provider
|
59 |
|
60 |
+
cfg = ConfigProvider.get()
|
|
|
|
|
|
|
|
|
61 |
|
62 |
work_mode = cfg.global_config.work_mode
|
63 |
|
|
|
83 |
# βββββββββββββββββββββββββ SPARK βββββββββββββββββββββββββ #
|
84 |
def _get_spark_token() -> Optional[str]:
|
85 |
"""Get Spark token based on work_mode"""
|
86 |
+
cfg = ConfigProvider.get()
|
87 |
+
|
88 |
work_mode = cfg.global_config.work_mode
|
89 |
|
90 |
if cfg.global_config.is_cloud_mode():
|
|
|
143 |
async def start_session(req: StartRequest):
|
144 |
"""Create new session"""
|
145 |
try:
|
146 |
+
cfg = ConfigProvider.get()
|
147 |
|
148 |
# Validate project exists
|
149 |
project = next((p for p in cfg.projects if p.name == req.project_name and p.enabled), None)
|
|
|
414 |
version
|
415 |
) -> str:
|
416 |
"""LLM kullanarak doΔal parametre sorusu ΓΌret"""
|
417 |
+
cfg = ConfigProvider.get()
|
418 |
|
419 |
# Config'i al
|
420 |
collection_config = cfg.global_config.parameter_collection_config
|
|
|
645 |
session.state = "call_api"
|
646 |
api_name = intent_config.action
|
647 |
|
648 |
+
cfg = ConfigProvider.get()
|
649 |
|
650 |
api_config = cfg.get_api(api_name)
|
651 |
|