Views
No views yet
npm i @huggingface/transformers1import { pipeline } from "@huggingface/transformers";
2
3// Create a text generation pipeline
4const generator = await pipeline(
5 "text-generation",
6 "onnx-community/TinySwallow-1.5B-Instruct-ONNX",
7 { dtype: "q4" },
8);
9
10// Define the list of messages
11const messages = [
12 { role: "system", content: "You are a helpful assistant." },
13 { role: "user", content: "Solve the equation: x^2 + 2x - 3 = 0" },
14];
15
16// Generate a response
17const output = await generator(messages, { max_new_tokens: 256, do_sample: false });
18console.log(output[0].generated_text.at(-1).content);Here's how to solve the quadratic equation \(x^2 + 2x - 3 = 0\):
**Step 1:** Recognize that this is a quadratic equation in standard form, \(ax^2 + bx + c = 0\), where \(a=1\), \(b=2\), and \(c=-3\).
**Step 2:** We can factor the left side of the equation:
\[x^2 + 2x - 3 = (x + 3)(x - 1) = 0.\]
**Step 3:** Now we have two possible solutions from factoring:
- \(x + 3 = 0\) or \(x - 1 = 0\)
**Step 4:** Solve each equation for \(x\):
- \(x + 3 = 0 \Rightarrow x = -3\)
- \(x - 1 = 0 \Rightarrow x = 1\)
Therefore, the solutions to the equation \(x^2 + 2x - 3 = 0\) are \(x = -3\) and \(x = 1\).onnx).