Spaces:
Sleeping
Sleeping
File size: 1,058 Bytes
24c4def |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import json
import yaml
class ClaimGenerator:
def __init__(self, prompt_path, chat):
with open(prompt_path,"r",encoding='utf-8') as file:
self.prompt = yaml.load(file, yaml.FullLoader)
self.chat = chat
def get_response(self, text):
user_prompt = self.prompt["user"].format(text=text)
message = [
{"role": "system", "content": self.prompt["system"]},
{"role": "user", "content": user_prompt}
]
response = self.chat.get_response(message=message)
try:
response = json.loads(response)
except Exception as e:
print(e) # 是否有问题
claim_list = []
cnt = 0
for seg in response:
for cla in seg["claims"]:
cnt=(lambda x:x+1)(cnt)
claim_list.append("claim{}: {}".format(str(cnt), cla["claim"]))
claim_list = "\n".join([claim for claim in claim_list])
return response, claim_list
|