Skip to content

Commit cf7fe66

Browse files
Adding Groq inference support (#536) (#542)
* Adding Groq inference support (#536) * Adding Groq inference support * Add Groq model Llama 3.3 70B Versatile * Add Groq Llama 3.3 70B SpecdDec model and form filling example - Added new Groq model "groq-llama-3.3-70b-specdec" to supported models - Created a new example script for form filling with sensible data using Groq - Updated model type definitions and provider mappings * Remove Groq form filling example script * Add Groq model type to LLMClient * Add Groq client to LLMProvider * changeset --------- Co-authored-by: Sankalp Gunturi <[email protected]>
1 parent fc5e8b6 commit cf7fe66

File tree

7 files changed

+447
-3
lines changed

7 files changed

+447
-3
lines changed

Diff for: .changeset/shiny-otters-think.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": minor
3+
---
4+
5+
You can now run Groq LLMs! "groq-llama-3.3-70b-versatile" and "groq-llama-3.3-70b-specdec" are now valid AvailableModel names

Diff for: .env.example

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
OPENAI_API_KEY=""
22
CEREBRAS_API_KEY=""
3+
GROQ_API_KEY=""
34
BROWSERBASE_API_KEY=""
45
BRAINTRUST_API_KEY=""
56
ANTHROPIC_API_KEY=""

Diff for: examples/form_filling_sensible_groq.ts

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { Stagehand } from "@/dist";
2+
import { GroqClient } from "@/lib/llm/GroqClient";
3+
import StagehandConfig from "@/stagehand.config";
4+
import chalk from "chalk";
5+
6+
async function formFillingSensible() {
7+
const stagehand = new Stagehand({
8+
...StagehandConfig,
9+
env: "LOCAL",
10+
llmClient: new GroqClient({
11+
modelName: "groq-llama-3.3-70b-versatile",
12+
clientOptions: {
13+
apiKey: process.env.GROQ_API_KEY,
14+
},
15+
logger: console.log,
16+
}),
17+
});
18+
await stagehand.init();
19+
20+
// Block manifest worker to prevent PWA installation popup.
21+
// This is necessary because the website prompts the user to install the PWA and prevents form filling.
22+
await stagehand.page.route("**/manifest.json", (route) => route.abort());
23+
24+
// Go to the website and wait for it to load
25+
await stagehand.page.goto("https://file.1040.com/estimate/", {
26+
waitUntil: "networkidle",
27+
timeout: 30000,
28+
});
29+
30+
// Observe the form fields with suggested actions
31+
const observed = await stagehand.page.observe({
32+
instruction:
33+
"fill all the form fields in the page with mock data. In the description inlcude the field name",
34+
returnAction: true,
35+
});
36+
37+
// Uncomment the following snippet to see the stagehand candidate suggestions (initial)
38+
console.log(
39+
`${chalk.green("Observe:")} Form fields found:\n${observed
40+
.map((r) => `${chalk.yellow(r.description)} -> ${chalk.gray(r.selector)}`)
41+
.join("\n")}`,
42+
);
43+
44+
// Create a mapping of 1+ keywords in the form fields to standardize field names
45+
const mapping = (description: string): string | null => {
46+
const keywords: { [key: string]: string[] } = {
47+
age: ["old"],
48+
dependentsUnder17: ["under age 17", "child", "minor"],
49+
dependents17to23: ["17-23", "school", "student"],
50+
wages: ["wages", "W-2 Box 1"],
51+
federalTax: ["federal tax", "Box 2"],
52+
stateTax: ["state tax", "Box 17"],
53+
};
54+
55+
for (const [key, terms] of Object.entries(keywords)) {
56+
if (terms.some((term) => description.toLowerCase().includes(term))) {
57+
return key;
58+
}
59+
}
60+
return null;
61+
};
62+
63+
// Fill the form fields with sensible data. This data will only be used in your session and not be shared with LLM providers/external APIs.
64+
const userInputs: { [key: string]: string } = {
65+
age: "26",
66+
dependentsUnder17: "1",
67+
wages: "54321",
68+
federalTax: "8345",
69+
stateTax: "2222",
70+
};
71+
72+
const updatedFields = observed.map((candidate) => {
73+
const key = mapping(candidate.description);
74+
if (key && userInputs[key]) {
75+
candidate.arguments = [userInputs[key]];
76+
}
77+
return candidate;
78+
});
79+
// List of sensible-data candidates
80+
console.log(
81+
`\n${chalk.green("Sensible Data form inputs:")} Form fields to be filled:\n${updatedFields
82+
.map(
83+
(r) =>
84+
`${chalk.yellow(r.description)} -> ${chalk.blue(r.arguments?.[0] || "no value")}`,
85+
)
86+
.join("\n")}`,
87+
);
88+
89+
// Fill all the form fields with the sensible candidates
90+
for (const candidate of updatedFields) {
91+
await stagehand.page.act(candidate);
92+
}
93+
}
94+
95+
(async () => {
96+
await formFillingSensible();
97+
})();

0 commit comments

Comments
 (0)