zamalali
commited on
Commit
·
ae2c609
1
Parent(s):
7c74f8f
Updated background agents latency checks
Browse files
agent.py
CHANGED
|
@@ -8,7 +8,6 @@ from github import Github, Auth
|
|
| 8 |
from langchain_groq import ChatGroq
|
| 9 |
from langchain_core.tools import tool
|
| 10 |
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
| 11 |
-
from langchain import hub
|
| 12 |
|
| 13 |
# Load environment variables
|
| 14 |
load_dotenv()
|
|
|
|
| 8 |
from langchain_groq import ChatGroq
|
| 9 |
from langchain_core.tools import tool
|
| 10 |
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
|
|
|
| 11 |
|
| 12 |
# Load environment variables
|
| 13 |
load_dotenv()
|
app.py
CHANGED
|
@@ -3,8 +3,8 @@ import time
|
|
| 3 |
import threading
|
| 4 |
import logging
|
| 5 |
from gradio.themes.utils import sizes
|
| 6 |
-
from main import run_repository_ranking
|
| 7 |
-
import agent
|
| 8 |
|
| 9 |
# ---------------------------
|
| 10 |
# Global Logging Buffer Setup
|
|
@@ -218,14 +218,10 @@ with gr.Blocks(
|
|
| 218 |
def chat_with_agent(user_msg, repo, history):
|
| 219 |
logging.info("[Chat] User sent message: '%s' for repo: '%s'", user_msg, repo)
|
| 220 |
if not user_msg or not user_msg.strip():
|
| 221 |
-
|
| 222 |
-
return
|
| 223 |
if not repo:
|
| 224 |
-
|
| 225 |
-
return
|
| 226 |
-
# Show user message immediately with a loading placeholder
|
| 227 |
-
new_history = history + [[user_msg, "⏳ Loading..."]]
|
| 228 |
-
yield new_history, new_history
|
| 229 |
full_query = f"[{repo}] {user_msg}"
|
| 230 |
try:
|
| 231 |
result = agent.agent_executor.invoke({"input": full_query})
|
|
@@ -234,9 +230,8 @@ with gr.Blocks(
|
|
| 234 |
except Exception as e:
|
| 235 |
answer = f"Error: {e}"
|
| 236 |
logging.error("[Chat] Error in agent_executor: %s", e)
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
yield new_history, new_history
|
| 240 |
|
| 241 |
# Disable send button if no repo is selected or message is blank, and show a helpful message
|
| 242 |
def can_send(user_msg, repo):
|
|
|
|
| 3 |
import threading
|
| 4 |
import logging
|
| 5 |
from gradio.themes.utils import sizes
|
| 6 |
+
from main import run_repository_ranking
|
| 7 |
+
import agent
|
| 8 |
|
| 9 |
# ---------------------------
|
| 10 |
# Global Logging Buffer Setup
|
|
|
|
| 218 |
def chat_with_agent(user_msg, repo, history):
|
| 219 |
logging.info("[Chat] User sent message: '%s' for repo: '%s'", user_msg, repo)
|
| 220 |
if not user_msg or not user_msg.strip():
|
| 221 |
+
# Block blank messages
|
| 222 |
+
return history + [["", "Please enter a message before sending."]], history
|
| 223 |
if not repo:
|
| 224 |
+
return history + [[user_msg, "Please select a repository first."]], history
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
full_query = f"[{repo}] {user_msg}"
|
| 226 |
try:
|
| 227 |
result = agent.agent_executor.invoke({"input": full_query})
|
|
|
|
| 230 |
except Exception as e:
|
| 231 |
answer = f"Error: {e}"
|
| 232 |
logging.error("[Chat] Error in agent_executor: %s", e)
|
| 233 |
+
history = history + [[user_msg, answer]]
|
| 234 |
+
return history, history
|
|
|
|
| 235 |
|
| 236 |
# Disable send button if no repo is selected or message is blank, and show a helpful message
|
| 237 |
def can_send(user_msg, repo):
|