Skip to content

Commit c784bc5

Browse files
committed
Updated LocalLab package v0.4.25 and Updated docs
1 parent b88965e commit c784bc5

File tree

11 files changed

+120
-93
lines changed

11 files changed

+120
-93
lines changed

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
- '.github/workflows/publish.yml'
1313
- 'CHANGELOG.md'
1414

15+
permissions:
16+
contents: write
17+
1518
jobs:
1619
build-and-publish:
1720
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 27 additions & 51 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@ graph LR
1313
```
1414

1515
### The Server (Your AI Engine)
16+
1617
Think of the server as your personal AI engine. It:
18+
1719
- Downloads and runs AI models on your computer
1820
- Manages memory and resources automatically
1921
- Optimizes performance based on your hardware
2022
- Provides a simple API for accessing models
2123

2224
You can run it:
25+
2326
- On your computer (local mode)
2427
- On Google Colab (free GPU mode)
2528

2629
### The Client (Your AI Controller)
30+
2731
The client is how your code talks to the AI. It:
32+
2833
- Connects to your LocalLab server
2934
- Sends requests for text generation
3035
- Handles chat conversations
@@ -36,15 +41,18 @@ The client is how your code talks to the AI. It:
3641
When you use LocalLab:
3742

3843
1. **Server Setup**
44+
3945
```python
4046
from locallab import start_server
4147
start_server() # Server starts and loads AI model
4248
```
4349

4450
2. **Client Connection**
51+
4552
```python
4653
from locallab.client import LocalLabClient
47-
client = LocalLabClient("http://localhost:8000")
54+
server_url = "http://localhost:8000" # or "https://your-ngrok-url.ngrok.app"
55+
client = LocalLabClient(server_url)
4856
```
4957

5058
3. **AI Interaction**
@@ -77,11 +85,13 @@ responses = await client.batch_generate([
7785
## 💻 Requirements
7886

7987
**Local Computer:**
88+
8089
- Python 3.8+
8190
- 4GB RAM minimum
8291
- GPU optional (but recommended)
8392

8493
**Google Colab:**
94+
8595
- Just a Google account!
8696
- Free tier works fine
8797

@@ -90,18 +100,21 @@ responses = await client.batch_generate([
90100
### 1. Choose Your Path
91101

92102
**New to AI/Programming?**
103+
93104
1. Start with our [Getting Started Guide](./docs/guides/getting-started.md)
94105
2. Try the [Basic Examples](./docs/guides/examples.md)
95106
3. Join our [Community](https://github.com/UtkarshTheDev/LocalLab/discussions)
96107

97108
**Developer?**
109+
98110
1. Check [API Reference](./docs/guides/api.md)
99111
2. See [Client Libraries](./docs/clients/README.md)
100112
3. Read [Advanced Features](./docs/guides/advanced.md)
101113

102114
### 2. Read the Docs
103115

104116
Our [Documentation Guide](./docs/README.md) will help you:
117+
105118
- Understand LocalLab's features
106119
- Learn best practices
107120
- Find solutions to common issues

docs/guides/cli.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ locallab info
151151

152152
## Environment Variables
153153

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-
156154
Key environment variables:
157155

156+
- `HUGGINGFACE_TOKEN`: HuggingFace API token for accessing models (optional)
158157
- `HUGGINGFACE_MODEL`: Model to load
159158
- `NGROK_AUTH_TOKEN`: Ngrok authentication token
160159
- `LOCALLAB_ENABLE_QUANTIZATION`: Enable/disable quantization
@@ -166,7 +165,11 @@ Key environment variables:
166165

167166
## Configuration Storage
168167

169-
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:
169+
- HuggingFace token (if provided)
170+
- Model settings
171+
- Server configuration
172+
- Optimization settings
170173

171174
To view your stored configuration:
172175

docs/guides/examples.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This guide provides practical examples of using LocalLab in your projects. Each example includes code snippets and explanations.
44

55
## 📚 Table of Contents
6+
67
- [Basic Usage](#basic-usage)
78
- [Text Generation](#text-generation)
89
- [Chat Completion](#chat-completion)
@@ -21,15 +22,15 @@ from locallab.client import LocalLabClient
2122

2223
async def main():
2324
# Initialize client
24-
client = LocalLabClient("http://localhost:8000")
25-
25+
client = LocalLabClient("http://localhost:8000") # or "https://your-ngrok-url.ngrok.app"
26+
2627
try:
2728
# Check if server is healthy
2829
is_healthy = await client.health_check()
2930
print(f"Server status: {'Ready' if is_healthy else 'Not Ready'}")
30-
31+
3132
# Your code here...
32-
33+
3334
finally:
3435
# Always close the client when done
3536
await client.close()
@@ -41,11 +42,12 @@ asyncio.run(main())
4142
## Text Generation
4243

4344
### Simple Generation
45+
4446
Generate text with default settings:
4547

4648
```python
4749
async def generate_text():
48-
client = LocalLabClient("http://localhost:8000")
50+
client = LocalLabClient("http://localhost:8000") # or "https://your-ngrok-url.ngrok.app"
4951
try:
5052
response = await client.generate(
5153
"Write a short story about a robot"
@@ -56,6 +58,7 @@ async def generate_text():
5658
```
5759

5860
### Custom Parameters
61+
5962
Control the generation with parameters:
6063

6164
```python
@@ -70,11 +73,12 @@ response = await client.generate(
7073
## Chat Completion
7174

7275
### Basic Chat
76+
7377
Have a simple conversation:
7478

7579
```python
7680
async def chat_example():
77-
client = LocalLabClient("http://localhost:8000")
81+
client = LocalLabClient("http://localhost:8000") # or "https://your-ngrok-url.ngrok.app"
7882
try:
7983
response = await client.chat([
8084
{"role": "system", "content": "You are a helpful assistant."},
@@ -86,6 +90,7 @@ async def chat_example():
8690
```
8791

8892
### Multi-turn Conversation
93+
8994
Maintain a conversation thread:
9095

9196
```python
@@ -101,11 +106,12 @@ response = await client.chat(messages)
101106
## Streaming Responses
102107

103108
### Stream Text Generation
109+
104110
Get responses token by token:
105111

106112
```python
107113
async def stream_example():
108-
client = LocalLabClient("http://localhost:8000")
114+
client = LocalLabClient("http://localhost:8000") # or "https://your-ngrok-url.ngrok.app"
109115
try:
110116
print("Generating story: ", end="", flush=True)
111117
async for token in client.stream_generate("Once upon a time"):
@@ -116,6 +122,7 @@ async def stream_example():
116122
```
117123

118124
### Stream Chat
125+
119126
Stream chat responses:
120127

121128
```python
@@ -129,6 +136,7 @@ async def stream_chat():
129136
## Batch Processing
130137

131138
### Process Multiple Prompts
139+
132140
Generate responses for multiple prompts efficiently:
133141

134142
```python
@@ -138,9 +146,9 @@ async def batch_example():
138146
"Tell a joke",
139147
"Give a fun fact"
140148
]
141-
149+
142150
responses = await client.batch_generate(prompts)
143-
151+
144152
for prompt, response in zip(prompts, responses["responses"]):
145153
print(f"\nPrompt: {prompt}")
146154
print(f"Response: {response}")
@@ -149,54 +157,56 @@ async def batch_example():
149157
## Model Management
150158

151159
### Load Different Models
160+
152161
Switch between different models:
153162

154163
```python
155164
async def model_management():
156-
client = LocalLabClient("http://localhost:8000")
165+
client = LocalLabClient("http://localhost:8000") # or "https://your-ngrok-url.ngrok.app"
157166
try:
158167
# List available models
159168
models = await client.list_models()
160169
print("Available models:", models)
161-
170+
162171
# Load a specific model
163172
await client.load_model("microsoft/phi-2")
164-
173+
165174
# Get current model info
166175
model_info = await client.get_current_model()
167176
print("Current model:", model_info)
168-
177+
169178
# Generate with loaded model
170179
response = await client.generate("Hello!")
171180
print(response)
172-
181+
173182
finally:
174183
await client.close()
175184
```
176185

177186
## Error Handling
178187

179188
### Handle Common Errors
189+
180190
Properly handle potential errors:
181191

182192
```python
183193
async def error_handling():
184194
try:
185195
# Try to connect
186-
client = LocalLabClient("http://localhost:8000")
187-
196+
client = LocalLabClient("http://localhost:8000") # or "https://your-ngrok-url.ngrok.app"
197+
188198
# Check server health
189199
if not await client.health_check():
190200
print("Server is not responding")
191201
return
192-
202+
193203
# Try generation
194204
try:
195205
response = await client.generate("Hello!")
196206
print(response)
197207
except Exception as e:
198208
print(f"Generation failed: {str(e)}")
199-
209+
200210
except ConnectionError:
201211
print("Could not connect to server")
202212
except Exception as e:
@@ -208,6 +218,7 @@ async def error_handling():
208218
## Best Practices
209219

210220
1. **Always Close the Client**
221+
211222
```python
212223
try:
213224
# Your code here
@@ -216,13 +227,15 @@ async def error_handling():
216227
```
217228

218229
2. **Check Server Health**
230+
219231
```python
220232
if not await client.health_check():
221233
print("Server not ready")
222234
return
223235
```
224236

225237
3. **Use Proper Error Handling**
238+
226239
```python
227240
try:
228241
response = await client.generate(prompt)
@@ -245,4 +258,4 @@ async def error_handling():
245258

246259
---
247260

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).

locallab/cli/interactive.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,17 @@ def prompt_for_config(use_ngrok: bool = None, port: int = None, ngrok_auth_token
256256
os.environ["LOCALLAB_LOG_FILE"] = log_file
257257
config["log_file"] = log_file
258258

259+
# Ask about HuggingFace token
260+
hf_token = config.get("huggingface_token") or os.environ.get("HUGGINGFACE_TOKEN")
261+
if not hf_token or force_reconfigure:
262+
hf_token = click.prompt(
263+
"🔑 Enter your HuggingFace token (optional, press Enter to skip)",
264+
default="",
265+
hide_input=True
266+
)
267+
if hf_token:
268+
os.environ["HUGGINGFACE_TOKEN"] = hf_token
269+
config["huggingface_token"] = hf_token
270+
259271
click.echo("\n✅ Configuration complete!\n")
260-
return config
272+
return config

locallab/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from huggingface_hub import model_info, HfApi
77
import logging
88
from pathlib import Path
9+
import click
910

1011

1112
def get_env_var(key: str, *, default: Any = None, var_type: Type = str) -> Any:
@@ -512,3 +513,8 @@ def reset_instructions(self, model_id: Optional[str] = None):
512513

513514
# Initialize system instructions
514515
system_instructions = SystemInstructions()
516+
517+
518+
519+
520+

locallab/model_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ async def load_model(self, model_id: str) -> bool:
254254
try:
255255
start_time = time.time()
256256
logger.info(f"\n{Fore.CYAN}Loading model: {model_id}{Style.RESET_ALL}")
257+
258+
from .config import get_hf_token
259+
hf_token = get_hf_token(interactive=True)
257260

258261
if self.model is not None:
259262
prev_model = self.current_model

0 commit comments

Comments
 (0)