Groq AI Integration
Intelligent chat assistant configuration and fallback logic
Groq AI Integration
BabyShopHub features an in-app AI assistant powered by Groq's high-speed inference API. It helps users find products, answers parenting FAQs, and guides them through the shop.
Configuration
The AI logic is encapsulated in the GroqService.
- API Key: Obtain an API key from the Groq console.
- Environment Variable: Store the key securely. Never hardcode it into public repositories.
Implementation Details
We use the standard HTTP REST approach to communicate with the Groq API, typically utilizing the llama3-8b-8192 or mixtral-8x7b-32768 models.
Context Injection
To make the AI aware of the store's current inventory, we can inject a summary of the ShopProvider's product list into the system prompt before sending the request.
Error Handling & Fallbacks
If the Groq API is down or rate-limited:
- The
GroqServicecatches the exception. - It returns a hardcoded fallback message:
"I'm currently taking a little nap. Please try asking me again later!" - This ensures the user experience isn't broken by a third-party outage.