Skip to content

Commit 67eecb9

Browse files
committed
2,3
1 parent 9344ad7 commit 67eecb9

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

docs/building-blocks/2-modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A **DSPy module** is a building block for programs that use LMs.
1313
- Multiple modules can be composed into bigger modules (programs). DSPy modules are inspired directly by NN modules in PyTorch, but applied to LM programs.
1414

1515

16-
### How do I use a built-in module, like `dspy.Predict` or `dspy.ChainOfThought`?
16+
## How do I use a built-in module, like `dspy.Predict` or `dspy.ChainOfThought`?
1717

1818
Let's start with the most fundamental module, `dspy.Predict`. Internally, all other DSPy modules are just built using `dspy.Predict`.
1919

docs/building-blocks/3-language_models.md

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,20 @@ sidebar_position: 4
44

55
# Language Models
66

7-
This guide assumes you followed the [intro tutorial](https://colab.research.google.com/github/stanfordnlp/dspy/blob/main/intro.ipynb) to build your first few DSPy programs.
87

9-
Remember that a **DSPy program** is just Python code that calls one or more DSPy modules, like `dspy.Predict` or `dspy.ChainOfThought`, to use LMs.
8+
## Remote LMs.
109

11-
## 1) Short Intro to LMs in DSPy {#1-short-intro-to-lms-in-dspy}
12-
13-
``` python
14-
# Install `dspy-ai` if needed.
15-
16-
try: import dspy
17-
except ImportError:
18-
%pip install dspy-ai
19-
import dspy
20-
```
21-
22-
## 2) Supported LM clients. {#2-supported-lm-clients}
23-
24-
### Remote LMs. {#remote-lms}
25-
26-
These models are managed services. You just need to sign up and obtain
27-
an API key.
10+
These models are managed services. You just need to sign up and obtain an API key.
2811

2912
1. `dspy.OpenAI` for GPT-3.5 and GPT-4.
3013

3114
2. `dspy.Cohere`
3215

3316
3. `dspy.Anyscale` for hosted Llama2 models.
3417

35-
### Local LMs. {#local-lms}
18+
### Local LMs.
3619

37-
You need to host these models on your own GPU(s). Below, we include
38-
pointers for how to do that.
20+
You need to host these models on your own GPU(s). Below, we include pointers for how to do that.
3921

4022
1. `dspy.HFClientTGI`: for HuggingFace models through the Text Generation Inference (TGI) system. [Tutorial: How do I install and launch the TGI server?](/api/hosting_language_models_locally/TGI)
4123

@@ -49,16 +31,14 @@ pointers for how to do that.
4931

5032
If there are other clients you want added, let us know!
5133

52-
## 3) Setting up the LM client. {#3-setting-up-the-lm-client}
34+
## Setting up the LM client.
5335

5436
You can just call the constructor that connects to the LM. Then, use
5537
`dspy.configure` to declare this as the default LM.
5638

5739
For example, for OpenAI, you can do it as follows.
5840

5941
``` python
60-
# TODO: Add a graceful line for OPENAI_API_KEY.
61-
6242
gpt3_turbo = dspy.OpenAI(model='gpt-3.5-turbo-1106', max_tokens=300)
6343
gpt4_turbo = dspy.OpenAI(model='gpt-4-1106-preview', max_tokens=300)
6444

@@ -69,13 +49,11 @@ gpt4_turbo = dspy.OpenAI(model='gpt-4-1106-preview', max_tokens=300)
6949
dspy.configure(lm=gpt3_turbo)
7050
```
7151

72-
## 4) Using a different LM within a code block. {#4-using-a-different-lm-within-a-code-block}
52+
## Using multiple LMs at once.
7353

74-
The default LM above is GPT-3.5, `gpt3_turbo`. What if I want to run a
75-
piece of code with, say, GPT-4 or LLama-2?
54+
The default LM above is GPT-3.5, `gpt3_turbo`. What if I want to run a piece of code with, say, GPT-4 or LLama-2?
7655

77-
Instead of changing the default LM, you can just change it inside a
78-
block of code.
56+
Instead of changing the default LM, you can just change it inside a block of code.
7957

8058
**Tip:** Using `dspy.configure` and `dspy.context` is thread-safe!
8159

@@ -93,7 +71,7 @@ with dspy.context(lm=gpt4_turbo):
9371
The castle David Gregory inherited has 7 floors.
9472
The number of floors in the castle David Gregory inherited cannot be determined with the information provided.
9573

96-
## 5) Tips and Tricks. {#5-tips-and-tricks}
74+
## Tips and Tricks.
9775

9876
In DSPy, all LM calls are cached. If you repeat the same call, you will
9977
get the same outputs. (If you change the inputs or configurations, you

0 commit comments

Comments
 (0)