Skip to content

fix: replace anthropic SDK with openai SDK for Groq API#2

Merged
HackMyTask merged 5 commits into
mainfrom
fix/groq-openai-sdk
May 14, 2026
Merged

fix: replace anthropic SDK with openai SDK for Groq API#2
HackMyTask merged 5 commits into
mainfrom
fix/groq-openai-sdk

Conversation

@kiro-agent
Copy link
Copy Markdown

@kiro-agent kiro-agent Bot commented May 14, 2026

This pull request was generated by @kiro-agent 👻

Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro autonomous agent


Summary

Bug kritis #1api_client.py menggunakan Anthropic SDK untuk memanggil Groq API, padahal Groq menggunakan format OpenAI-compatible API.

Changes

  • scripts/api_client.py:

    • Ganti import anthropicfrom openai import OpenAI
    • Method _try_groq_generation sekarang menggunakan client.chat.completions.create()
    • Response parsing: response.choices[0].message.content
    • Token counting: completion_tokens + prompt_tokens
  • requirements.txt (NEW):

    • openai>=1.0.0
    • google-generativeai>=0.3.0
    • requests>=2.28.0
  • .github/workflows/generate-content.yml:

    • pip install requestspip install -r requirements.txt

Why This Was Broken

Groq API is OpenAI-compatible (/v1/chat/completions). The Anthropic SDK uses a different message format (/v1/messages) that does not work with Groq's endpoint. This caused a runtime error every time content generation was triggered.

- Groq uses OpenAI-compatible API, not Anthropic SDK
- Changed import from 'anthropic' to 'openai' (OpenAI class)
- Updated _try_groq_generation to use chat.completions.create()
- Response parsing now uses choices[0].message.content format
- Token counting uses completion_tokens + prompt_tokens
- Added requirements.txt with correct dependencies
- Updated CI workflow to use pip install -r requirements.txt

Co-authored-by: HackMyTask <271546871+HackMyTask@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 14, 2026

Deploying agc-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: e1f84b1
Status: ✅  Deploy successful!
Preview URL: https://2e46898f.agc-website.pages.dev
Branch Preview URL: https://fix-groq-openai-sdk.agc-website.pages.dev

View logs

- All scripts now write/read from src/content/glossary/ (was content/glossary/)
- Migrated [slug].astro from manual import.meta.glob + string parsing
  to proper Astro Content Collections with getCollection() + render()
- Added src/content.config.ts with Zod schema validation for frontmatter
- Created src/content/glossary/.gitkeep placeholder directory
- Updated maintenance.yml paths to match
- Keywords and related_terms now properly parsed as arrays
- Added 'import random' module
- Added random_pick parameter to generate_batch()
- When --random is used, pending list is shuffled before slicing
- Without --random, behavior stays sequential (no change)
- Fix CI loop: added paths-ignore for generated content dirs
- Fix site URL: use env var SITE_URL with fallback to pages.dev
- Fix font loading: replace render-blocking @import with link preconnect
- Fix canonical URL: use Astro.site instead of hardcoded domain
- Fix homepage: use getCollection(), render gracefully with 0 articles
- Fix .gitignore: remove stale content/glossary pattern
- Build verified: npm run build passes with 3 pages
- Always rotate after failure (fixes stuck-on-last-key bug)
- Next term now starts from next key, not the same exhausted one
- Added _is_rate_limit_error() with comprehensive detection:
  rate_limit, 429, too many requests, tokens/requests per minute/day
- Removed broken fallback that would send full comma-string as key
- Better logging: shows attempt count and retry context
@HackMyTask HackMyTask merged commit 45f9265 into main May 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants