What You’ll Learn
- Sending prompts to Groq’s OpenAI-compatible API (
llama-3.1-8b-instant) for ultra-fast code generation - Stripping markdown code fences from LLM responses before execution
- Writing generated code into a Declaw sandbox filesystem
- Executing the code securely with
sbx.commands.run() - Graceful demo mode when no API key is configured
Prerequisites
- Declaw instance running and
DECLAW_API_KEY/DECLAW_DOMAINset GROQ_API_KEY(optional — the example runs in demo mode without it)
Code Walkthrough
This example is available in Python. TypeScript support coming soon.
1. Ask Groq to generate Python code
The Groq SDK follows the OpenAI client interface exactly — swap inGroq() and choose a model:
Groq’s hosted inference is significantly faster than most cloud LLM providers.
llama-3.1-8b-instant typically responds in under 200 ms, making it a good choice for high-throughput code-generation pipelines.