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
Copy file name to clipboardExpand all lines: docs/guides/cli.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,10 +151,9 @@ locallab info
151
151
152
152
## Environment Variables
153
153
154
-
The CLI respects environment variables that you've already set. If an environment variable is set, the CLI won't prompt for that setting unless you explicitly run the configuration wizard.
155
-
156
154
Key environment variables:
157
155
156
+
-`HUGGINGFACE_TOKEN`: HuggingFace API token for accessing models (optional)
The CLI stores your configuration in `~/.locallab/config.json` for future use. This means you don't have to re-enter your settings each time you run LocalLab.
168
+
The CLI stores your configuration in `~/.locallab/config.json` for future use. This includes:
client = LocalLabClient("http://localhost:8000")# or "https://your-ngrok-url.ngrok.app"
109
115
try:
110
116
print("Generating story: ", end="", flush=True)
111
117
asyncfor token in client.stream_generate("Once upon a time"):
@@ -116,6 +122,7 @@ async def stream_example():
116
122
```
117
123
118
124
### Stream Chat
125
+
119
126
Stream chat responses:
120
127
121
128
```python
@@ -129,6 +136,7 @@ async def stream_chat():
129
136
## Batch Processing
130
137
131
138
### Process Multiple Prompts
139
+
132
140
Generate responses for multiple prompts efficiently:
133
141
134
142
```python
@@ -138,9 +146,9 @@ async def batch_example():
138
146
"Tell a joke",
139
147
"Give a fun fact"
140
148
]
141
-
149
+
142
150
responses =await client.batch_generate(prompts)
143
-
151
+
144
152
for prompt, response inzip(prompts, responses["responses"]):
145
153
print(f"\nPrompt: {prompt}")
146
154
print(f"Response: {response}")
@@ -149,54 +157,56 @@ async def batch_example():
149
157
## Model Management
150
158
151
159
### Load Different Models
160
+
152
161
Switch between different models:
153
162
154
163
```python
155
164
asyncdefmodel_management():
156
-
client = LocalLabClient("http://localhost:8000")
165
+
client = LocalLabClient("http://localhost:8000")# or "https://your-ngrok-url.ngrok.app"
157
166
try:
158
167
# List available models
159
168
models =await client.list_models()
160
169
print("Available models:", models)
161
-
170
+
162
171
# Load a specific model
163
172
await client.load_model("microsoft/phi-2")
164
-
173
+
165
174
# Get current model info
166
175
model_info =await client.get_current_model()
167
176
print("Current model:", model_info)
168
-
177
+
169
178
# Generate with loaded model
170
179
response =await client.generate("Hello!")
171
180
print(response)
172
-
181
+
173
182
finally:
174
183
await client.close()
175
184
```
176
185
177
186
## Error Handling
178
187
179
188
### Handle Common Errors
189
+
180
190
Properly handle potential errors:
181
191
182
192
```python
183
193
asyncdeferror_handling():
184
194
try:
185
195
# Try to connect
186
-
client = LocalLabClient("http://localhost:8000")
187
-
196
+
client = LocalLabClient("http://localhost:8000")# or "https://your-ngrok-url.ngrok.app"
197
+
188
198
# Check server health
189
199
ifnotawait client.health_check():
190
200
print("Server is not responding")
191
201
return
192
-
202
+
193
203
# Try generation
194
204
try:
195
205
response =await client.generate("Hello!")
196
206
print(response)
197
207
exceptExceptionas e:
198
208
print(f"Generation failed: {str(e)}")
199
-
209
+
200
210
exceptConnectionError:
201
211
print("Could not connect to server")
202
212
exceptExceptionas e:
@@ -208,6 +218,7 @@ async def error_handling():
208
218
## Best Practices
209
219
210
220
1.**Always Close the Client**
221
+
211
222
```python
212
223
try:
213
224
# Your code here
@@ -216,13 +227,15 @@ async def error_handling():
216
227
```
217
228
218
229
2.**Check Server Health**
230
+
219
231
```python
220
232
ifnotawait client.health_check():
221
233
print("Server not ready")
222
234
return
223
235
```
224
236
225
237
3.**Use Proper Error Handling**
238
+
226
239
```python
227
240
try:
228
241
response =await client.generate(prompt)
@@ -245,4 +258,4 @@ async def error_handling():
245
258
246
259
---
247
260
248
-
Need more examples? Check our [Community Examples](https://github.com/UtkarshTheDev/LocalLab/discussions/categories/show-and-tell) or ask in our [Discussion Forum](https://github.com/UtkarshTheDev/LocalLab/discussions).
261
+
Need more examples? Check our [Community Examples](https://github.com/UtkarshTheDev/LocalLab/discussions/categories/show-and-tell) or ask in our [Discussion Forum](https://github.com/UtkarshTheDev/LocalLab/discussions).
0 commit comments