Umer797 commited on
Commit
0d53058
·
verified ·
1 Parent(s): 945355d

Update llm_node.py

Browse files
Files changed (1) hide show
  1. llm_node.py +27 -10
llm_node.py CHANGED
@@ -1,11 +1,28 @@
 
 
 
1
  def llm_node(question, search_result):
2
- # Check if search_result is a list of dicts
3
- if isinstance(search_result, list):
4
- combined_result = " ".join(
5
- item.get("content", "") for item in search_result if isinstance(item, dict)
6
- )
7
- else:
8
- combined_result = str(search_result)
9
-
10
- combined_answer = combined_result.strip()
11
- return combined_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain_community.chat_models import ChatOpenAI
3
+
4
  def llm_node(question, search_result):
5
+ # Initialize GPT-4
6
+ llm = ChatOpenAI(
7
+ model="gpt-4",
8
+ temperature=0,
9
+ openai_api_key=os.getenv("OPENAI_API_KEY")
10
+ )
11
+
12
+ prompt = f"""You are solving a GAIA benchmark evaluation question.
13
+
14
+ Here’s the question:
15
+ {question}
16
+
17
+ Here’s retrieved information:
18
+ {search_result}
19
+
20
+ ⚠️ VERY IMPORTANT:
21
+ - ONLY return the final answer, exactly as required.
22
+ - Do NOT include explanations, prefixes, or notes.
23
+ - If the question asks for a list, give only the list, in the requested format.
24
+
25
+ Your answer:"""
26
+
27
+ response = llm.invoke(prompt)
28
+ return response.content.strip()