Skip to content

Commit

Permalink
AI funcionando
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovannaNaves committed Oct 15, 2024
1 parent ce3e504 commit 894d68d
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 29 deletions.
133 changes: 133 additions & 0 deletions db.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,139 @@
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "8f25",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "41a6",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "ae10",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "1808",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "2f02",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "69ce",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "059b",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "97ec",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "c51f",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "4c4a",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "655b",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "dffe",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "355e",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "4836",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "b239",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "9e3b",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "3ea7",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "5634",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
},
{
"id": "75c6",
"titulo": "",
"conteudo": "",
"imagem": "",
"categorias": []
}
],
"mensagens": [
Expand Down
50 changes: 23 additions & 27 deletions docs/pages/js/custom.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
const form = document.getElementById('topicForm');
const { OpenAI } = require('openai');

const api = new OpenAI({
baseURL: 'https://api.aimlapi.com',
//apiKey:
});

if (form) {
form.addEventListener("submit", async (e) => {
e.preventDefault();

form.addEventListener("submit", async (e) => {

e.preventDefault();

const result = await api.chat.completions.create({
model: 'meta-llama/Meta-Llama-3-70B-Instruct-Lite',
messages: [
{
role: 'system',
content: 'Você deve responder com um passo a passo em tópicos.',
},
{
role: 'user',
content: 'Como salvo um contato no celular?'
}
],
});

const message = result.choices[0].message.content;
console.log(`Assistant: ${message}`);
const response = await fetch('https://api.aimlapi.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer bdda4200a7c948328cb8b3f6c800e27e`, // Use sua chave API aqui
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'user',
content: 'Como salvo um contato no celular?'
}
]
})
});
}

const result = await response.json();
const message = result.choices[0].message.content;
console.log(`Assistant: ${message}`);
});
}
Loading

0 comments on commit 894d68d

Please sign in to comment.