Try to fix the fix.
This commit is contained in:
parent
b82477fc83
commit
2cd66b55ee
@ -136,7 +136,14 @@ class AIResponder(object):
|
|||||||
result = await openai.ChatCompletion.acreate(model=self.config["fix-model"],
|
result = await openai.ChatCompletion.acreate(model=self.config["fix-model"],
|
||||||
messages=messages,
|
messages=messages,
|
||||||
temperature=0.2)
|
temperature=0.2)
|
||||||
return result['choices'][0]['message']['content']
|
logging.info(f"got this message as fix:\n{pformat(result['choices'][0]['message']['content'])}")
|
||||||
|
response = result['choices'][0]['message']['content']
|
||||||
|
start, end = response.find("```"), response.rfind("```")
|
||||||
|
if start == -1 or end == -1 or (start + 3) >= end:
|
||||||
|
return answer
|
||||||
|
response = response[start + 3, end]
|
||||||
|
logging.info(f"fixed answer:\n{pformat(response)}")
|
||||||
|
return response
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.warning(f"failed to execute a fix for the answer: {repr(err)}")
|
logging.warning(f"failed to execute a fix for the answer: {repr(err)}")
|
||||||
return answer
|
return answer
|
||||||
@ -146,9 +153,9 @@ class AIResponder(object):
|
|||||||
self.history.append(answer)
|
self.history.append(answer)
|
||||||
if len(self.history) > limit:
|
if len(self.history) > limit:
|
||||||
self.history = self.history[-limit:]
|
self.history = self.history[-limit:]
|
||||||
if self.history_file is not None:
|
if self.history_file is not None:
|
||||||
with open(self.history_file, 'wb') as fd:
|
with open(self.history_file, 'wb') as fd:
|
||||||
pickle.dump(self.history, fd)
|
pickle.dump(self.history, fd)
|
||||||
|
|
||||||
async def send(self, message: AIMessage) -> AIResponse:
|
async def send(self, message: AIMessage) -> AIResponse:
|
||||||
limit = self.config["history-limit"]
|
limit = self.config["history-limit"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user