scrimba
Mistral AI
Mistral's models
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Mistral's models
Expand for more info
index.js
run
preview
console
import MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;
const client = new MistralClient(apiKey);

const prompt1 = `
Classify the following email to determine if it is spam or not. Only respond with the exact words "Spam" or "Not spam".

🎉 Urgent! You've Won a $1,000,000 Cash Prize! 💰 To claim your prize, please click on the link below: https://bit.ly/claim-your-prize
`

const prompt2 = `
Compose a welcome email for new customers who have just made their first purchase with your product.
Start by expressing your gratitude for their business, and then convey your excitement for having them as a customer.
Include relevant details about their recent order. Sign the email with "The Fun Shop Team".

Order details:
- Customer name: Anna
- Product: hat
- Estimate date of delivery: Feb. 25, 2024
- Return policy: 30 days
`

const prompt3 = `Calculate the difference in payment dates between the two customers whose payment amounts are closest to each other in the given dataset:

'{
"transaction_id":{"0":"T1001","1":"T1002","2":"T1003","3":"T1004","4":"T1005"},
"customer_id":{"0":"C001","1":"C002","2":"C003","3":"C002","4":"C001"},
"payment_amount":{"0":125.5,"1":89.99,"2":120.0,"3":54.3,"4":210.2},
"payment_date":{"0":"2021-10-05","1":"2021-10-06","2":"2021-10-07","3":"2021-10-05","4":"2021-10-08"},
"payment_status":{"0":"Paid","1":"Unpaid","2":"Paid","3":"Paid","4":"Pending"}
}'`

// Testing models
const chatResponse = await client.chat({
model: 'mistral-medium-latest',
messages: [
{role: 'system', content: 'You are a helpful assistant. Be short and succinct.'},
{role: 'user', content: prompt1}
]
});

console.log(chatResponse.choices[0].message.content);
Console
"First, find the two payments with the closest amounts: Payment 1 (T1002) = 89.99 Payment 3 (T1004) = 54.3 Difference = 35.69 Next, calculate the difference in payment dates: Payment 1's date = 2021-10-06 Payment 3's date = 2021-10-05 Difference = 1 day"
,
/index.html
-4:31