Skip to content

Commit

Permalink
Function
Browse files Browse the repository at this point in the history
  • Loading branch information
redji committed Apr 2, 2024
1 parent c509e1c commit 7a2eec0
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ let liarAnswer = [];
let inpromptAnswer = [];
let embeddingAnswer = [];
let whisperAnswer = [];
//helloApi
let functionAnswer = [];
// //helloApi
fetch('https://tasks.aidevs.pl/token/helloapi', {
method: 'POST',
headers: {
Expand Down Expand Up @@ -300,4 +301,65 @@ fetch('https://tasks.aidevs.pl/token/whisper', {
console.error('Error transcribing audio file:', error);
});
})
.catch(error => console.error('Error:', error));
.catch(error => console.error('Error:', error));
//function
fetch('https://tasks.aidevs.pl/token/functions', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ apikey: APIKey })
})
.then(async (response) => {
const data = await response.json();
const token = data.token;
const taskUrl = `https://tasks.aidevs.pl/task/${token}`;
const response2 = await makeRequestWithDelay(taskUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
}, 10);
console.log(response2.msg + response2.hint1)
const responseFromChat = await chatCompletion({
messages: [{
role: 'system', content: `
Return everything in JSON format.
Follow answer format:
{
"name": "[function name]"
"description": "[function description]"
"parameters": {
type: "object"
properties: {
property name: {
"type": "parameter type",
"description": "parameter description",
}
}
}
}
Don't wrap result in answer object
`
}, { role: 'user',
content: response2.msg + response2.hint1 }],
model: 'gpt-3.5-turbo-0125',
response_format: {
type: "json_object"
}
});
const functionAnswer = responseFromChat.choices[0].message.content;
console.log(functionAnswer);

const response4 = await makeRequestWithDelay(`https://tasks.aidevs.pl/answer/${token}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({answer: JSON.parse(functionAnswer)})
}, 10);
console.log('Answer from API', response4);
})
.catch(error => console.error('Error:', error));


0 comments on commit 7a2eec0

Please sign in to comment.