├── README.md
├── main.py
└── requirements.txt
/README.md:
--------------------------------------------------------------------------------
1 | # Strawberry Groq 2.0
2 | Strawberry Groq is a streamlined demo application showcasing the power of enhanced chain of thought reasoning using PocketGroq. Experience the advanced capabilities of Groq's language models, elevated by autonomous agent-powered reasoning techniques inspired by OpenAI's "Strawberry" o1 LLM.
3 |
4 | 
5 |
6 | ONLINE DEMO: https://strawberrygroq.streamlit.app/
7 |
8 | ## Features
9 | - **Enhanced Chain of Thought Reasoning**: Toggle between standard responses and detailed step-by-step problem-solving powered by an autonomous agent.
10 | - **Autonomous Agent Integration**: Each step in the chain of thought process is now verified and researched, providing more accurate and well-informed responses.
11 | - **Interactive Chat Interface**: Engage in conversations and pose complex queries with ease.
12 | - **Groq API Integration**: Harness the power of Groq's cutting-edge language models.
13 |
14 | ## Installation
15 | Get started with Strawberry Groq in just a few simple steps:
16 |
17 | 1. Clone this repository:
18 | ```
19 | git clone https://github.com/yourusername/StrawberryGroq.git
20 | cd StrawberryGroq
21 | ```
22 | 2. Install the required dependencies:
23 | ```
24 | pip install -r requirements.txt
25 | ```
26 | 3. Run the Strawberry Groq application:
27 | ```
28 | streamlit run main.py
29 | ```
30 |
31 | ## Usage
32 | 1. Launch the application and enter your Groq API key when prompted.
33 | 2. Toggle the "Use Chain of Thought with Autonomous Agent" checkbox to enable enhanced reasoning.
34 | 3. Enter your questions or prompts in the chat input.
35 | 4. Experience the power of autonomous agent-powered chain of thought processing in action!
36 |
37 | ## Why Strawberry Groq?
38 | Strawberry Groq demonstrates the true potential of enhanced chain of thought processing, a technique that elevates language models to new heights of reasoning and problem-solving. By leveraging PocketGroq and its autonomous agent capabilities, Strawberry Groq showcases how developers can easily integrate these advanced features into their own projects.
39 |
40 | The enhanced chain of thought feature, inspired by OpenAI's "Strawberry" o1 LLM and powered by an autonomous agent, allows for:
41 | - More transparent and verifiable reasoning processes
42 | - Improved problem-solving capabilities with real-time research
43 | - Enhanced explainability of AI-generated responses
44 | - Greater accuracy and reliability in complex problem-solving tasks
45 |
46 | ## Powered by PocketGroq
47 | Strawberry Groq's capabilities are built on top of [PocketGroq](https://github.com/jgravelle/pocketgroq), a powerful yet simple library for Groq API integration. PocketGroq makes it effortless to incorporate advanced language model features and autonomous agent capabilities into your Python projects.
48 |
49 | By using PocketGroq, developers can:
50 | - Easily implement enhanced chain of thought reasoning with autonomous agent support
51 | - Streamline Groq API interactions
52 | - Incorporate real-time research and verification into AI-generated responses
53 | - Enhance their applications with state-of-the-art language processing and autonomous problem-solving
54 |
55 | Explore PocketGroq to unlock the full potential of Groq's language models and autonomous agent capabilities in your own projects!
56 |
57 | ## Contributing
58 | We welcome contributions to Strawberry Groq! If you have suggestions for improvements or new features, please open an issue or submit a pull request.
59 |
60 | ## License
61 | Strawberry Groq is released under the MIT License.
62 |
63 | Please mention J. Gravelle in your code and/or docs if you use his stuff.
64 | He gets all whiny if you don't, and we're the ones who have to put up with him...
65 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import requests
3 | from pocketgroq import GroqProvider
4 | from pocketgroq.autonomous_agent import AutonomousAgent
5 |
6 | # Initialize session state
7 | if 'messages' not in st.session_state:
8 | st.session_state.messages = []
9 | if 'api_key' not in st.session_state:
10 | st.session_state.api_key = ''
11 | if 'available_models' not in st.session_state:
12 | st.session_state.available_models = []
13 | if 'selected_model' not in st.session_state:
14 | st.session_state.selected_model = "llama2-70b-4096" # Default model
15 |
16 | def get_groq_provider():
17 | if not st.session_state.api_key:
18 | st.error("Please enter your Groq API key.")
19 | return None
20 | return GroqProvider(api_key=st.session_state.api_key)
21 |
22 | def fetch_available_models():
23 | api_key = st.session_state.api_key
24 | url = "https://api.groq.com/openai/v1/models"
25 | headers = {
26 | "Authorization": f"Bearer {api_key}",
27 | "Content-Type": "application/json"
28 | }
29 | try:
30 | response = requests.get(url, headers=headers)
31 | response.raise_for_status()
32 | models_data = response.json()
33 | st.session_state.available_models = [model['id'] for model in models_data['data']]
34 | if st.session_state.selected_model not in st.session_state.available_models:
35 | st.session_state.selected_model = st.session_state.available_models[0]
36 | except requests.RequestException as e:
37 | st.error(f"Error fetching models: {str(e)}")
38 |
39 | def generate_response(prompt: str, use_cot: bool, model: str) -> str:
40 | groq = get_groq_provider()
41 | if not groq:
42 | return "Error: No API key provided."
43 |
44 | # Include chat history in the prompt
45 | history = "\n".join([f"{msg['role']}: {msg['content']}" for msg in st.session_state.messages])
46 | full_prompt = f"{history}\nUser: {prompt}"
47 |
48 | if use_cot:
49 | agent = AutonomousAgent(groq, max_sources=25, model=model)
50 | cot_prompt = f"Solve the following problem step by step, showing your reasoning:\n\n{full_prompt}\n\nSolution:"
51 |
52 | steps = []
53 | for step in agent.process_request(cot_prompt, 25, True):
54 | if step['type'] == 'research':
55 | st.write(f"Research: {step['content']}")
56 | elif step['type'] == 'response':
57 | steps.append(step['content'])
58 |
59 | # Combine steps into a single response
60 | return "\n".join(steps)
61 | else:
62 | return groq.generate(full_prompt, temperature=0, model=model)
63 |
64 | def on_model_change():
65 | st.session_state.selected_model = st.session_state.model_selectbox
66 |
67 | def main():
68 | st.title("Strawberry Groq DEMO")
69 | st.write("This is a simple demo of the PocketGroq library's enhanced 'Chain of Thought' functionality with Autonomous Agent.")
70 | st.write("https://github.com/jgravelle/pocketgroq | https://www.youtube.com/watch?v=S5dY0DG-q-U", unsafe_allow_html=True)
71 |
72 | # API Key input
73 | api_key = st.text_input("Enter your Groq API Key:", type="password")
74 | if api_key:
75 | st.session_state.api_key = api_key
76 | fetch_available_models()
77 |
78 | # Model selection
79 | if st.session_state.available_models:
80 | st.selectbox(
81 | "Select a model:",
82 | st.session_state.available_models,
83 | index=st.session_state.available_models.index(st.session_state.selected_model),
84 | key="model_selectbox",
85 | on_change=on_model_change
86 | )
87 |
88 | st.write(f"Current model: {st.session_state.selected_model}")
89 |
90 | # CoT toggle
91 | use_cot = st.checkbox("Use Chain of Thought with Autonomous Agent")
92 |
93 | # Display chat messages
94 | for message in st.session_state.messages:
95 | with st.chat_message(message["role"]):
96 | st.write(message["content"])
97 |
98 | # Chat input
99 | if prompt := st.chat_input("What would you like to know?"):
100 | st.session_state.messages.append({"role": "user", "content": prompt})
101 | with st.chat_message("user"):
102 | st.write(prompt)
103 |
104 | with st.chat_message("assistant"):
105 | if use_cot:
106 | st.write("Thinking step-by-step with autonomous research...")
107 |
108 | response = generate_response(prompt, use_cot, st.session_state.selected_model)
109 | st.write(response)
110 |
111 | st.session_state.messages.append({"role": "assistant", "content": response})
112 |
113 | if __name__ == "__main__":
114 | main()
115 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | streamlit==1.38.0
2 | pocketgroq==0.5.6
3 | python-dotenv
4 | pillow==10.4.0
5 | beautifulsoup4==4.12.3
6 | requests==2.32.3
7 |
--------------------------------------------------------------------------------