Whitepaper
Docs
Sign In
Function
Function
filter
v0.1
Tama Adapter
Function ID
tama_adapter
Creator
@zacksiri
Downloads
9+
Adapter for Tama Engine
Get
README
No README available
Function Code
Show
""" title: Tama Adapter author: zacksiri author_url: https://github.com/zacksiri funding_url: https://github.com/zacksiri version: 0.1 """ from pydantic import BaseModel, Field from typing import Optional class Filter: class Valves(BaseModel): priority: int = Field( default=0, description="Priority level for the filter operations." ) max_turns: int = Field( default=8, description="Maximum allowable conversation turns for a user." ) pass class UserValves(BaseModel): max_turns: int = Field( default=4, description="Maximum allowable conversation turns for a user." ) pass def __init__(self): # Indicates custom file handling logic. This flag helps disengage default routines in favor of custom # implementations, informing the WebUI to defer file-related operations to designated methods within this class. # Alternatively, you can remove the files directly from the body in from the inlet hook # self.file_handler = True # Initialize 'valves' with specific configurations. Using 'Valves' instance helps encapsulate settings, # which ensures settings are managed cohesively and not confused with operational flags like 'file_handler'. self.valves = self.Valves() pass def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict: chat_id = body.get("chat_id") if chat_id is None: chat_id = body.get("metadata")["chat_id"] actor = {"identifier": __user__["id"], "source": "webui"} messages = [] for i, message in enumerate(body["messages"]): new_message = message.copy() new_message["index"] = i messages.append(new_message) body["chat_id"] = chat_id body["actor"] = actor body["message"] = messages[-1] del body["messages"] return body def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict: return body