From fbca081eae6fa09ea0abd86014bb58012c7f97bc Mon Sep 17 00:00:00 2001 From: Regis David Souza Mesquita Date: Wed, 22 Jan 2025 15:57:40 +0000 Subject: [PATCH] Adds a "Thought for X seconds...." to BetterR1.txt Adds a "Thought for X seconds...." to BetterR1.txt --- BetterR1.txt | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/BetterR1.txt b/BetterR1.txt index 891b74e..3e53806 100644 --- a/BetterR1.txt +++ b/BetterR1.txt @@ -1,31 +1,23 @@ -""" -title: Better R1 -author: Aaron Feng -author_url: https://github.com/AaronFeng753 -version: 0.1 -""" - from pydantic import BaseModel, Field from typing import Optional import re - +import time class Filter: + start_time = None # class variable to track time + class Valves(BaseModel): priority: int = Field(default=0, description="") max_turns: int = Field(default=9999, description="") - pass class UserValves(BaseModel): max_turns: int = Field(default=9999, description="") - pass def __init__(self): self.valves = self.Valves() - pass + Filter.start_time = time.time() # set initial time when instance created def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict: - messages = body.get("messages", []) modified_messages = [] @@ -40,34 +32,30 @@ class Filter: modified_messages.append(modified_message) body["messages"] = modified_messages - - # print(f"inlet:modified_body:{body}") - return body async def outlet( self, body: dict, __user__: Optional[dict] = None, __event_emitter__=None ) -> dict: - # print(f"outlet:{__name__}") - # print(f"outlet:body:{body}") - # print(f"outlet:user:{__user__}") - + elapsed_time = time.time() - Filter.start_time + messages = body.get("messages", []) - if not messages: return body - User_message = messages[-2].get("content", "") - model_response = messages[-1].get("content", "") + thought_time_str = f"Thought for {int(elapsed_time)} seconds...\n\n" + model_response = thought_time_str + model_response model_response = model_response.replace( "", "
\nThoughts 💭" ) - model_response = model_response.replace("", "\n\n---\n\n
") messages[-1]["content"] = model_response body["messages"] = messages + # Reset timer for next run + Filter.start_time = time.time() + return body