Bhanu-Chander-ABB commited on
Commit
ae4a304
·
1 Parent(s): 47d092c
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -8,6 +8,7 @@ from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
8
  from langchain.agents import initialize_agent, AgentType
9
  from bs4 import BeautifulSoup
10
  import base64
 
11
 
12
  ## # Load environment variables from .env file
13
  # --- Constants ---
@@ -16,7 +17,8 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
  # Load the environment variables
17
  HF_ACCESS_KEY = os.getenv('HF_ACCESS_KEY')
18
  WEATHER_API_KEY = os.getenv('WEATHER_API_KEY')
19
-
 
20
 
21
  ########## ----- DEFINING TOOLS -----##########
22
 
@@ -329,7 +331,7 @@ Instructions:
329
 
330
  ## --- Initialize Hugging Face Model ---
331
  # Generate the chat interface, including the tools
332
-
333
  llm = HuggingFaceEndpoint(
334
  repo_id="meta-llama/Llama-3.3-70B-Instruct",
335
  # repo_id="Qwen/Qwen2.5-32B-Instruct",
@@ -339,12 +341,12 @@ llm = HuggingFaceEndpoint(
339
  )
340
  chat_llm = ChatHuggingFace(llm=llm)
341
  '''
342
- llm = ChatOpenAI(
343
  openai_api_key=OPENAI_KEY,
344
  model_name=OPENAI_MODEL,
345
  temperature=0.1
346
  )
347
- '''
348
  # chat = ChatHuggingFace(llm=llm, verbose=True)
349
  # tools = [search_tool, fetch_weather]
350
  # chat_with_tools = chat.bind_tools(tools)
@@ -354,7 +356,7 @@ agent = initialize_agent(
354
  # llm=llm,
355
  llm=chat_llm,
356
  agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
357
- # agent_kwargs={"system_message": system_prompt},
358
  verbose=True,
359
  handle_parsing_errors=True
360
  )
@@ -424,9 +426,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
424
  print(f"Skipping item with missing task_id or question: {item}")
425
  continue
426
  try:
427
- full_prompt = f"{system_prompt}\n Input Question: {question_text}"
428
- submitted_answer = agent.run(full_prompt)
429
- # submitted_answer = agent.run(question_text)
430
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
431
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
432
  except Exception as e:
 
8
  from langchain.agents import initialize_agent, AgentType
9
  from bs4 import BeautifulSoup
10
  import base64
11
+ from langchain_openai import ChatOpenAI
12
 
13
  ## # Load environment variables from .env file
14
  # --- Constants ---
 
17
  # Load the environment variables
18
  HF_ACCESS_KEY = os.getenv('HF_ACCESS_KEY')
19
  WEATHER_API_KEY = os.getenv('WEATHER_API_KEY')
20
+ OPENAI_KEY = os.getenv('OPENAI_KEY')
21
+ OPENAI_MODEL = os.getenv ('OPENAI_MODEL')
22
 
23
  ########## ----- DEFINING TOOLS -----##########
24
 
 
331
 
332
  ## --- Initialize Hugging Face Model ---
333
  # Generate the chat interface, including the tools
334
+ '''
335
  llm = HuggingFaceEndpoint(
336
  repo_id="meta-llama/Llama-3.3-70B-Instruct",
337
  # repo_id="Qwen/Qwen2.5-32B-Instruct",
 
341
  )
342
  chat_llm = ChatHuggingFace(llm=llm)
343
  '''
344
+ chat_llm = ChatOpenAI(
345
  openai_api_key=OPENAI_KEY,
346
  model_name=OPENAI_MODEL,
347
  temperature=0.1
348
  )
349
+
350
  # chat = ChatHuggingFace(llm=llm, verbose=True)
351
  # tools = [search_tool, fetch_weather]
352
  # chat_with_tools = chat.bind_tools(tools)
 
356
  # llm=llm,
357
  llm=chat_llm,
358
  agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
359
+ agent_kwargs={"system_message": system_prompt},
360
  verbose=True,
361
  handle_parsing_errors=True
362
  )
 
426
  print(f"Skipping item with missing task_id or question: {item}")
427
  continue
428
  try:
429
+ # full_prompt = f"{system_prompt}\n Input Question: {question_text}"
430
+ # submitted_answer = agent.run(full_prompt)
431
+ submitted_answer = agent.run(question_text)
432
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
433
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
434
  except Exception as e: