Assistant API removing【5 sources】
# 📖tutorials
a
Removing the 【5 sources】can be done using a bit of code. In Botpress Assistant API file, - open SRC folder >> handle response - head to the execute code card shown in the screenshot - slot in this code below after the line "let responseText". > // delete everything between and including【】 > responseText = responseText.replace(/【.*?】/g, "") Here is the link to botpress's GPTs deployment code https://botpress.com/templates/deploy-openai-gpts _###Debugging### _ 1) Check if you have a text card printing
workflow.response
. 2) Check if bracket symbol in code is the same as output. Copy and paste the brackets from your output and replace the ones in the code. 3) If above don't work, create 2 variables, one before change and one after change for trouble shooting. Print both workflow.responseRaw & workflow.response > // Extracting the first text value from the response data. > let responseText = response.data.data[0].content[0].text.value > > workflow.responseRaw = responseText > > // delete everything between and including【】 > responseText = responseText.replace(/【.*?】/g, "") > > workflow.response = responseText 4) If above don't work, @quick-musician-29561 kindly shared the ultimate bug hunter. Link below. https://discord.com/channels/1108396290624213082/1192699975990259822/1199027713583886406 .
w
Thank you for sharing Josh!
c
Thanks @able-rocket-15603 😉
f
Would you help me please oh would you give me your template to remove Source from the Open IA wizards
b
same
a
@fierce-nest-17923 @best-army-74344 The original Assistant API code can be found here.. After downloading a copy of the bot, you can paste in the above mentioned code. Let me know if it works for you. https://botpress.com/templates/deploy-openai-gpts
f
At the moment it doesn't work for me since it comes out another way
I try to implement the code and I really get an error
a
@fierce-nest-17923 Replace: > workflow.response = response.data.data[0].content[0].text.value With: > Let responseText = response.data.data[0].content[0].text.value > > // delete everything between and including【】 > responseText = responseText.replace(/【.*?】/g, "") > > workflow.response = responseText
c
Thank you @able-rocket-15603 !
f
I get this error, how can I fix it?
I get this error, how can I fix it?
a
@fierce-nest-17923 Will need more info to do debugging. Were you able to get a response before the code change?
b
This work for me !
Thanks @able-rocket-15603 🙌
f
If the bot responded to me previously. Wouldn't it be easier if you could send me a modified template to see if it works for me?
t
Unfortunately it's been a while since Open Ai has still not resolved the response delay problem with the API...
b
You mean that it take's too much time to get an answer?
Heyy again @able-rocket-15603 , so testing my bot, i got again the [35+source] problem. Any idea how can I fix this 🕵️‍♂️
@fresh-fireman-491 any idea🤣
f
Add this
responseText = responseText.replace(/【.*?】/g, "")
Change the responseText to the variable that has the output from the Assistants
b
It's like this already
or does I have an error
f
And it still shows up in the workflow.response?
b
Yep
f
Then @able-rocket-15603 would have to step in as this is not my field of expertise
b
Thanks anyway @fresh-fireman-491 🙂
@User
a
@best-army-74344 1) Check if you have a text card printing
workflow.response
. See image below. 2) If above don't work, check if bracket symbol in code is the same as output. Copy and paste the brackets from your output and replace the ones in the code? 3) If above don't work, create 2 variables, one before change and one after change. Print both. This is for trouble shooting. workflow.responseRaw & workflow.response > // Extracting the first text value from the response data. > let responseText = response.data.data[0].content[0].text.value > > workflow.responseRaw = responseText > > // delete everything between and including【】 > responseText = responseText.replace(/【.*?】/g, "") > > workflow.response = responseText
b
Thankss🙌🙌
Could you send me a template obviously without your api key and assistant Id
My api call card is different
a
@best-army-74344 This template is taken from botpress
b
@quick-musician-29561
q
What a great tutorial from 🦸‍♂️ @able-rocket-15603 🛠️ ! I tried all of JoshZ's and Decay's instructions, and they worked, as seen here. The first picture is without their instructions, and the second one is using their instructions. I was going to post a guide on "How to debug the Assistants API," I have done it so many times (not enough times it seems). But since it's still in BETA, and even OpenAI devs are debugging it every day, maybe it's not smart to try to solve issues they know exist and are going to solve when they update it. I have not been using the Assistants API with the Retrieval tool so much, only in the beginning when testing it, since I don't have my own use case for that. For my simple chatbots (so far), the Botpress KB table is more than enough. But since this is a really important feature for many who have much more advanced use cases, I wanted to try it as well.
So, I came up with five different alternative solutions, which I have used and they also work. Maybe not all of those are a perfect fit for this problem. Solution #1: If you are using GPT-3.5, consider switching to GPT-4. One day, all my Assistants API projects suddenly stopped working. I began debugging them, and then I tried my initial Assistants API projects here, only to find that they didn't work either. All projects were using external APIs, and I tried various solutions without success. Then I changed the Assistants to use GPT-4, and all of them started working without me changing anything else. It's not ideal that it only works with the more expensive GPT-4, especially since some of these projects are quite simple, like my weather chatbot here, which just uses a weather API to get the current weather. GPT-3.5 should be more than capable of handling that task. Additionally, some projects may not even be able to function with the daily costs associated with using GPT-4.
Solution #2: Ask AI nicely. In your Assistants API instructions, include something like, 'Answer users' questions only from these documents and never include any annotations or citations (or always include them if that is your use case, which is good, for example, with research papers).' I tried something like that, and it worked as well, but perhaps I was just lucky. If I had tested it enough, I might have noticed that it doesn't work (since many bot builders have reported that it doesn't).
Solution #3: Order AI to do its job. In Assistants API Instructions, use a prompt like, 'IF YOU INCLUDE ANY ANNOTATIONS OR CITATIONS, I WILL HUNT YOU DOWN, AND I WILL DELETE YOU.' Add an image of Liam Neeson; AI should recognize that and understand the seriousness of the request.
b
What 😂
q
Solutions 4 and 5 are going to be more useful, but I added a touch of humor since, in addition to your bot building skills, you are also known as a funny guy 🦸‍♂️ 🛠️ 🫡
Solution #4: Make sure you are using the correct JavaScript syntax. If you are using the same Assistants API call than in the Botpress template JoshZ provided, and match the instructions from JoshZ and Decay carefully, it works. If you are using a custom build Assistants API with complex tools, then it may return the answer in a slightly different form. Make sure you are replacing the【†5 sources】 from a correct type of variable. So use this .replace(/【.?】/g, "") to a variable which has to be a string (=text).
This code works in my custom Assistants API project (the last part of the API call):
Copy code
js
const response = await listMessages(session.threadID);

