Spaces:
Build error
Build error
Commit
·
49c93c0
1
Parent(s):
2b5105c
test connection
Browse files- app/main.py +19 -2
app/main.py
CHANGED
@@ -154,13 +154,30 @@ async def webhook(request: Request):
|
|
154 |
|
155 |
app.get("/webhook")(verify_webhook)
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
@app.post("/load_file")
|
158 |
async def load_file_with_markitdown(file_path: str, llm_client: str = None, model: str = None):
|
159 |
try:
|
160 |
async with httpx.AsyncClient(timeout=10) as client:
|
161 |
response = await client.get(file_path)
|
162 |
response.raise_for_status()
|
163 |
-
|
|
|
164 |
|
165 |
# Initialize MarkItDown
|
166 |
if llm_client and model:
|
@@ -169,7 +186,7 @@ async def load_file_with_markitdown(file_path: str, llm_client: str = None, mode
|
|
169 |
markitdown = MarkItDown()
|
170 |
|
171 |
# Convert the fetched content
|
172 |
-
documents = markitdown.
|
173 |
|
174 |
print(f"documents: {documents}")
|
175 |
return {"documents": documents}
|
|
|
154 |
|
155 |
app.get("/webhook")(verify_webhook)
|
156 |
|
157 |
+
|
158 |
+
@app.get("/test_connection")
|
159 |
+
async def test_connection():
|
160 |
+
url = "https://sswalfa.surabaya.go.id/info/detail/pengganti-ipt"
|
161 |
+
try:
|
162 |
+
async with httpx.AsyncClient(timeout=10) as client:
|
163 |
+
response = await client.get(url)
|
164 |
+
response.raise_for_status()
|
165 |
+
return {"status": "success", "data": response.text[:200]} # Return first 200 chars
|
166 |
+
except httpx.ConnectTimeout:
|
167 |
+
raise HTTPException(status_code=504, detail="Connection timed out.")
|
168 |
+
except httpx.HTTPStatusError as e:
|
169 |
+
raise HTTPException(status_code=e.response.status_code, detail=e.response.text)
|
170 |
+
except Exception as e:
|
171 |
+
raise HTTPException(status_code=500, detail=str(e))
|
172 |
+
|
173 |
@app.post("/load_file")
|
174 |
async def load_file_with_markitdown(file_path: str, llm_client: str = None, model: str = None):
|
175 |
try:
|
176 |
async with httpx.AsyncClient(timeout=10) as client:
|
177 |
response = await client.get(file_path)
|
178 |
response.raise_for_status()
|
179 |
+
print(f"response: {response.json()}")
|
180 |
+
content = response.json()
|
181 |
|
182 |
# Initialize MarkItDown
|
183 |
if llm_client and model:
|
|
|
186 |
markitdown = MarkItDown()
|
187 |
|
188 |
# Convert the fetched content
|
189 |
+
documents = markitdown.convert(content) # Assuming a method that accepts raw content
|
190 |
|
191 |
print(f"documents: {documents}")
|
192 |
return {"documents": documents}
|