Spaces:
Configuration error
Configuration error
File size: 1,324 Bytes
3dee94a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import axios from 'axios'
const BASE_URL = 'https://gwvq4e5wn6lu2fdsuahlsm3l.agents.do-ai.run/api/v1/chat/completions'
const TOKEN = 'djw6eleVgign22llV6f02WjOYrHNLvDZ'
let messageHistory = [] // Simples controle em memória (será armazenado também em arquivo backend)
export async function sendToTARS(userInput) {
try {
// Adiciona a mensagem do usuário
messageHistory.push({ role: 'user', content: userInput })
const payload = {
messages: messageHistory,
temperature: 0.7,
top_p: 1,
max_tokens: 512,
retrieval_method: 'rewrite',
stream: false,
provide_citations: true
}
const response = await axios.post(BASE_URL, payload, {
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
}
})
// A resposta pode estar em response.data.choices[0].message.content
const assistantReply = response?.data?.choices?.[0]?.message?.content || 'Erro ao processar resposta'
// Armazena também a resposta no histórico
messageHistory.push({ role: 'assistant', content: assistantReply })
return assistantReply
} catch (err) {
console.error('Erro ao se comunicar com a IA da DigitalOcean:', err)
return 'Erro ao conectar com a TARS'
}
}
|