Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,11 +86,9 @@ async def webhook(request: Request) -> Dict[str, Any]:
|
|
| 86 |
if chunk.choices[0].delta.content is not None:
|
| 87 |
continuation_text += chunk.choices[0].delta.content
|
| 88 |
continuation_text = continuation_text.strip()
|
| 89 |
-
print(f"Bot response: {continuation_text[:50]}...")
|
| 90 |
if not continuation_text:
|
| 91 |
raise ValueError("No text generated by NVIDIA API")
|
| 92 |
except Exception as e:
|
| 93 |
-
print(f"Inference error: {str(e)}")
|
| 94 |
raise HTTPException(status_code=500, detail=f"Inference failed: {str(e)}")
|
| 95 |
|
| 96 |
# Publication du commentaire avec gestion des nouvelles tentatives
|
|
@@ -108,16 +106,12 @@ async def webhook(request: Request) -> Dict[str, Any]:
|
|
| 108 |
comment_response.raise_for_status()
|
| 109 |
# Vérifier si la réponse contient "newMessage" (succès implicite)
|
| 110 |
if comment_response.json().get("newMessage"):
|
| 111 |
-
print("Bot comment posted successfully")
|
| 112 |
return {"success": True}
|
| 113 |
-
print("Bot comment posted successfully")
|
| 114 |
return {"success": True}
|
| 115 |
except requests.exceptions.HTTPError as e:
|
| 116 |
if "rate-limited" in str(e):
|
| 117 |
-
print(f"Rate limit encountered, retrying after {2 ** attempt} seconds")
|
| 118 |
time.sleep(2 ** attempt) # Backoff exponentiel
|
| 119 |
continue
|
| 120 |
-
print(f"Comment posting error: {str(e)}")
|
| 121 |
raise HTTPException(status_code=500, detail=f"Failed to post comment: {str(e)}")
|
| 122 |
|
| 123 |
raise HTTPException(status_code=429, detail="Rate limit exceeded after retries")
|
|
@@ -127,7 +121,6 @@ async def webhook(request: Request) -> Dict[str, Any]:
|
|
| 127 |
except HTTPException as he:
|
| 128 |
raise he
|
| 129 |
except Exception as e:
|
| 130 |
-
print(f"Unexpected error: {str(e)}")
|
| 131 |
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
|
|
|
| 86 |
if chunk.choices[0].delta.content is not None:
|
| 87 |
continuation_text += chunk.choices[0].delta.content
|
| 88 |
continuation_text = continuation_text.strip()
|
|
|
|
| 89 |
if not continuation_text:
|
| 90 |
raise ValueError("No text generated by NVIDIA API")
|
| 91 |
except Exception as e:
|
|
|
|
| 92 |
raise HTTPException(status_code=500, detail=f"Inference failed: {str(e)}")
|
| 93 |
|
| 94 |
# Publication du commentaire avec gestion des nouvelles tentatives
|
|
|
|
| 106 |
comment_response.raise_for_status()
|
| 107 |
# Vérifier si la réponse contient "newMessage" (succès implicite)
|
| 108 |
if comment_response.json().get("newMessage"):
|
|
|
|
| 109 |
return {"success": True}
|
|
|
|
| 110 |
return {"success": True}
|
| 111 |
except requests.exceptions.HTTPError as e:
|
| 112 |
if "rate-limited" in str(e):
|
|
|
|
| 113 |
time.sleep(2 ** attempt) # Backoff exponentiel
|
| 114 |
continue
|
|
|
|
| 115 |
raise HTTPException(status_code=500, detail=f"Failed to post comment: {str(e)}")
|
| 116 |
|
| 117 |
raise HTTPException(status_code=429, detail="Rate limit exceeded after retries")
|
|
|
|
| 121 |
except HTTPException as he:
|
| 122 |
raise he
|
| 123 |
except Exception as e:
|
|
|
|
| 124 |
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")
|
| 125 |
|
| 126 |
if __name__ == "__main__":
|