fixes for summarizers

This commit is contained in:
Believethehype 2024-04-15 11:54:59 +02:00
parent cb7802c509
commit c60e8af3af
2 changed files with 15 additions and 19 deletions

View File

@ -83,9 +83,11 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
for evt in evts:
prompt += evt.content() + "\n"
clean_prompt = re.sub(r'^https?:\/\/.*[\r\n]*', '', prompt, flags=re.MULTILINE)
options = {
"prompt": prompt,
"prompt": clean_prompt[:4000],
}
request_form['options'] = json.dumps(options)
return request_form
@ -102,14 +104,11 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
cookies = sign.login()
sign.saveCookiesToDir(cookie_path_dir)
options = DVMTaskInterface.set_options(request_form)
try:
chatbot = hugchat.ChatBot(cookies=cookies.get_dict()) # or cookie_path="usercookies/<email>.json"
text = re.sub(r'^https?:\/\/.*[\r\n]*', '', str(options["prompt"]), flags=re.MULTILINE)
query_result = chatbot.query("Summarize the following notes: " + text[:3500])
query_result = chatbot.query("Summarize the following notes: " + str(options["prompt"]))
print(query_result["text"]) # or query_result.text or query_result["text"]
return str(query_result["text"]).lstrip()
@ -118,7 +117,6 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
raise Exception(e)
# We build an example here that we can call by either calling this file directly from the main directory,
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
# playground or elsewhere

View File

@ -84,9 +84,9 @@ class SummarizationUnleashedChat(DVMTaskInterface):
for evt in evts:
prompt += evt.content() + "\n"
prompt = re.sub(r'http\S+', '', prompt)
clean_prompt = re.sub(r'^https?:\/\/.*[\r\n]*', '', prompt, flags=re.MULTILINE)
options = {
"prompt": prompt,
"prompt": clean_prompt[:4000],
"nostr": nostr_mode,
}
request_form['options'] = json.dumps(options)
@ -108,9 +108,8 @@ class SummarizationUnleashedChat(DVMTaskInterface):
for model in client.models.list():
print('- ' + model.id)
text = re.sub(r'^https?:\/\/.*[\r\n]*', '', str(options["prompt"]), flags=re.MULTILINE)
content = "Summarize the following notes: " + text[:3500]
content = "Summarize the following notes: " + str(options["prompt"])
normal_stream = client.chat.completions.create(
messages=[
{
@ -148,7 +147,6 @@ def build_example(name, identifier, admin_config):
dvm_config.SEND_FEEDBACK_EVENTS = True
admin_config.LUD16 = dvm_config.LN_ADDRESS
nip89info = {
"name": name,
"image": "https://unleashed.chat/_app/immutable/assets/hero.pehsu4x_.jpeg",
@ -164,9 +162,9 @@ def build_example(name, identifier, admin_config):
admin_config2 = AdminConfig()
admin_config2.REBROADCAST_NIP89 = False
return SummarizationUnleashedChat(name=name, dvm_config=dvm_config, nip89config=nip89config, admin_config=admin_config2)
return SummarizationUnleashedChat(name=name, dvm_config=dvm_config, nip89config=nip89config,
admin_config=admin_config2)
if __name__ == '__main__':
process_venv(SummarizationUnleashedChat)