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', '')}]
|
||||
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.
|
||||
"""
|
||||
@@ -106,7 +106,7 @@ class LLMChat:
|
||||
except:
|
||||
pass
|
||||
time.sleep(sleeptime)
|
||||
return guarded_post(url, headers, payload)
|
||||
return self.guarded_post(url, headers, payload)
|
||||
else:
|
||||
data = response.json()
|
||||
response.close()
|
||||
@@ -131,7 +131,7 @@ class LLMChat:
|
||||
url = f"{self.provider.get('base_url').rstrip('/')}/chat/completions"
|
||||
|
||||
try:
|
||||
response = guarded_post(url, self.headers, payload)
|
||||
response = self.guarded_post(url, self.headers, payload)
|
||||
data = response.json()
|
||||
response.close() # Important for CircuitPython memory
|
||||
bot_content = data['choices'][0]['message']['content']
|
||||
|
||||
Reference in New Issue
Block a user