added post guards to deck.llm
This commit is contained in:
+3
-3
@@ -86,7 +86,7 @@ class LLMChat:
|
|||||||
self.messages = [{"role": "system", "content": self.config.get('system_prompt', '')}]
|
self.messages = [{"role": "system", "content": self.config.get('system_prompt', '')}]
|
||||||
return (True, "Context cleared")
|
return (True, "Context cleared")
|
||||||
|
|
||||||
def guarded_post(url, headers={}, payload={}):
|
def guarded_post(self, url, headers={}, payload={}):
|
||||||
"""
|
"""
|
||||||
Performs a POST request trying to bypass possible 429 errors with heuristics.
|
Performs a POST request trying to bypass possible 429 errors with heuristics.
|
||||||
"""
|
"""
|
||||||
@@ -106,7 +106,7 @@ class LLMChat:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
time.sleep(sleeptime)
|
time.sleep(sleeptime)
|
||||||
return guarded_post(url, headers, payload)
|
return self.guarded_post(url, headers, payload)
|
||||||
else:
|
else:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
response.close()
|
response.close()
|
||||||
@@ -131,7 +131,7 @@ class LLMChat:
|
|||||||
url = f"{self.provider.get('base_url').rstrip('/')}/chat/completions"
|
url = f"{self.provider.get('base_url').rstrip('/')}/chat/completions"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = guarded_post(url, self.headers, payload)
|
response = self.guarded_post(url, self.headers, payload)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
response.close() # Important for CircuitPython memory
|
response.close() # Important for CircuitPython memory
|
||||||
bot_content = data['choices'][0]['message']['content']
|
bot_content = data['choices'][0]['message']['content']
|
||||||
|
|||||||
Reference in New Issue
Block a user