Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,12 +87,8 @@ async def startup_event():
|
|
| 87 |
global agent
|
| 88 |
try:
|
| 89 |
logger.info("Initializing TxAgent...")
|
| 90 |
-
# Get Hugging Face token from environment variable
|
| 91 |
-
hf_token = os.getenv("HUGGINGFACE_TOKEN")
|
| 92 |
-
model_kwargs = {"token": hf_token} if hf_token else {}
|
| 93 |
-
|
| 94 |
agent = TxAgent(
|
| 95 |
-
model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
|
| 96 |
rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",
|
| 97 |
tool_files_dict={},
|
| 98 |
enable_finish=True,
|
|
@@ -100,23 +96,17 @@ async def startup_event():
|
|
| 100 |
force_finish=True,
|
| 101 |
enable_checker=True,
|
| 102 |
step_rag_num=4,
|
| 103 |
-
seed=100
|
| 104 |
-
**model_kwargs
|
| 105 |
)
|
| 106 |
agent.init_model()
|
| 107 |
logger.info("TxAgent initialized successfully")
|
| 108 |
except Exception as e:
|
| 109 |
logger.error(f"Failed to initialize agent: {str(e)}")
|
| 110 |
-
|
| 111 |
-
agent = None
|
| 112 |
|
| 113 |
@app.post("/chat")
|
| 114 |
async def chat_endpoint(request: ChatRequest):
|
| 115 |
"""Handle chat conversations with formatting options"""
|
| 116 |
-
if agent is None:
|
| 117 |
-
logger.error("TxAgent not initialized")
|
| 118 |
-
raise HTTPException(status_code=503, detail="TxAgent service unavailable")
|
| 119 |
-
|
| 120 |
try:
|
| 121 |
logger.info(f"Chat request received (format: {request.format})")
|
| 122 |
raw_response = agent.chat(
|
|
@@ -146,10 +136,6 @@ async def chat_endpoint(request: ChatRequest):
|
|
| 146 |
@app.post("/upload")
|
| 147 |
async def upload_file(file: UploadFile = File(...)):
|
| 148 |
"""Handle file uploads and process with TxAgent"""
|
| 149 |
-
if agent is None:
|
| 150 |
-
logger.error("TxAgent not initialized")
|
| 151 |
-
raise HTTPException(status_code=503, detail="TxAgent service unavailable")
|
| 152 |
-
|
| 153 |
try:
|
| 154 |
logger.info(f"File upload received: {file.filename}")
|
| 155 |
content = ""
|
|
@@ -192,7 +178,7 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 192 |
async def service_status():
|
| 193 |
"""Check service status"""
|
| 194 |
return {
|
| 195 |
-
"status": "running"
|
| 196 |
"version": "2.0.0",
|
| 197 |
"model": agent.model_name if agent else "not loaded",
|
| 198 |
"formats_available": ["raw", "clean", "structured", "html"],
|
|
|
|
| 87 |
global agent
|
| 88 |
try:
|
| 89 |
logger.info("Initializing TxAgent...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
agent = TxAgent(
|
| 91 |
+
model_name="mims-harvard/TxAgent-T1-Llama-3.1-8B",
|
| 92 |
rag_model_name="mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B",
|
| 93 |
tool_files_dict={},
|
| 94 |
enable_finish=True,
|
|
|
|
| 96 |
force_finish=True,
|
| 97 |
enable_checker=True,
|
| 98 |
step_rag_num=4,
|
| 99 |
+
seed=100
|
|
|
|
| 100 |
)
|
| 101 |
agent.init_model()
|
| 102 |
logger.info("TxAgent initialized successfully")
|
| 103 |
except Exception as e:
|
| 104 |
logger.error(f"Failed to initialize agent: {str(e)}")
|
| 105 |
+
raise RuntimeError(f"Failed to initialize agent: {str(e)}")
|
|
|
|
| 106 |
|
| 107 |
@app.post("/chat")
|
| 108 |
async def chat_endpoint(request: ChatRequest):
|
| 109 |
"""Handle chat conversations with formatting options"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
try:
|
| 111 |
logger.info(f"Chat request received (format: {request.format})")
|
| 112 |
raw_response = agent.chat(
|
|
|
|
| 136 |
@app.post("/upload")
|
| 137 |
async def upload_file(file: UploadFile = File(...)):
|
| 138 |
"""Handle file uploads and process with TxAgent"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
try:
|
| 140 |
logger.info(f"File upload received: {file.filename}")
|
| 141 |
content = ""
|
|
|
|
| 178 |
async def service_status():
|
| 179 |
"""Check service status"""
|
| 180 |
return {
|
| 181 |
+
"status": "running",
|
| 182 |
"version": "2.0.0",
|
| 183 |
"model": agent.model_name if agent else "not loaded",
|
| 184 |
"formats_available": ["raw", "clean", "structured", "html"],
|