You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`Entity.LLM` and `Entity.ASSISTANT`: Message sender types to filter
119
119
-`ChatDocument`: Message format with content and metadata
120
120
-`DONE` constant: Must be imported from `langroid.utils.constants`
121
+
-`MockLMConfig`: Allows testing without API keys using pattern-matched responses
121
122
122
123
3.**WebSocket Considerations**:
123
124
- Need robust session management
124
125
- Must handle reconnections gracefully
125
126
- Async message monitoring is complex with Langroid's sync model
126
127
128
+
### MockLM Integration
129
+
130
+
One positive outcome is the successful integration of Langroid's `MockLMConfig`, which allows the application to run without any API keys. The mock responses are pattern-matched based on keywords in the user input:
131
+
132
+
```python
133
+
MockLMConfig(
134
+
response_dict={
135
+
"hello": "Hello! I'm a mock Langroid agent...",
136
+
"5 + 7|5+7": "5 + 7 equals 12!",
137
+
"default": "That's interesting! As a mock agent..."
138
+
}
139
+
)
140
+
```
141
+
142
+
This makes the project accessible for testing and development without requiring expensive API calls.
143
+
127
144
## Proposed Solutions (Not Yet Implemented)
128
145
129
146
### 1. Singleton Session Manager
@@ -176,14 +193,100 @@ class EventDrivenAgent(lr.ChatAgent):
176
193
177
194
### Setup
178
195
179
-
1.**Backend**:
196
+
**No API Keys Required!** The application uses Langroid's `MockLMConfig` by default, allowing you to test the chat interface without any API keys.
197
+
198
+
#### Quick Start (Recommended)
199
+
200
+
The easiest way to run both frontend and backend together:
201
+
202
+
```bash
203
+
# From the ui directory
204
+
./run.sh
205
+
```
206
+
207
+
This script:
208
+
- Starts the backend server on port 8000
209
+
- Starts the frontend development server on port 5173
210
+
- Handles graceful shutdown when you press Ctrl+C
211
+
212
+
#### Manual Setup (Alternative)
213
+
214
+
If you prefer to run each component separately or if `run.sh` doesn't work on your system:
215
+
216
+
1.**Backend** (in one terminal):
180
217
```bash
181
218
cd backend
182
219
pip install -r requirements.txt
183
-
export OPENAI_API_KEY="your-key"# Optional
184
220
python main.py
185
221
```
186
222
223
+
2.**Frontend** (in another terminal):
224
+
```bash
225
+
cd frontend
226
+
npm install
227
+
npm run dev
228
+
```
229
+
230
+
### Testing the Implementation
231
+
232
+
Once both servers are running:
233
+
234
+
1.**Open the UI**: Navigate to http://localhost:5173 in your browser
235
+
2.**Test Basic Connectivity**:
236
+
- The UI should load without errors
237
+
- Check browser console for WebSocket connection messages
238
+
- You should see "Connected to chat server" in the UI
239
+
240
+
3.**Test Message Flow**:
241
+
- Type a message like "hello" and press Enter
242
+
- The backend terminal should show the message was received
243
+
- Watch for agent response generation in the backend logs
244
+
-**Current Issue**: Agent responses are generated but don't appear in the UI
245
+
246
+
4.**Monitor the Backend Console**:
247
+
- Look for `🤖 Using MockLM` or `🔑 Using OpenAI GPT` to confirm LLM mode
248
+
- Watch for any error messages or stack traces
249
+
- Agent responses will be visible in the console even if not in UI
250
+
251
+
5.**Debug WebSocket Connection**:
252
+
- Browser DevTools → Network tab → WS filter
253
+
- Look for the WebSocket connection to `ws://localhost:8000/ws`
254
+
- Check the Messages tab to see data flow
255
+
256
+
### Running with MockLM
257
+
258
+
There are three ways to use the MockLM (no API keys needed):
259
+
260
+
1.**Default behavior**: Just run without any API keys
261
+
```bash
262
+
python main.py
263
+
```
264
+
265
+
2.**Environment variable**: Force mock mode even with API keys
266
+
```bash
267
+
USE_MOCK_LLM=true python main.py
268
+
```
269
+
270
+
3.**Command line flag**: Use the --mock flag
271
+
```bash
272
+
python main.py --mock
273
+
```
274
+
275
+
The backend will print which mode it's using:
276
+
-`🤖 Using MockLM - no API keys required!`
277
+
-`🔑 Using OpenAI GPT (API key: sk-proj...)`
278
+
279
+
### Command Line Options
280
+
281
+
```bash
282
+
python main.py --help
283
+
284
+
Options:
285
+
--mock Force use of MockLM even if API keys are present
286
+
--port PORT Port to run the server on (default: 8000)
287
+
--host HOST Host to bind the server to (default: 0.0.0.0)
use_mock=os.getenv("USE_MOCK_LLM", "").lower() in ["true", "1", "yes"]
98
100
openai_key=os.getenv("OPENAI_API_KEY")
99
101
100
-
ifopenai_key:
102
+
# Use mock if explicitly requested OR if no API key is present
103
+
ifuse_mockornotopenai_key:
104
+
print("🤖 Using MockLM - no API keys required!")
105
+
config=ChatAgentConfig(
106
+
llm=MockLMConfig(
107
+
response_dict={
108
+
"hello": "Hello! I'm a mock Langroid agent running locally without any API keys. How can I help you test the chat interface?",
109
+
"hi": "Hi there! I'm the mock assistant. Try asking me to calculate something, or ask about the weather!",
110
+
"help": "I can help you test the chat UI! Try these:\n- Basic math (e.g., 'What is 5 + 7?')\n- Weather queries\n- General conversation\n- Or just chat about anything!",
111
+
"weather": "I'm a mock model, so I can't check real weather, but let's pretend it's sunny with a chance of debugging! ☀️",
112
+
"coding": "I love talking about code! This UI is built with React and FastAPI. What would you like to know?",
113
+
"math|calculate|what is": "Let me pretend to calculate that for you... The answer is 42! (I'm a mock, so I always give the same answer 😄)",
114
+
"5 + 7|5+7": "5 + 7 equals 12! (Even a mock can do simple math sometimes)",
115
+
"bye|goodbye": "Goodbye! Thanks for testing the Langroid Chat UI!",
116
+
"langroid": "Langroid is an amazing framework for building LLM-powered applications! This chat UI demonstrates how to integrate it with web technologies.",
117
+
"test": "Testing, testing, 1-2-3! The WebSocket connection seems to be working well!",
118
+
"default": "That's interesting! As a mock agent, I have limited responses, but I'm here to help test the chat interface. What else would you like to try?",
119
+
},
120
+
default_response="I'm a mock Langroid agent with limited responses. Try asking about math, weather, or just say hello!"
121
+
),
122
+
system_message="You are a mock assistant for testing the Langroid Chat UI without API keys."
123
+
)
124
+
else:
125
+
print(f"🔑 Using OpenAI GPT (API key: {openai_key[:8]}...)")
0 commit comments