generated from webtech-network/ti1-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce3e504
commit 894d68d
Showing
4 changed files
with
363 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); | ||
} |
Oops, something went wrong.