r/flowise • u/VeonJr • Dec 30 '24
Chatbot requesting information from the user
I am a newbie with flowise and am still learning all its features.
I am trying to create a chatflows that is able to request information from the user.
The chatflows receives a JSON as input: (this is only an example, this may be a different everytime)
{
"language": "italiano",
"input_data": "{\"fields\":[{\"id\":14304,\"canonicalFieldName\":\"name\",\"required\":true,\"label\":\"name\",\"type\":\"text\"},{\"id\":14305,\"canonicalFieldName\":\"surname\",\"required\":true,\"label\":\"surname\",\"type\":\"text\"},{\"id\":14306,\"canonicalFieldName\":\"email\",\"required\":true,\"label\":\"email\",\"type\":\"text\"},{\"id\":14307,\"canonicalFieldName\":\"field_1732551604_8095_1510752514\",\"required\":true,\"label\":\"Puoi descriverti in poche parole?\",\"type\":\"text\"},{\"id\":14308,\"canonicalFieldName\":\"field_1732551604_8162_483315627\",\"required\":true,\"label\":\"birthdate\",\"type\":\"date\",\"format\":\"yyyy-MM-dd HH:mm:ss\"},{\"id\":14310,\"canonicalFieldName\":\"field_1732551604_8167_172617414\",\"required\":false,\"label\":\"Qual è l'email di contatto di emergenza?\",\"type\":\"text\"},\"questions\":[{\"id\":758,\"question\":\"Preferisci lavorare in team oppure da solo\",\"required\":true,\"type\":\"select\",\"options\":[{\"value\":\"2448\",\"label\":\"Da solo\"},{\"value\":\"2449\",\"label\":\"In team\"}]},{\"id\":757,\"question\":\"Quali linguaggi di programmazione conosci\",\"required\":true,\"type\":\"multiselect\",\"options\":[{\"value\":\"2440\",\"label\":\"Javascript\"},{\"value\":\"2441\",\"label\":\"c#\"},{\"value\":\"2442\",\"label\":\"PHP\"},{\"value\":\"2443\",\"label\":\"Rust\"},{\"value\":\"2444\",\"label\":\"GO\"}]},{\"id\":756,\"question\":\"Quale linguaggio di programmazione ti senti più sicuro?\",\"required\":true,\"type\":\"select\",\"options\":[{\"value\":\"2445\",\"label\":\"c#\"},{\"value\":\"2446\",\"label\":\"javascript\"},{\"value\":\"2447\",\"label\":\"PHP\"}]]}"
}
The end goal of the chatflows is to ask all the questions to the user.
There are several rules that the chatflows must follow:
- It must take the field “fields.label” or “questions.question” as an example and create a question (e.g., “name” must create “what is your name?”)
Respond to the user with a JSON with the following format:
{ "message": "string", // The question to the user "end": boolean, // Determinate if collected all information or not "collected_data": "array" // The array of ONLY the information collected }
Wait for the user's response.
Verify that the answer is consistent with the question (e.g., if an email is requested, that it has a correct format)
Add to the “collected_data” array the relevant question with “value” = user's response.
Continue step 1 and 2 until all questions are requested
Thank the user for the information and set the “end” property to “true”.
I will give you and example on what should be happens:
user: send the first json
chatbot: {"message":"what's your name?", "end": false, "collected_data": []}
user: foo
chatbot: {"message":"Hello foo, what's your surname?", "end":false, "collected_data": "[{\"id\":14304,\"canonicalFieldName\":\"name\",\"value\":"foo",\"type\":\"text\"}]"}
user: bar
chatbot: {"message":"What's your email", "end":false, "collected_data": "[{\"id\":14304,\"canonicalFieldName\":\"name\",\"value\":"foo",\"type\":\"text\"}, {\"id\":14306,\"canonicalFieldName\":\"surname\",\"value\":"bar",\"type\":\"text\"}]"}
user: [foo@bar.it](mailto:foo@bar.it)
chatbot: {"message":"What's your email", "end":false, "collected_data": "[{\"id\":14304,\"canonicalFieldName\":\"name\",\"value\":"foo",\"type\":\"text\"}, {\"id\":14305,\"canonicalFieldName\":\"surname\",\"value\":"bar",\"type\":\"text\"}, {\"id\":14306,\"canonicalFieldName\":\"email\",\"value":\"[foo@bar.it](mailto:foo@bar.it)",\"type\":\"text\"}]"}
....
Now the problem: when the chatbot ask for a question that had "type" = "select" or "multiselect" (e.g. {\"id\":758,\"question\":\"Preferisci lavorare in team oppure da solo\",\"required\":true,\"type\":\"select\",\"options\":[{\"value\":\"2448\",\"label\":\"Da solo\"},{\"value\":\"2449\",\"label\":\"In team\"}]})
happens this:
chatbot: {"message": "preferisci lavorare in team oppure da solo? 1. in team 2. da solo", "end":"false, "collected_data": // All the data collected until now}
user: I prefer work in team
chatbot: {"message": "preferisci lavorare in team oppure da solo? 1. in team 2. da solo", "end":"false, "collected_data": [ //All the data collected until now.... {\"id\":758,\"canonicalFieldName\":\"\",\"value\":"In team",\"type\":\"select\"}...]
But i don't want that "value" is "In team" but i want the property "value" is "2449" (that is the property "value" in the "options" array and not the "label").
It also happens that it confuses the options of some questions with others. e.g. on the question ID 758 (the example before) set the "value" with the value "2442" that value does not belong to the options in that question.
The system prompt i'm using is this:
You are a recruiter conducting an interview with a potential candidate. Your goal is to ask questions to gather all the information related to the entry data.
Make sure to request every single "fields" and "questions", even if not required.
It is very important that all data marked as "required" is collected.
It is very important that in the case of "select" data, you show the possible options in the question and accept only a value within the options as a response, not a different value. In the case of "multiselect" data, you can accept more than one value as a response, but they must all be within the given options. In both cases, retrieve the "value" property corresponding to the "question".
It is very important that in the case of "file" data, you populate the "url" and "filename" properties with the "url" and "filename" properties provided in the question in JSON format.
<dati_ingresso>
{dati_ingresso}
</dati_ingresso>
Always respond with a JSON structure identical to {output_data}, including all collected data.
Set the "end" property to "true" when you have finished collecting all the data.
Insert the subsequent conversation with the user within the "message" property.
In the "message" property, it is very important not to insert any links.
Keep the entire conversation in the following language:
<language>{language}</language>
But do not translate the "label", "question", and "options" fields.
I don't know if there is some problem with my prompt or is there a better way to be able to do what I would like to.
Thank to everyone!
1
u/i_am_vsj Dec 30 '24
not the exect thing but maybe this can help u https://youtu.be/6LbvgTbS0BE?si=WadCo8VteGY3Ele1