Spaces:
Configuration error
Configuration error
Download src/services/tarsAPI.js from CPISTO/TARSTHENEXT: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/CPISTO/TARSTHENEXT/resolve/main/src/services/tarsAPI.js
- Command line
-
hf download hf://spaces/CPISTO/TARSTHENEXT/src/services/tarsAPI.js
-
curl -L -o tarsAPI.js https://huggingface.co/spaces/CPISTO/TARSTHENEXT/resolve/main/src/services/tarsAPI.js
1.32 kB
| 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' | |
| } | |
| } | |