Spaces:
Sleeping
Sleeping
File size: 1,066 Bytes
90b3952 | 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";
import dotenv from "dotenv";
// Load environment variables
dotenv.config();
console.log(process.env.HUGGING_FACE_API_KEY); // Verify if the key loads correctly
const testMistralAPI = async () => {
try {
const inputText = "I feel like today has been a rollercoaster of emotions.";
// Mistral-7B API endpoint
const apiUrl =
"https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3";
// Make the API request
const response = await axios.post(
apiUrl,
{
inputs: `Analyze the following text and summarize its emotional tone: "${inputText}"`,
},
{
headers: {
Authorization: `Bearer ${process.env.HUGGING_FACE_API_KEY}`,
"Content-Type": "application/json",
},
}
);
// Log the response from the API
console.log("Mistral API Response:", response.data);
} catch (error) {
console.error(
"Error testing Mistral API:",
error.response?.data || error.message
);
}
};
testMistralAPI();
|