Spaces:
Sleeping
Sleeping
Download groq_chat.py from DanishShahzad/Sample_ChatBot: direct link, hf CLI and curl.
- Browser
- Download file 999 Bytes
-
https://huggingface.co/spaces/DanishShahzad/Sample_ChatBot/resolve/main/groq_chat.py
- Command line
-
hf download hf://spaces/DanishShahzad/Sample_ChatBot/groq_chat.py
-
curl -L -o groq_chat.py https://huggingface.co/spaces/DanishShahzad/Sample_ChatBot/resolve/main/groq_chat.py
999 Bytes
| # groq_chat.py | |
| import os | |
| from groq import Groq | |
| client = Groq(api_key=os.getenv("GROQ_API_KEY_simple_chatbot")) | |
| MODEL = "moonshotai/kimi-k2-instruct" | |
| def stream_chat_with_groq(prompt, history=None, system_prompt="You are a helpful assistant.", temperature=0.7): | |
| messages = [{"role": "system", "content": system_prompt}] | |
| if history: | |
| messages += history | |
| messages.append({"role": "user", "content": prompt}) | |
| return client.chat.completions.create( | |
| model=MODEL, | |
| messages=messages, | |
| temperature=temperature, | |
| stream=True | |
| ) | |
| def chat_with_groq(prompt, history=None, system_prompt="You are a helpful assistant.", temperature=0.7): | |
| messages = [{"role": "system", "content": system_prompt}] | |
| if history: | |
| messages += history | |
| messages.append({"role": "user", "content": prompt}) | |
| return client.chat.completions.create( | |
| model=MODEL, | |
| messages=messages, | |
| temperature=temperature, | |
| stream=False | |
| ) | |