Hire 
Daniel D'Souza
Submit
Note: Voiceflow is not responsible for the exchange of services between you and the partner.
Thank you! An email will be sent connecting you with the expert.
Oops! Something went wrong while submitting the form.

Send a Query to Mistral 7xB (via. together.ai)

Template
Function
2
Template
Function
by
Daniel D'Souza

Use Voiceflows Knowledge Base with Mistral 7xB as your AI model. This function works with the chunk extraction function to send a question and relevant chunks to Mistral 7xB (via. together.ai).

Created:

Heading

Voiceflow APIs used:

Channels
No items found.
Created By
Daniel D'Souza
This is some text inside of a div block.

Function Code Snippet


export default async function main(args) {
// Extract the API key and Question from inputVars
const {question, MistralApiKey, chunks} = args.inputVars;

//Define the API data
const url = 'https://api.together.xyz/v1/chat/completions';
const data = {
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
max_tokens: 1024,
messages: [
{
role: 'system',
content: 'Answer the question using only the information provided'
},
{
role: 'user',
content: `Question: ${question} ### Information: ${chunks}`
}
]
};

// Wrap the API call in a try block so it can detect errors
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${MistralApiKey}`,
'OpenAI-Beta': 'assistants=v1'
},
body: JSON.stringify(data)
});

// Check if the response status is OK (status in the range 200-299)
if (!response.ok) {

// If not OK, throw an error to be caught by the catch block
throw new Error(`HTTP error! status: ${response.status}`);
}

// Await the response and save it to the responseBody variable
let responseBody = await response.json;

// Access the answer from the responseBody
const answer = responseBody.choices[0].message.content;


// Return the desired output structure
return {
outputVars: {
answer: answer
},
next: {
path: 'success'
},
trace: [
{
type: 'debug',
payload: {
message: `Information recieved: ${answer}`
}
}
],
};
} catch (error) {
// Catch block handles any errors thrown in the try block
return {
outputVars: {
error: `An error occurred: ${error.message}`
},
next: {
path: 'error'
},
trace: [
{
type: 'text',
payload: {
message: `An error occurred: ${error.message} body is ${responseBody}`
}
}
],
};
}
}
copy-icon

Explore More Templates

Build and submit a Template to have it featured in the community.

ghraphic
No items found.
No items found.