mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +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
|
"eval_count": 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tries = 0
|
||||||
while True:
|
while True:
|
||||||
|
tries += 1
|
||||||
try:
|
try:
|
||||||
r = requests.post(url=url,
|
r = requests.post(url=url,
|
||||||
json=ai_gen_request)
|
json=ai_gen_request)
|
||||||
ai_response = str(r.json()["response"])
|
ai_response = str(r.json()["response"])
|
||||||
|
|
||||||
logging.warning(ai_response)
|
logging.debug(f"ai response: {ai_response}")
|
||||||
|
|
||||||
lines = ai_response.split("\n")
|
lines = ai_response.split("\n")
|
||||||
|
|
||||||
while len(lines) != 3:
|
while len(lines) != 3:
|
||||||
lines.pop()
|
lines.pop()
|
||||||
|
|
||||||
logging.warning(lines)
|
logging.info(f"lines for haiku: {lines}")
|
||||||
|
|
||||||
if len(lines) != 3:
|
if len(lines) < 3:
|
||||||
|
if tries < 20:
|
||||||
|
logging.warning(f"too few lines, trying again")
|
||||||
|
logging.debug(lines)
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
logging.warning(f"too many tries, aborting")
|
||||||
|
raise Exception(
|
||||||
|
"Generating the haiku took too many tries")
|
||||||
|
|
||||||
haiku = Haiku(
|
haiku = Haiku(
|
||||||
[
|
[
|
||||||
|
|
@ -55,8 +64,9 @@ class Haiku:
|
||||||
])
|
])
|
||||||
|
|
||||||
break
|
break
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError as e:
|
||||||
continue
|
logging.error(f"error while reading json from LLM: {e}")
|
||||||
|
raise e
|
||||||
|
|
||||||
return haiku
|
return haiku
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue