Spaces:
Sleeping
Sleeping
Download examples/groq_basics.py from LVKinyanjui/FastInferenceChat: direct link, hf CLI and curl.
- Browser
- Download file 849 Bytes
-
https://huggingface.co/spaces/LVKinyanjui/FastInferenceChat/resolve/main/examples/groq_basics.py
- Command line
-
hf download hf://spaces/LVKinyanjui/FastInferenceChat/examples/groq_basics.py
-
curl -L -o groq_basics.py https://huggingface.co/spaces/LVKinyanjui/FastInferenceChat/resolve/main/examples/groq_basics.py
849 Bytes
| import requests | |
| import json | |
| import os | |
| api_key = os.getenv('GROQ_API_KEY') | |
| url = "https://api.groq.com/openai/v1/chat/completions" | |
| payload = json.dumps({ | |
| "messages": [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| { | |
| "type": "text", | |
| "text": "What's in this image?" | |
| }, | |
| { | |
| "type": "image_url", | |
| "image_url": { | |
| "url": "https://upload.wikimedia.org/wikipedia/commons/f/f2/LPU-v1-die.jpg" | |
| } | |
| } | |
| ] | |
| } | |
| ], | |
| "model": "meta-llama/llama-4-scout-17b-16e-instruct", | |
| "temperature": 1, | |
| "max_completion_tokens": 1024, | |
| "top_p": 1, | |
| "stream": False, | |
| "stop": None | |
| }) | |
| headers = { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': f'Bearer {api_key}' | |
| } | |
| response = requests.request("POST", url, headers=headers, data=payload) | |
| print(response.text) | |