Implementing the filterText function for APIs in SillyTavern.
Do not do this until you are well aware of what you are doing. I, Flamanon, do not take any responsibility if you break your SillyTavern while making the changes prescribed below, proceed of your own volition.
Table of Contents
Please use the filterText.js
file provided with the FilterConfigurationModule and not your old file from Zlaude
-
Quick intro
After I made Zlaude, people requested me to make a filter for API keys as well, at first i was a bit apprehensive of making changes in the SillyTavern files to implement this functionality, primarily because people absolutely do not want to read and figure things out for themselves, which leads to my DMs being cluttered with how-do-i-do-this type of messages. But because of popular demand, I have decided to create this tutorial to allow you to implement the filterText function for APIs.
Copy the original server.js
file from the Sillytavern folder and paste it somewhere else, in case you mess things up or do not want to use the filterText
function, you can paste the original file back into the SillyTavern folder, hence replacing the modified file.
-
For Anthropic API
(OOC: To all you lucky peeps whose applications went through, congratulations Jealous slow claps. This one is going to be pretty straightforward, or not Muahahaha)
- Install a text editor, preferably Sublime Text.
- Navigate to the path where you would like to clone the Filter Configuration Module and type
cmd.exe
in the address bar. Once the command prompt opens up, typegit clone https://github.com/Flamanon/FilterConfigurationModule
and hit enter. This will clone the repository in the desired path. Now, click onnewconfig.bat
and follow the steps in theREADME.md
file in theFlamanon/FilterConfigurationModule
repository to configure your filter. - Once you have configured the filter, copy the
filterText.js
file and paste it in the SillyTavern folder. - This is where the fun begins:
- Open the
server.js file
in the SillyTavern Folder using your text editor, and navigate to line number 2900 (OOC: Yeah, Big number) and above theasync function sendClaudeRequest(request, response) {
line writeconst filterText = require('./filterText');
. Now, Navigate toconsole.log('Claude response:', responseText);
usingCtrl+F
(Shortcut for Find tool in Sublime text).
-
Now below this paste the following bit of code:
Under this you will find
//Wrap it back up to OAI format
, in this section, replaceresponseText
withfilteredResponseText
. So it should look something like this:
And we're done for this section. (OOC: Yup, drink some water, wipe the sweat on your forehead big guy. You live to see another day!)
-
For OpenAI API
(OOC: This one might look a tad-bit scarier, and honestly while testing it i did face some bumps here and there, but in the end it just began working like expected, weird.)
- The first two steps for this are identical to the changes we made for Anthropic's API. And also, remember to paste
const filterText = require('./filterText');
in the right place in theserver.js
file.(see pt. no. 4 in Anthropic API) - Navigate to line 3022 or something like that (OOC: but it might not be 3022 anymore if you also just altered the Anthropic API section or even pasted the
const filterText = require('./filterText');
line as instructed, as it was located just above the OAI section, so the line we're looking for is prolly numbered anything >3022, dont worry tho, use the Find tool with the text in the picture below to navigate to it)
- So replace the code below
(OOC: oooohhh boy! That one looked a bit messy didn't it? Yeah...but you did it tho(hopefully), good job!)
- The first two steps for this are identical to the changes we made for Anthropic's API. And also, remember to paste
-
Poe API
(OOC: This is probably the easiest one out of all the modification suggested in this document. However, I have not tested this one as much as i have tested the others, so just keep that in mind.)
- Open the SillyTavern folder and then open the
src
subfolder. Now paste yourfilterText.js
file here. You will have to modify thefilterText.js
file a little bit for this one. Copy thefunction filterText(text) {
line and replace it with:
function filterText(text) { // Will check if input is a valid string if (typeof text !== 'string') { return ''; }
so before:
and after:
- Now open the
poe-client.js
file, and right under the starting comment (probably line 20) writeconst filterText = require('./filterText');
Should look like:.
- In the same file find
async on_message
, this section looks like:- Replace
const message = message_data["payload"]["data"]["messageAdded"]
with:
- Replace
(OOC: And we're done, you survived!!(hopefully). Make sure to keep a backup of
server.js
andpoe-client.js
files.)
- Open the SillyTavern folder and then open the