I’m just trying to learn Llama AI API and I’m trying to get it to respond to the question “What are common questions to ask on an NDA”. but I’m unable to get an response. The content field in the response json is always NULL. any help would be appreciated!
I tried the example given on their website but also was not able to get a response. I’m using JavaScript to do this.
const apiRequestJson = {
"messages": [
{ "role": "user", "content": "What are the common questions to ask to create an NDA for a food industry for an employee?" }
],
"functions": [
{
"name": "get_nda_questions",
"description": "Get the frequently asked questions to generate an NDA contract",
"parameters": {
"type": "object",
"properties": {
"Industry": {
"type": "string",
"description": "The industry to generate this contract in"
},
"BusinessType": {
"type": "string",
"description": "NDA for a business or individual"
}
}
},
"required": ["Industry", "BusinessType"]
}
],
"stream": false,
"function_call": "get_nda_questions"
};
app.get('/contract', async (req, res) => {
try {
const { default: LlamaAI } = await import('llamaai');
const llamaAPI = new LlamaAI(apiToken);
// Run the first API request
const response = await llamaAPI.run(apiRequestJson);
const output = response['choices'][0]['message'];
// Parse the function call arguments
const funcArguments = output['function_call']['arguments'];
// Create flight_info object
const flight_info = {
"Industry": funcArguments.Industry,
"BusinessType": funcArguments.BusinessType
};
// Convert flight_info to a JSON string
const stringInfo = JSON.stringify(flight_info);
// Prepare the second API request JSON
const second_api_request_json = {
"model": "llama-70b-chat",
"messages": [
{"role": "user", "content": "What are the common questions to ask to create an NDA for a food industry for an employee?"},
{"role": "function", "name": output['function_call']['name'], "content": stringInfo}
],
"functions": [
{
"name": "get_nda_questions",
"description": "Get the frequently asked questions to generate an NDA contract",
"parameters": {
"type": "object",
"properties": {
"Industry": {
"type": "string",
"description": "The industry to generate this contract in"
},
"BusinessType": {
"type": "string",
"description": "NDA for a business or individual"
}
}
},
"required": ["Industry", "BusinessType"]
}
]
};
const second_response = await llamaAPI.run(second_api_request_json);
const second_output = second_response['choices'][0]['message']['content']; //This returns null for some reason
res.send(second_response)
} catch (error) {
res.status(500).json({ error: error.message });
}
});