workflow.response = response.data.data[0].content[0].text.value
const regexBrackets = /【.?】/g;
workflow.response2 = workflow.response.replace(regexBrackets, "");
You can use that .replace(/【.*?】/g, "") to a 'workflow.response' variable which is 100% a string, if you have used Type: String. Then you can create a second variable called 'workflow.response2' and display that to the user and it has removed all the 【†5 sources】
If you are using .replace(/【.?】/g, "") to entire response Assistants API is returning, then that's an Array of objects, and in JavaScript to perform a replace operation on an array of objects, you need to iterate over each object and then specifically target the string within each object where the replacement should occur.
For example
Copy code
js
response.forEach(message => {
    message.content.forEach(content => {
        if (content.text && content.text.value) {
            content.text.value = content.text.value.replace(/【.*?】/g, "");
        }
    });
});
If you also have these errors that many have in OpenAI Help-forums ​【oaicite:0】​.
Then use it like this
Copy code
js
response.forEach(message => {
    message.content.forEach(content => {
        if (content.text && content.text.value) {
            const regexZeroWidthSpace = /​/g;
            content.text.value = content.text.value.replace(regexZeroWidthSpace, "");

            const regexBrackets = /【.?】/g;
            content.text.value = content.text.value.replace(regexBrackets, "");
        }
    });
});
Solution #5: Upload your chatbot. Or send us the exact code that you're using with Assistants API, so we can try it and get the exact same response from the API call. Then we can try to fix it together! 🤖 🚀
m
@enough-cat-65786 Here's the fix
I don't see the HTTP GET request thingy
@fresh-fireman-491 (sorry for the ping) coudl you help me?
f
The Assistants API is unfortunately not in my area of expertise. Maybe its better to ask @able-rocket-15603 here
m
@able-rocket-15603 Sorry for the ping brother, mind helping here?
a
@mammoth-salesmen-78451 no worries.. It is usually the last "execute code" card before you do the text card. We are changing whatever variable is holding your response.data.data[0].content[0].text.value
m
Tanks man, truly appreciate it 🙏
@able-rocket-15603 (sorry for the ping) I tried copying the code and doing lots of things, but nothing's still working. is there new fix being implemented, is that what you meant in the previous message?
a
@mammoth-salesmen-78451 Have you tried trouble shooting it using this? https://discord.com/channels/1108396290624213082/1192699975990259822/1197809387062952006 Otherwise if you could send a snapshot of the code, might be able to debug it better. Also, Assistant API was my temp solution while botpress team was pushing out GPT-4 Turbo into the knowledge agent. Now that it is out, you might want to test that out.
m
@able-rocket-15603 I want to connect my assistant API bot to botpress so that I could host it. The only problem is the (source) error
I'll send a screenshot of the code rn
I tried replaceing the last execute dode block with your code
didn't work
Last one here
e
Hi. Having the same issue like @mammoth-salesmen-78451 and the exact same code like in the screenshot. I tried the tutorial and it did not work. Any suggestions @able-rocket-15603 ?
c
It would perhaps help if you could pinpoint where it failed.
e
I inserted the code exactly like @mammoth-salesmen-78451 and it still gave the source citations…
m
it keep on adding (source5) (any number, not just 5) with the responce
d
Ok one more option here put this code
right there and it also works
a
Hello, thank you for all the advice. Unfortunately, it doesn't work for me... I followed the instructions you provided to integrate our Assistant API here: https://discord.com/channels/1108396290624213082/1180023587646746715 And I am unable to remove the sources. Do you have a solution? Or perhaps someone else could help me?
d
@alert-activity-33578 use this
j
hii
so im using the deploy GPT extension
where do i add this code ?
b
gpt or assistant api?
j
I used the gpt deploy extension
@quick-musician-29561 plssssssssss help
q
Yesss, I can also try this today! 🫡 We need to fix this issue. Those previous instructions here worked when we tried them last time; let's see if something has changed.
j
are you fixing the bot please ???????????????????????
PLSSSS
My client is pissed 😭
f
About what?
q
I downloaded the bot file. After testing, make sure to change your OpenAI API key, etc., because those are in the bot file also.
j
Shucks....
Ok
I don't see any errors
j
Yeah, becuase i dont hav teh code in there.
i took it out. 🙂
I dont know where to put the code
q
So everything is working regarding that issue, no 'sources' to remove?
j
There is sources.
Let me show you
Here are some complex Euclidean Geometry problems for you to solve: Find the value of 'a' if a = 70° and h = 100°【11†source】. Solve for 'b' when 20° < b < 80° and c = 70°, d = 100°, e = 80°【11†source】. Determine the length of BC if BC = 674 cm【11†source】. Calculate the missing angles when B^ = 65°, E_2^ = 65°, M_2^ = 115°, and N_1^ = 115°【11†source】. Given A^ = 110°, find the measures of B_1^, D_1^ if B_2^ = D_2^ = 35°【11†source】. If C_2^L = 60° and M_2^N = 120°, what are the values of the other angles in the figure referenced?【11†source】. Please ensure you have the full geometry figure or additional
It says that when it has to provide a lot of content
q
Ok, can you give the exact questions how to get that error? I tried and it was working well, so I didn't ask the right questions
using your chatbot
j
Create 20 random questions
click the button create a quz
q
j
Yeah, how can i fix this.
It deos this when it has a lot of content to give.
Why openai password ?
Make a text that has 10 questions with the answer under each question. It should be about chapter 1 M Virtual assistant said : Hey there! Here's a 10-question test based on Chapter 1: Algebraic Expressions, along with the answers for each question: Simplify: 3(x - 2) + 4 Answer: 3x - 6 + 4 = 3x - 2 Factorize: x^2 - 9 Answer: (x + 3)(x - 3) Expand: (4x + 3)(2x - 5) Answer: 8x^2 - 20x + 6x - 15 = 8x^2 - 14x - 15 Simplify: (5x^3 - 4x^2 + 3x) - (2x^3 + x^2 - x) Answer: 5x^3 - 4x^2 + 3x - 2x^3 - x^2 + x = 3x^3 - 5x^2 + 4x Solve for x: 4(x - 1) + 3(2x + 5) = 2(3x + 7) Answer: 4x - 4 + 6x + 15 = 6x + 14 10x + 11 = 6x + 14 4x = 3 x = 3/4 If ( a^2 = 9 ) and ( b = -4 ), evaluate: ( 2a - 3b ) Answer: ( 2\sqrt{9} - 3(-4) = 2 \cdot 3 + 12 = 6 + 12 = 18 ) Simplify: ( \frac{2x^2y - 14xy^2}{6xy} ) Answer: ( \frac{2x^2y}{6xy} - \frac{14xy^2}{6xy} = \frac{2x}{6} - \frac{14y}{6} = \frac{x}{3} - \frac{7y}{3} ) Determine the product of ( (x + 5) ) and ( (x - 5) ) Answer: ( x^2 - 25 ) Simplify and express the result in positive exponents: ( 3x^{-2} \cdot (2x^5) ) Answer: ( 3 \cdot 2x^{-2+5} = 6x^3 ) Factorise completely: ( 36x^2 - 49 ) Answer: ( (6x + 7)(6x - 7) ) Please make sure the questions match the goals of your specific assessment and the abilities of your students【11†source】.
It said 11+ sources
q
Your OpenAI API key (and others) are stored to that chatbot file you shared.
Yes, let me try change the code to fix that.
j
Nobody has that template only you 🙂
q
I changed this code a little bit in Handle Response workflow
Copy code
js
const response = await bot.retryingAxiosRequest({
  method: 'get',
  maxBodyLength: Infinity,
  url: `https://api.openai.com/v1/threads/${workflow.threadId}/messages`,
  headers: {
    'OpenAI-Beta': 'assistants=v1',
    Authorization: `Bearer ${env.openAIToken}`,
    'Content-Type': 'application/json'
  }
})
console.log('message', JSON.stringify(response.data))

// CHANGED AFTER THIS
const removeSources = response.data.data[0].content[0].text.value
const regexBrackets = /【.?】/g;
workflow.response = removeSources.replace(regexBrackets, "");
Now it removed the '23+ source' in the end https://cdn.discordapp.com/attachments/1192699975990259822/1225699365423943720/image.png?ex=6622147d&is=660f9f7d&hm=014de61a3dab5b40d94a7cc29ceea3e38f8affae3f986569c17f1d1225b08814&
compared to the earlier picture where it had that error
Try if that works, for my Assistants API projects, those instructions here all work.
I send it to you. There is the changed code in right place, otherwise it's exactly the same bot.
Did that solve the 'sources' issue for you? We need to fix this completely so it works for everyone else as well ⚡ 🛠️
The important part was to change this
Copy code
js
workflow.response = response.data.data[0].content[0].text.value
to this
Copy code
js
const removeSources = response.data.data[0].content[0].text.value
const regexBrackets = /【.?】/g;
workflow.response = removeSources.replace(regexBrackets, "");
b
@quick-musician-29561 @able-rocket-15603 Guys, do you have a template for the V2 of assistants API???
23 Views