From f1df184f4f6bfa7605951a331402df3432869b9a Mon Sep 17 00:00:00 2001 From: mike <219478+ilude@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:54:38 -0400 Subject: [PATCH] update css for show summary button --- app/processors/title_editor.py | 119 ++++++++++++++++----------------- app/static/css/widgets.css | 16 +++++ 2 files changed, 75 insertions(+), 60 deletions(-) diff --git a/app/processors/title_editor.py b/app/processors/title_editor.py index 5a06c72..f571619 100644 --- a/app/processors/title_editor.py +++ b/app/processors/title_editor.py @@ -6,72 +6,71 @@ from langchain.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate from langchain_core.messages import SystemMessage from langchain.output_parsers import ResponseSchema, StructuredOutputParser +from langchain.callbacks.tracers import ConsoleCallbackHandler from models.utils import calculate_sha1_hash - logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) -logger.propagate = False - -# create console handler -consoleHandler = logging.StreamHandler() -consoleHandler.setFormatter(logging.Formatter(fmt='%(asctime)s - %(message)s')) - -# Add console handler to logger -logger.addHandler(consoleHandler) class TitleEditor: - def __init__(self): - self.ollama_url = os.getenv('OLLAMA_URL') - if self.ollama_url: - parser = StructuredOutputParser.from_response_schemas( - [ResponseSchema(name="title", description="title of the article")] - ) + def __init__(self): + self.ollama_url = os.getenv('OLLAMA_URL') + if self.ollama_url: + parser = StructuredOutputParser.from_response_schemas( + [ResponseSchema(name="title", description="title of the article")] + ) + + format_instructions = f""" + {parser.get_format_instructions()} + The contents of the markdown code snippet MUST be in VALID json format which includes proper quotes and escape characters! + JSON property names are case sensitive, and MUST ONLY include the defined schema properties! + """ - prompt = PromptTemplate( - template=""" - title: {title}, - summary: {summary}, - {format_instructions} - """, - input_variables=["title", "summary"], - partial_variables={"format_instructions": parser.get_format_instructions()}, - ) + prompt = PromptTemplate( + template=""" + title: {title}, + summary: {summary}, + {format_instructions} + """, + input_variables=["title", "summary"], + partial_variables={"format_instructions": format_instructions}, + ) - # format chat prompt - system_prompt = SystemMessage(content=(""" - You are an expert news article title editor. - Use the provided title and summary to write a concise and accurate title that is informative and avoids sounding like clickbait. - Do not include links or urls in the title. - Do not editorialize the title, even if the title and description do. - Title must be as short as possible, aim to be less that 70 characters long. - Title must have an absolute minimum of punctuation and NOT use words that are all upper case. - """)) - user_prompt = HumanMessagePromptTemplate(prompt=prompt) - - chat_prompt = ChatPromptTemplate.from_messages([system_prompt, user_prompt]) - #model_name = "dolphin-mistral" - model_name = "dolphin-llama3" - model_temp = 0.2 - model = Ollama(base_url=self.ollama_url, model=model_name, keep_alive=5, temperature=model_temp) - self.chain = chat_prompt | model | parser - - self.script_hash = calculate_sha1_hash(f"{system_prompt.content}{model_name}{model_temp}") + # format chat prompt + system_prompt = SystemMessage(content=(""" + You are an expert news article title editor. + Use the provided title and summary to write a concise and accurate title that is informative and avoids sounding like clickbait. + Do not include links or urls in the title. + Do not editorialize the title, even if the title and description do. + Title must be as short as possible, aim to be less that 70 characters long. + Title must have an absolute minimum of punctuation and NOT use words that are all upper case. + Only return the title in the requested format! + """)) + user_prompt = HumanMessagePromptTemplate(prompt=prompt) + + chat_prompt = ChatPromptTemplate.from_messages([system_prompt, user_prompt]) + model_name = "dolphin-mistral" + #model_name = "dolphin-llama3" + model_temp = 0.0 + model = Ollama(base_url=self.ollama_url, model=model_name, keep_alive=5, temperature=model_temp) + self.chain = chat_prompt | model | parser + + self.script_hash = calculate_sha1_hash(f"{system_prompt.content}{model_name}{model_temp}") - def process(self, articles: list[FeedArticle]) -> list[FeedArticle]: - if self.ollama_url: - - needs_processed = list(filter(lambda article: article.processed != self.script_hash, articles)) - - total = len(needs_processed) - for count, article in enumerate(needs_processed, start=1): - try: - logger.info(f"Processing title {count}/{total}: {article.original_title}") - result = self.chain.invoke({"title": article.original_title, "summary": article.description}) - article.title = result['title'] - article.processed = self.script_hash - except Exception as ex: - logger.error(f"Error: {ex} for {article.original_title}") - #needs_processed.remove(article) - - return articles + def process(self, articles: list[FeedArticle]) -> list[FeedArticle]: + if self.ollama_url: + + needs_processed = list(filter(lambda article: article.processed != self.script_hash, articles)) + + total = len(needs_processed) + for count, article in enumerate(needs_processed, start=1): + try: + logger.info(f"Processing title {count}/{total}: {article.original_title}") + result = self.chain.invoke({"title": article.original_title, "summary": article.description}) #, config={'callbacks': [ConsoleCallbackHandler()]}) + article.title = result['title'] + article.processed = self.script_hash + except Exception as ex: + logger.error(f"Error: {ex} for {article.original_title}") + #needs_processed.remove(article) + + return articles diff --git a/app/static/css/widgets.css b/app/static/css/widgets.css index 4c9beb0..ee7e75b 100644 --- a/app/static/css/widgets.css +++ b/app/static/css/widgets.css @@ -74,6 +74,22 @@ ul li:last-child { color: #a885fac7; } +.widget-item { + position: relative; /* Make the parent container a positioning context */ +} + +.feed-link { + position: relative; /* Make the anchor tag a positioning context */ + z-index: 1; /* Ensure the anchor tag is on top of the toolbar */ +} + +.widget-item-toolbar { + position: absolute; /* Position the toolbar absolutely */ + top: 0; /* Align the toolbar to the top of its parent container */ + right: 0; /* Align the toolbar to the right of its parent container */ + z-index: 2; /* Ensure the toolbar is on top of the anchor tag */ +} + .summary { padding: 0.188em 0; }