Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,9 @@ from Gradio_UI import GradioUI
|
|
| 12 |
# Define the Perplexity system prompt
|
| 13 |
Perplex_Assistant_Prompt = """You are a helpful AI assistant that searches the web for accurate information."""
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
#@weave.op()
|
| 16 |
def tracked_perplexity_call(prompt: str, system_messages: str, model_name: str = "sonar-pro", assistant_meta: bool = False):
|
| 17 |
"""Enhanced Perplexity API call with explicit model tracking."""
|
|
@@ -62,15 +65,12 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 62 |
|
| 63 |
final_answer = FinalAnswerTool()
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 67 |
-
|
| 68 |
model = HfApiModel(
|
| 69 |
max_tokens=2096,
|
| 70 |
temperature=0.5,
|
| 71 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud', # Using the backup endpoint
|
| 72 |
-
custom_role_conversions=None
|
| 73 |
-
huggingface_api_key=os.getenv("HUGGINGFACE_API_KEY") # Add this line to provide authentication
|
| 74 |
)
|
| 75 |
|
| 76 |
# Import tool from Hub
|
|
@@ -81,7 +81,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 81 |
|
| 82 |
agent = CodeAgent(
|
| 83 |
model=model,
|
| 84 |
-
tools=[final_answer, Sonar_Web_Search_Tool, get_current_time_in_timezone],
|
| 85 |
max_steps=6,
|
| 86 |
verbosity_level=1,
|
| 87 |
grammar=None,
|
|
@@ -91,6 +91,16 @@ agent = CodeAgent(
|
|
| 91 |
prompt_templates=prompt_templates
|
| 92 |
)
|
| 93 |
|
| 94 |
-
# To fix the TypeError
|
| 95 |
-
#
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Define the Perplexity system prompt
|
| 13 |
Perplex_Assistant_Prompt = """You are a helpful AI assistant that searches the web for accurate information."""
|
| 14 |
|
| 15 |
+
# Set up API key in environment variable as expected by HfApiModel
|
| 16 |
+
os.environ["HUGGINGFACE_API_TOKEN"] = os.getenv("HUGGINGFACE_API_KEY", "")
|
| 17 |
+
|
| 18 |
#@weave.op()
|
| 19 |
def tracked_perplexity_call(prompt: str, system_messages: str, model_name: str = "sonar-pro", assistant_meta: bool = False):
|
| 20 |
"""Enhanced Perplexity API call with explicit model tracking."""
|
|
|
|
| 65 |
|
| 66 |
final_answer = FinalAnswerTool()
|
| 67 |
|
| 68 |
+
# Remove the huggingface_api_key parameter - it's not supported
|
|
|
|
|
|
|
| 69 |
model = HfApiModel(
|
| 70 |
max_tokens=2096,
|
| 71 |
temperature=0.5,
|
| 72 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud', # Using the backup endpoint
|
| 73 |
+
custom_role_conversions=None
|
|
|
|
| 74 |
)
|
| 75 |
|
| 76 |
# Import tool from Hub
|
|
|
|
| 81 |
|
| 82 |
agent = CodeAgent(
|
| 83 |
model=model,
|
| 84 |
+
tools=[final_answer, Sonar_Web_Search_Tool, get_current_time_in_timezone, image_generation_tool], # Added the image tool
|
| 85 |
max_steps=6,
|
| 86 |
verbosity_level=1,
|
| 87 |
grammar=None,
|
|
|
|
| 91 |
prompt_templates=prompt_templates
|
| 92 |
)
|
| 93 |
|
| 94 |
+
# To fix the TypeError in Gradio_UI.py, you would need to modify that file
|
| 95 |
+
# For now, we'll just use the agent directly
|
| 96 |
+
try:
|
| 97 |
+
GradioUI(agent).launch()
|
| 98 |
+
except TypeError as e:
|
| 99 |
+
if "unsupported operand type(s) for +=" in str(e):
|
| 100 |
+
print("Error: Token counting issue in Gradio UI")
|
| 101 |
+
print("To fix, edit Gradio_UI.py and change:")
|
| 102 |
+
print("total_input_tokens += agent.model.last_input_token_count")
|
| 103 |
+
print("To:")
|
| 104 |
+
print("total_input_tokens += (agent.model.last_input_token_count or 0)")
|
| 105 |
+
else:
|
| 106 |
+
raise e
|