Walkthrough - Using Groq LLM API for free (for scripts or in ComfyUI)
세부 정보
파일 다운로드
모델 설명
이 기사에서는 Groq LLM API에 무료로 접근하고 사용하는 방법, 그리고 이를 ComfyUI 내에서 사용하는 방법을 간략히 정리했습니다.
기사 버전은 여기에서 확인하실 수 있습니다.
다운로드할 필요가 없습니다. 이는 모델이 아니라 아래 텍스트를 텍스트 형식으로 제공한 것이며, 기사로의 링크만 포함합니다.
계정 생성
여기에서 Groq 계정을 생성하세요. 이 모든 과정은 무료이며, 분당, 일당 사용 가능 횟수와 사용할 수 있는 토큰 수에 일부 요청 제한이 적용됩니다. 현재 제한은 매우 넉넉합니다.
글을 작성한 시점(2024-04-19) 기준 요청 제한은 다음과 같습니다:
API 키 생성
GroqCloud Playground로 이동하여 왼쪽 메뉴에서 API 키 섹션을 찾으세요.

다음으로 표시되는 대화 창에서 API 키를 복사하세요. 이 코드는 이때만 볼 수 있으므로, 나중에 이 키를 다시 사용하려면 백업을 만들어 두세요.
새 키를 생성하고 그 키로 전환할 수 있으므로, 사실상 어떤 키를 사용하든 큰 차이가 없습니다.
온라인에서 API 테스트
GroqCloud Playground로 이동하여 왼쪽 필드에 시스템 메시지를 입력하세요. 이제 사용자 정의 챗 모델을 테스트할 준비가 되었습니다.
User 필드에 채팅 메시지를 입력하고 CTRL + ENTER를 눌러 메시지를 전송하세요.

Python 코드 가져오기
Playground 페이지 하단에 "View code" 버튼이 있습니다. 이 버튼은 귀하의 쿼리와 지시사항을 백그라운드에서 실행하는 Python 스크립트를 보여줍니다.
다음과 같은 창이 나타납니다:
from groq import Groq
client = Groq()
completion = client.chat.completions.create(
model="mixtral-8x7b-32768",
messages=[
{
"role": "system",
"content": "You are an expert python programmer and your mission is to help the user with their programming troubles."
},
{
"role": "user",
"content": "I need help to write a script. Please write a hello world script for me."
},
{
"role": "assistant",
"content": "Sure, I'd be happy to help you write a \"Hello, World\" script in Python! Here's an example:\n```python\nprint(\"Hello, World!\")\n```\nWhen you run this script, it will display the message \"Hello, World!\" in the console. Let me know if you have any questions or if there's anything else I can help you with!"
}
],
temperature=1,
max_tokens=1024,
top_p=1,
stream=True,
stop=None,
)
for chunk in completion:
print(chunk.choices[0].delta.content or "", end="")
응답을 제거하면, Python을 사용해 로컬에서 API에 쿼리를 보낼 수 있는 유효한 코드 조각이 됩니다. 제거한 후 코드는 다음과 같습니다:
from groq import Groq
client = Groq()
completion = client.chat.completions.create(
model="mixtral-8x7b-32768",
messages=[
{
"role": "system",
"content": "You are an expert python programmer and your mission is to help the user with their programming troubles."
},
{
"role": "user",
"content": "I need help to write a script. Please write a hello world script for me."
}
],
temperature=1,
max_tokens=1024,
top_p=1,
stream=True,
stop=None,
)
for chunk in completion:
print(chunk.choices[0].delta.content or "", end="")
API 키를 스크립트에 추가하기
이제 해야 할 유일한 작업은 스크립트에 API 키를 추가하는 것입니다. client = Groq() 라인에 다음을 추가하세요.
client = Groq(api_key="gsk_xxxxxxxxxxxxxxxxxxxxxxxxxx")
이제 이 스크립트를 Python에서 실행하면 작동합니다.
먼저 groq 라이브러리를 설치해야 합니다. pip install groq 명령을 실행하면 됩니다. 이상적으로는 이 모든 작업을 수행하기 전 별도의 환경을 생성했어야 하지만, 이는 별도의 주제입니다. 제가 만든 가상 환경 생성 도구는 여기에서 확인할 수 있습니다. 또는 온라인에서 Python 가상 환경 설정 방법을 찾아보세요.
추가 참고: 이와 같이 코드에 API 키를 하드코딩하는 것은 권장되지 않습니다. 시스템의 환경 변수에 저장하거나, 예를 들어 configparser 라이브러리를 사용하여 .ini 파일로 관리하는 것이 더 좋습니다. 이 부분에 대해 ChatGPT가 도와줄 수 있습니다.
ComfyUI에서 Groq 사용하기
위 방법을 사용하여 ComfyUI에서 사용할 수 있는 노드를 만들었습니다. 이 노드는 제 GitHub 노드 패키지에 있습니다: https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes?tab=readme-ov-file#-groq-llm-api-node.
ComfyUI Manager를 통해 노드 패키지를 설치하거나, 저장소를 수동으로 /ComfyUI/custom_nodes/ 디렉터리에 클론하세요.
설치 후, 구성 파일(ComfyUI\custom_nodes\ComfyUI-mnemic-nodes\nodes\groq)에 API 키를 입력하면 준비가 완료됩니다! ComfyUI를 재시작하고 Groq LLM API 노드를 찾아 워크플로우에 추가하세요.
추가 정보는 GitHub 페이지에서 확인할 수 있습니다.
ComfyUI Groq LLM API 스크린샷
아래는 이 노드가 수행할 수 있는 작업을 보여주는 몇 가지 스크린샷입니다.






아래에 질문을 자유롭게 남겨주세요.
