diff --git a/nostr_dvm/tasks/summarization_huggingchat.py b/nostr_dvm/tasks/summarization_huggingchat.py index 45c8dd0..00585e2 100644 --- a/nostr_dvm/tasks/summarization_huggingchat.py +++ b/nostr_dvm/tasks/summarization_huggingchat.py @@ -54,8 +54,8 @@ class TextSummarizationHuggingChat(DVMTaskInterface): prompt += tag.as_vec()[1] + "\n" elif input_type == "event": collect_events.append(tag.as_vec()[1]) - #evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) - #prompt += evt.content() + "\n" + # evt = get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config) + # prompt += evt.content() + "\n" elif input_type == "job": evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client, kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT, @@ -66,7 +66,7 @@ class TextSummarizationHuggingChat(DVMTaskInterface): if evt is None: print("Event not found") raise Exception - + if evt.kind() == EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY: result_list = json.loads(evt.content()) prompt = "" @@ -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/.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 @@ -140,7 +138,7 @@ def build_example(name, identifier, admin_config): nip89config.CONTENT = json.dumps(nip89info) return TextSummarizationHuggingChat(name=name, dvm_config=dvm_config, nip89config=nip89config, - admin_config=admin_config) + admin_config=admin_config) if __name__ == '__main__': diff --git a/nostr_dvm/tasks/summarization_unleashed_chat.py b/nostr_dvm/tasks/summarization_unleashed_chat.py index 2b56330..e9e5345 100644 --- a/nostr_dvm/tasks/summarization_unleashed_chat.py +++ b/nostr_dvm/tasks/summarization_unleashed_chat.py @@ -4,7 +4,7 @@ import re from nostr_sdk import Tag, Kind from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv from nostr_dvm.utils.admin_utils import AdminConfig -from nostr_dvm.utils.definitions import EventDefinitions +from nostr_dvm.utils.definitions import EventDefinitions from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config from nostr_dvm.utils.nip88_utils import NIP88Config from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag @@ -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,14 +108,13 @@ 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=[ { 'role': 'user', - 'content':content, + 'content': content, } ], model='dolphin-2.2.1-mistral-7b', @@ -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) -