guoquan-net commited on
Commit
0635e79
·
verified ·
1 Parent(s): d1f8299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -3,8 +3,10 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
6
  from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
 
8
 
9
  # Define a custom tool (this is just a placeholder; feel free to modify it)
10
  def my_custom_tool(arg1: str, arg2: int) -> str:
@@ -46,6 +48,21 @@ model = HfApiModel(
46
  with open("prompts.yaml", 'r') as stream:
47
  prompt_templates = yaml.safe_load(stream)
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  # Creating the CodeAgent with tools and model setup
50
  agent = CodeAgent(
51
  model=model,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import time
7
  from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
+ from huggingface_hub import InferenceClient
10
 
11
  # Define a custom tool (this is just a placeholder; feel free to modify it)
12
  def my_custom_tool(arg1: str, arg2: int) -> str:
 
48
  with open("prompts.yaml", 'r') as stream:
49
  prompt_templates = yaml.safe_load(stream)
50
 
51
+ # Function to handle model timeout and retries
52
+ def get_model_response_with_retry(model_input, max_retries=3):
53
+ retries = 0
54
+ while retries < max_retries:
55
+ try:
56
+ client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
57
+ response = client.text_generation(model_input)
58
+ return response
59
+ except Exception as e:
60
+ retries += 1
61
+ print(f"Retry {retries} due to error: {e}")
62
+ if retries == max_retries:
63
+ return "Model is busy. Please try again later."
64
+ time.sleep(2) # Wait before retrying
65
+
66
  # Creating the CodeAgent with tools and model setup
67
  agent = CodeAgent(
68
  model=model,