Adds a "Thought for X seconds...." to BetterR1.txt
Adds a "Thought for X seconds...." to BetterR1.txt
This commit is contained in:
+11
-23
@@ -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(
|
||||
"<think>", "<details>\n<summary>Thoughts 💭</summary>"
|
||||
)
|
||||
|
||||
model_response = model_response.replace("</think>", "\n\n---\n\n</details>")
|
||||
|
||||
messages[-1]["content"] = model_response
|
||||
body["messages"] = messages
|
||||
|
||||
# Reset timer for next run
|
||||
Filter.start_time = time.time()
|
||||
|
||||
return body
|
||||
|
||||
Reference in New Issue
Block a user