Dave67350 commited on
Commit
bc1e1ea
·
verified ·
1 Parent(s): 7a985be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -18,18 +18,19 @@ class AIRegulationModel:
18
  )
19
 
20
  def get_regulation_info(self, query: str) -> str:
21
- """Generates a response based on an AI regulation query.
22
-
 
23
  Args:
24
  query (str): The input question related to AI regulations.
25
 
26
  Returns:
27
- str: A relevant response from the AI regulation model.
28
  """
29
  response = self.model.generate(prompt=query) # Ensure correct API call
30
  if isinstance(response, dict) and "generated_text" in response:
31
  return response["generated_text"]
32
- return "No response generated."
33
 
34
  # Initialize AI Regulation Tool
35
  ai_regulation_tool = AIRegulationModel()
@@ -40,24 +41,23 @@ def ai_regulation_query_tool(query: str) -> str:
40
  Queries an AI model for information on AI regulation.
41
 
42
  Args:
43
- query (str): A question or topic related to AI regulations.
44
 
45
  Returns:
46
  str: The response from the AI model regarding AI regulations.
47
  """
48
  return ai_regulation_tool.get_regulation_info(query)
49
 
50
-
51
-
52
  @tool
53
  def get_current_time_in_timezone(timezone: str) -> str:
54
- """Fetches the current local time in a specified timezone.
 
55
 
56
  Args:
57
  timezone (str): A string representing a valid timezone (e.g., 'America/New_York').
58
 
59
  Returns:
60
- str: The current time in the given timezone.
61
  """
62
  try:
63
  tz = pytz.timezone(timezone)
@@ -73,7 +73,7 @@ final_answer = FinalAnswerTool()
73
  model = HfApiModel(
74
  max_tokens=2096,
75
  temperature=0.5,
76
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
77
  custom_role_conversions=None
78
  )
79
 
@@ -85,8 +85,12 @@ except Exception as e:
85
  image_generation_tool = None # Prevent crash if tool fails
86
 
87
  # Load system prompt from YAML file
88
- with open("prompts.yaml", 'r') as stream:
89
- prompt_templates = yaml.safe_load(stream)
 
 
 
 
90
 
91
  # Create Agent
92
  agent = CodeAgent(
 
18
  )
19
 
20
  def get_regulation_info(self, query: str) -> str:
21
+ """
22
+ Generates a response based on an AI regulation query.
23
+
24
  Args:
25
  query (str): The input question related to AI regulations.
26
 
27
  Returns:
28
+ str: The response from the AI regulation model, or an error message if generation fails.
29
  """
30
  response = self.model.generate(prompt=query) # Ensure correct API call
31
  if isinstance(response, dict) and "generated_text" in response:
32
  return response["generated_text"]
33
+ return "No response generated. Please try again."
34
 
35
  # Initialize AI Regulation Tool
36
  ai_regulation_tool = AIRegulationModel()
 
41
  Queries an AI model for information on AI regulation.
42
 
43
  Args:
44
+ query (str): The user's question related to AI regulations.
45
 
46
  Returns:
47
  str: The response from the AI model regarding AI regulations.
48
  """
49
  return ai_regulation_tool.get_regulation_info(query)
50
 
 
 
51
  @tool
52
  def get_current_time_in_timezone(timezone: str) -> str:
53
+ """
54
+ Fetches the current local time in a specified timezone.
55
 
56
  Args:
57
  timezone (str): A string representing a valid timezone (e.g., 'America/New_York').
58
 
59
  Returns:
60
+ str: The current time in the given timezone or an error message if the timezone is invalid.
61
  """
62
  try:
63
  tz = pytz.timezone(timezone)
 
73
  model = HfApiModel(
74
  max_tokens=2096,
75
  temperature=0.5,
76
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
77
  custom_role_conversions=None
78
  )
79
 
 
85
  image_generation_tool = None # Prevent crash if tool fails
86
 
87
  # Load system prompt from YAML file
88
+ try:
89
+ with open("prompts.yaml", "r") as stream:
90
+ prompt_templates = yaml.safe_load(stream)
91
+ except FileNotFoundError:
92
+ print("Warning: prompts.yaml file not found. Using default templates.")
93
+ prompt_templates = {}
94
 
95
  # Create Agent
96
  agent = CodeAgent(