Spaces:
Runtime error
Runtime error
Download server/services/testMistralHuggingFaceAPI.js from lemachinarbo/lucas: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/lemachinarbo/lucas/resolve/main/server/services/testMistralHuggingFaceAPI.js
- Command line
-
hf download hf://spaces/lemachinarbo/lucas/server/services/testMistralHuggingFaceAPI.js
-
curl -L -o testMistralHuggingFaceAPI.js https://huggingface.co/spaces/lemachinarbo/lucas/resolve/main/server/services/testMistralHuggingFaceAPI.js
1.07 kB
| 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(); | |