mirror of
https://github.com/senju1337/senju.git
synced 2025-12-23 23:39:27 +00:00
fix: request_haiku method did not work with a simple 3 line haiku
Refs: OPS-70
This commit is contained in:
parent
897bf80e38
commit
3889809d07
1 changed files with 16 additions and 6 deletions
|
|
@ -29,23 +29,32 @@ class Haiku:
|
|||
"eval_count": 20
|
||||
}
|
||||
|
||||
tries = 0
|
||||
while True:
|
||||
tries += 1
|
||||
try:
|
||||
r = requests.post(url=url,
|
||||
json=ai_gen_request)
|
||||
ai_response = str(r.json()["response"])
|
||||
|
||||
logging.warning(ai_response)
|
||||
logging.debug(f"ai response: {ai_response}")
|
||||
|
||||
lines = ai_response.split("\n")
|
||||
|
||||
while len(lines) != 3:
|
||||
lines.pop()
|
||||
|
||||
logging.warning(lines)
|
||||
logging.info(f"lines for haiku: {lines}")
|
||||
|
||||
if len(lines) != 3:
|
||||
continue
|
||||
if len(lines) < 3:
|
||||
if tries < 20:
|
||||
logging.warning(f"too few lines, trying again")
|
||||
logging.debug(lines)
|
||||
continue
|
||||
else:
|
||||
logging.warning(f"too many tries, aborting")
|
||||
raise Exception(
|
||||
"Generating the haiku took too many tries")
|
||||
|
||||
haiku = Haiku(
|
||||
[
|
||||
|
|
@ -55,8 +64,9 @@ class Haiku:
|
|||
])
|
||||
|
||||
break
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
except json.JSONDecodeError as e:
|
||||
logging.error(f"error while reading json from LLM: {e}")
|
||||
raise e
|
||||
|
||||
return haiku
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue