Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An interactive platform to explore and experiment with various AI models powered by Groq. 🤖 Customize parameters, chat with AI, and export your conversations in multiple formats. 📄✨

NotificationsYou must be signed in to change notification settings

SauravSrivastav/groq-ai-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Groq AI Playground is an interactive platform to explore and experiment with various AI models powered by Groq. Customize parameters, chat with AI, and export your conversations in multiple formats.

Features ✨

  • Fast and Efficient: Powered by Groq's LPU for low latency and high performance.
  • Customizable: Modify system prompts and choose from various models.
  • Interactive UI: Built with Streamlit for an intuitive user interface.
  • Export Options: Export chat history in JSON, TXT, or PDF formats.

Installation 🛠️

  1. Clone the repository:

    git clone https://github.com/SauravSrivastav/groq-ai-playground.gitcd groq-ai-playground
  2. Create a virtual environment:

    python -m venv venvsource venv/bin/activate# On Windows use `venv\Scripts\activate`
  3. Install the dependencies:

    pip install -r requirements.txt
  4. Set up your Groq API Key:

    • Sign up on theGroq website and generate an API key.
    • Set the API key as an environment variable:
      export GROQ_API_KEY=your_groq_api_key

Running the Application 🚀

  1. Start the Streamlit app:

    streamlit run app.py
  2. Open your browser and navigate tohttp://localhost:8501 to interact with the AI models.

Usage Instructions 📖

  1. Enter your Groq API Key in the sidebar.
  2. Choose a model from the dropdown menu.
  3. Adjust parameters such as max tokens and temperature.
  4. Ask a question in the text input box and get responses from the AI.

App Screenshots 📸

App Screenshot 1
App Screenshot 2

Detailed Code Explanation 🧩

Main Application (app.py)

Imports and Setup

importosimportstreamlitasstfromtypingimportGeneratorfromgroqimportGroqimportjsonfromdatetimeimportdatetimefromfpdfimportFPDFimportbase64importtorchfromtransformersimportpipelinefromdatasetsimportload_datasetfromtorch.nn.attentionimportSDPBackend,sdpa_kernel
  • Import necessary libraries and modules.
  • Set up the main function for the Streamlit application.

Sidebar Configuration

withst.sidebar:st.markdown("### Configuration")api_key=st.text_input("Enter your Groq API Key:",type="password",placeholder="Your API Key")ifapi_key:st.session_state.api_key=api_keyst.markdown("[Get your Groq API key here](https://console.groq.com/keys)")model_option=st.selectbox("Choose a model:",options=list(models.keys()),format_func=lambdax:models[x]["name"],index=0)st.markdown(f"**Name:**{models[model_option]['name']} **Max Tokens:**{models[model_option]['tokens']} **Developer:**{models[model_option]['developer']}")max_tokens=st.slider("Max Tokens:",min_value=512,max_value=models[model_option]["tokens"],value=4096,step=512)temperature=st.slider("Temperature:",min_value=0.0,max_value=1.0,value=0.7,step=0.1)ifst.button("Clear Chat"):st.session_state.messages= []export_format=st.selectbox("Choose export format:",options=["JSON","TXT","PDF"],index=0)ifst.button("Export Chat"):# Export logic here
  • Provide instructions for obtaining the Groq API key.
  • Input field for the user to enter their API key.
  • Model selection and parameter adjustment.

Chat Interaction

ifinteraction_type=="Text Chat":ifprompt:=st.chat_input("Enter your prompt here..."):ifnotst.session_state.api_key:st.error("Please enter your Groq API Key in the sidebar.")else:st.session_state.messages.append({"role":"user","content":prompt})withst.chat_message("user",avatar="🧑‍💻"):st.markdown(prompt)client=create_groq_client()ifclient:try:chat_completion=client.chat.completions.create(model=model_option,messages=[{"role":m["role"],"content":m["content"]}forminst.session_state.messages],max_tokens=max_tokens,temperature=temperature,stream=True,                    )response_chunks= []withst.chat_message("assistant",avatar="🤖"):message_placeholder=st.empty()forchunkingenerate_chat_responses(chat_completion):response_chunks.append(chunk)message_placeholder.markdown(''.join(response_chunks)+"▌")full_response=''.join(response_chunks)message_placeholder.markdown(full_response)st.session_state.messages.append({"role":"assistant","content":full_response})exceptExceptionase:st.error(f"An error occurred:{str(e)}",icon="❌")
  • Initialize session state for chat history.
  • Handle user input and display chatbot responses.

Contributing 🤝

Contributions are welcome! If you'd like to improve Groq AI Playground, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

License 📄

This project is licensed under the MIT License. See theLICENSE file for details.

📞 Contact Us

Have questions or suggestions? Reach out to us:


Happy Chatting! 🎉

About

An interactive platform to explore and experiment with various AI models powered by Groq. 🤖 Customize parameters, chat with AI, and export your conversations in multiple formats. 📄✨

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp