@@ -36,8 +36,9 @@ def load_config():
36
36
hf_token = load_config ()
37
37
openai_key = os .getenv ("OPENAI_API_KEY" )
38
38
39
- local_agent = LocalRAGAgent (vector_store ) if hf_token else None
40
- openai_agent = RAGAgent (vector_store , openai_api_key = openai_key ) if openai_key else None
39
+ # Initialize agents with use_cot=True to ensure CoT is available
40
+ local_agent = LocalRAGAgent (vector_store , use_cot = True ) if hf_token else None
41
+ openai_agent = RAGAgent (vector_store , openai_api_key = openai_key , use_cot = True ) if openai_key else None
41
42
42
43
def process_pdf (file : tempfile ._TemporaryFileWrapper ) -> str :
43
44
"""Process uploaded PDF file"""
@@ -84,18 +85,22 @@ def chat(message: str, history: List[List[str]], agent_type: str, use_cot: bool,
84
85
print (f"Agent: { agent_type } , CoT: { use_cot } , Language: { language } , Collection: { collection } " )
85
86
print ("=" * 50 + "\n " )
86
87
87
- # Select appropriate agent
88
- agent = local_agent if agent_type == "Local (Mistral)" else openai_agent
89
- if not agent :
90
- response_text = "Agent not available. Please check your configuration."
91
- print (f"Error: { response_text } " )
92
- return history + [[message , response_text ]]
88
+ # Select appropriate agent and reinitialize with correct settings
89
+ if agent_type == "Local (Mistral)" :
90
+ if not hf_token :
91
+ response_text = "Local agent not available. Please check your HuggingFace token configuration."
92
+ print (f"Error: { response_text } " )
93
+ return history + [[message , response_text ]]
94
+ agent = LocalRAGAgent (vector_store , use_cot = use_cot )
95
+ else :
96
+ if not openai_key :
97
+ response_text = "OpenAI agent not available. Please check your OpenAI API key configuration."
98
+ print (f"Error: { response_text } " )
99
+ return history + [[message , response_text ]]
100
+ agent = RAGAgent (vector_store , openai_api_key = openai_key , use_cot = use_cot )
93
101
94
102
# Convert language selection to language code
95
103
lang_code = "es" if language == "Spanish" else "en"
96
-
97
- # Set CoT option and language
98
- agent .use_cot = use_cot
99
104
agent .language = lang_code
100
105
101
106
# Process query and get response
0 commit comments