Skip to content

Commit

Permalink
initial example
Browse files Browse the repository at this point in the history
  • Loading branch information
mertyg committed Jun 11, 2024
1 parent 60a0863 commit 5975d94
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ This API is similar to the Pytorch API, making it simple to adapt to your usecas

## QuickStart

```python
import textgrad as tg
# Step 1: Get an initial response from an LLM
model = tg.BlackboxLLM("gpt-4o")
punchline = model(tg.Variable("write a punchline for my github package about optimizing compound AI systems", role_description="prompt", requires_grad=False))
punchline.set_role_description("a concise punchline that must hook everyone")
```

Initial `punchline` from the model:
> Supercharge your AI synergy with our optimization toolkit – where compound intelligence meets peak performance!

```python
# Step 2: Define the loss function and the optimizer, just like in PyTorch!
loss_fn = tg.TextLoss("We want to have a super smart and funny punchline. Is the current one concise and addictive? Is the punch fun, makes sense, and subtle enough?")
optimizer = tg.TGD(parameters=[punchline])
```

```python
# Step 3: Do the loss computation, backward pass, and update the punchline
loss = loss_fn(punchline)
loss.backward()
optimizer.step()
```
Optimized punchline:
> Boost your AI with our toolkit – because even robots need a tune-up!

### Tutorials

We have prepared a couple of tutorials to get you started with TextGrad.
Expand All @@ -46,7 +74,7 @@ You can install TextGrad via pip:
pip install textgrad
```

## Examples
## More detailed examples

### Minimal Instance Optimization Example

Expand Down

0 comments on commit 5975d94

Please sign in to comment.