Originally created by @0721-Day on GitHub (Jul 2, 2025).
Check Existing Issues
I have searched the existing issues and discussions.
Problem Description
I created a Filter to generate random numbers within the chat.
It works normally, but before each request, I need to go through all the chat records to replace this random value.
It cannot be stored in the database, and I haven't found a better solution
Perhaps "Pipe" can achieve this function, but if we insist on using its proxy for every model, I believe it would be counterproductive.
It could also be that I am not very familiar with the project, and I am unable to find a reasonable solution
async def inlet(self, body: dict, __event_emitter__) -> dict:
# This is where you manipulate user inputs.
chat_id = body["metadata"]["chat_id"]
random.seed(chat_id)
__RANDOM__ = r"\{\{RANDOM\#\[([^\]]+)\]\#(\d+)\}\}"
def replace_random(match):
items = [item.strip() for item in match.group(1).split(",")]
count = int(match.group(2))
selected = random.sample(items, min(count, len(items)))
return ", ".join(selected)
for i, msg in enumerate(body["messages"]):
if i >= 10:
break
if "content" in msg and isinstance(msg["content"],str):
msg["content"] = re.sub(__RANDOM__, replace_random, msg["content"])
return body
Desired Solution you'd like
There are optional parameters or other methods to directly modify the original content
Alternatives Considered
No response
Additional Context
No response
Originally created by @0721-Day on GitHub (Jul 2, 2025).
### Check Existing Issues
- [x] I have searched the existing issues and discussions.
### Problem Description
I created a Filter to generate random numbers within the chat.
It works normally, but before each request, I need to go through all the chat records to replace this random value.
It cannot be stored in the database, and I haven't found a better solution
Perhaps "Pipe" can achieve this function, but if we insist on using its proxy for every model, I believe it would be counterproductive.
It could also be that I am not very familiar with the project, and I am unable to find a reasonable solution
```
async def inlet(self, body: dict, __event_emitter__) -> dict:
# This is where you manipulate user inputs.
chat_id = body["metadata"]["chat_id"]
random.seed(chat_id)
__RANDOM__ = r"\{\{RANDOM\#\[([^\]]+)\]\#(\d+)\}\}"
def replace_random(match):
items = [item.strip() for item in match.group(1).split(",")]
count = int(match.group(2))
selected = random.sample(items, min(count, len(items)))
return ", ".join(selected)
for i, msg in enumerate(body["messages"]):
if i >= 10:
break
if "content" in msg and isinstance(msg["content"],str):
msg["content"] = re.sub(__RANDOM__, replace_random, msg["content"])
return body
```
### Desired Solution you'd like
There are optional parameters or other methods to directly modify the original content
### Alternatives Considered
_No response_
### Additional Context
_No response_
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @0721-Day on GitHub (Jul 2, 2025).
Check Existing Issues
Problem Description
I created a Filter to generate random numbers within the chat.
It works normally, but before each request, I need to go through all the chat records to replace this random value.
It cannot be stored in the database, and I haven't found a better solution
Perhaps "Pipe" can achieve this function, but if we insist on using its proxy for every model, I believe it would be counterproductive.
It could also be that I am not very familiar with the project, and I am unable to find a reasonable solution
Desired Solution you'd like
There are optional parameters or other methods to directly modify the original content
Alternatives Considered
No response
Additional Context
No response
@tjbck commented on GitHub (Jul 2, 2025):
Not entirely sure what you meant here, could you elaborate a bit more?