Skip to content

Commit

Permalink
Merge branch 'main' into pr/sushmanthreddy/1745
Browse files Browse the repository at this point in the history
  • Loading branch information
okhat committed Nov 8, 2024
2 parents de02d5b + cdee3b4 commit e0610a1
Show file tree
Hide file tree
Showing 104 changed files with 4,688 additions and 1,413 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ jobs:
run: python3 setup.py sdist bdist_wheel
- name: Publish distribution 📦 to PyPI (dspy)
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
# Publish to dspy-ai
with:
attestations: false
# Publish to dspy-ai
- name: Update version in setup.py (dspy-ai)
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ needs.extract-tag.outputs.version }}"/;}' ./dspy/.internal_dspyai/setup.py
- name: Update package name in setup.py
run: sed -i '/#replace_package_name_marker/{n;s/name="[^"]*"/name="dspy-ai"/;}' ./dspy/.internal_dspyai/setup.py
- name: Update dspy dependency version in setup.py
run: |
sed -i '/#replace_dspy_version_marker/{n;s/dspy==[^"]*/dspy==${{ needs.extract-tag.outputs.version }}/;}' ./dspy/.internal_dspyai/setup.py
sed -i '/#replace_dspy_version_marker/{n;s/dspy==[^"]*/dspy>=${{ needs.extract-tag.outputs.version }}/;}' ./dspy/.internal_dspyai/setup.py
- name: Build a binary wheel
run: python3 ./dspy/.internal_dspyai/setup.py sdist bdist_wheel
- name: Publish distribution 📦 to PyPI (dspy-ai)
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
with:
attestations: false
2 changes: 1 addition & 1 deletion .github/workflows/precommits_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
echo "Changed files"
echo ${{ steps.files.outputs.all }}
echo "Github Client version"
echo "GitHub Client version"
echo $(gh --version)
- name: Pre-Commit Checks
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
id: ruff_fix
uses: chartboost/ruff-action@v1
with:
args: check --fix-only --exit-non-zero-on-fix
args: check --fix-only --diff --exit-non-zero-on-fix
continue-on-error: true
- name: Fail Workflow if Ruff Fix Failed
if: steps.ruff_fix.outcome == 'failure'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The DSPy documentation is divided into **tutorials** (step-by-step illustration
| **Level** | **Tutorial** | **Run in Colab** | **Description** |
| --- | ------------- | ------------- | ------------- |
| Beginner | [**Getting Started**](intro.ipynb) | [<img align="center" src="https://colab.research.google.com/assets/colab-badge.svg" />](https://colab.research.google.com/github/stanfordnlp/dspy/blob/main/intro.ipynb) | Introduces the basic building blocks in DSPy. Tackles the task of complex question answering with HotPotQA. |
| Beginner | [**Minimal Working Example**](https://dspy-docs.vercel.app/docs/quick-start/minimal-example) | N/A | Builds and optimizes a very simple chain-of-thought program in DSPy for math question answering. Very short. |
| Beginner | [**Minimal Working Example**](/docs/docs/quick-start/getting-started-01.md) | N/A | Builds a very simple chain-of-thought program in DSPy for question answering. Very short. |
| Beginner | [**Compiling for Tricky Tasks**](examples/nli/scone/scone.ipynb) | N/A | Teaches LMs to reason about logical statements and negation. Uses GPT-4 to bootstrap few-shot CoT demonstrations for GPT-3.5. Establishes a state-of-the-art result on [ScoNe](https://arxiv.org/abs/2305.19426). Contributed by [Chris Potts](https://twitter.com/ChrisGPotts/status/1740033519446057077). |
| Beginner | [**Local Models & Custom Datasets**](examples/skycamp2023.ipynb) | [<img align="center" src="https://colab.research.google.com/assets/colab-badge.svg" />](https://colab.research.google.com/github/stanfordnlp/dspy/blob/main/examples/skycamp2023.ipynb) | Illustrates two different things together: how to use local models (Llama-2-13B in particular) and how to use your own data examples for training and development.
| Intermediate | [**The DSPy Paper**](https://arxiv.org/abs/2310.03714) | N/A | Sections 3, 5, 6, and 7 of the DSPy paper can be consumed as a tutorial. They include explained code snippets, results, and discussions of the abstractions and API.
Expand Down Expand Up @@ -415,7 +415,7 @@ Guidance, LMQL, RELM, and Outlines are all exciting new libraries for controllin
This is very useful in many settings, but it's generally focused on low-level, structured control of a single LM call. It doesn't help ensure the JSON (or structured output) you get is going to be correct or useful for your task.
In contrast, **DSPy** automatically optimizes the prompts in your programs to align them with various task needs, which may also include producing valid structured ouputs. That said, we are considering allowing **Signatures** in **DSPy** to express regex-like constraints that are implemented by these libraries.
In contrast, **DSPy** automatically optimizes the prompts in your programs to align them with various task needs, which may also include producing valid structured outputs. That said, we are considering allowing **Signatures** in **DSPy** to express regex-like constraints that are implemented by these libraries.
</details>
## Testing
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/building-blocks/1-language_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Any OpenAI-compatible endpoint is easy to set up with an `openai/` prefix as wel

#### Setting up SGLang

1. **Install SGLang (adapted from SGLang [documentation](https://sgl-project.github.io/starts/install.html)):**
1. **Install SGLang (adapted from SGLang [documentation](https://sgl-project.github.io/start/install.html)):**

```bash
pip install "sglang[all]"
Expand Down
1 change: 1 addition & 0 deletions docs/docs/building-blocks/2-signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The 21-year-old Lee made seven appearances and scored one goal for West Ham last

Many DSPy modules (except `dspy.Predict`) return auxiliary information by expanding your signature under the hood.

For example, `dspy.ChainOfThought` also adds a `reasoning` field that includes the LM's reasoning before it generates the output `summary`.
For example, `dspy.ChainOfThought` also adds a `reasoning` field that includes the LM's reasoning before it generates the output `summary`.

```python
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/building-blocks/3-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ response.completions.answer

Let's discuss the output object here.

The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature.
The `dspy.ChainOfThought` module will generally inject a `reasoning` before the output field(s) of your signature.

Let's inspect the (first) rationale and answer!
Let's inspect the (first) reasoning and answer!

```python
print(f"Rationale: {response.rationale}")
print(f"Reasoning: {response.reasoning}")
print(f"Answer: {response.answer}")
```
**Output:**
Expand All @@ -86,7 +86,7 @@ This is accessible whether we request one or many completions.
We can also access the different completions as a list of `Prediction`s or as several lists, one for each field.

```python
response.completions[3].rationale == response.completions.rationale[3]
response.completions[3].reasoning == response.completions.reasoning[3]
```
**Output:**
```text
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def gsm8k_metric(gold, pred, trace=None) -> int:
class FactJudge(dspy.Signature):
"""Judge if the answer is factually correct based on the context."""

context = dspy.InputField(desc="Context for the prediciton")
context = dspy.InputField(desc="Context for the prediction")
question = dspy.InputField(desc="Question to be answered")
answer = dspy.InputField(desc="Answer for the question")
factually_correct = dspy.OutputField(desc="Is the answer factually correct based on the context?", prefix="Factual[Yes/No]:")
Expand Down Expand Up @@ -417,7 +417,7 @@ optimized_program = teleprompter.compile(
optimized_program.save(f"mipro_optimized")

# Evaluate optimized program
print(f"Evluate optimized program...")
print(f"Evaluate optimized program...")
evaluate(optimized_program, devset=devset[:])
```

Expand Down Expand Up @@ -446,7 +446,7 @@ optimized_program = teleprompter.compile(
optimized_program.save(f"mipro_optimized")

# Evaluate optimized program
print(f"Evluate optimized program...")
print(f"Evaluate optimized program...")
evaluate(optimized_program, devset=devset[:])
```
### Signature Optimizer with Types
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/deep-dive/data-handling/loading-custom-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Using the Dataset base class now makes loading custom datasets incredibly easy a

!!! caution

We did not populate `_test` attribute in the above code, which is fine and won't cause any unneccesary error as such. However it'll give you an error if you try to access the test split.
We did not populate `_test` attribute in the above code, which is fine and won't cause any unnecessary error as such. However it'll give you an error if you try to access the test split.

```python
dataset.test[:5]
Expand All @@ -110,6 +110,6 @@ Using the Dataset base class now makes loading custom datasets incredibly easy a

To prevent that you'll just need to make sure `_test` is not `None` and populated with the appropriate data.

You can overide the methods in `Dataset` class to customize your class even more.
You can override the methods in `Dataset` class to customize your class even more.

In summary, the Dataset base class provides a simplistic way to load and preprocess custom datasets with minimal code!
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The constructor initializes the `HFModel` base class to support the handling of
- `model` (_str_): ID of Hugging Face model connected to the TGI server.
- `port` (_int_ or _list_): Port for communicating to the TGI server. This can be a single port number (`8080`) or a list of TGI ports (`[8080, 8081, 8082]`) to route the requests to.
- `url` (_str_): Base URL of hosted TGI server. This will often be `"http://localhost"`.
- `http_request_kwargs` (_dict_): Dictionary of additional keyword agruments to pass to the HTTP request function to the TGI server. This is `None` by default.
- `http_request_kwargs` (_dict_): Dictionary of additional keyword arguments to pass to the HTTP request function to the TGI server. This is `None` by default.
- `**kwargs`: Additional keyword arguments to configure the TGI client.

Example of the TGI constructor:
Expand Down
29 changes: 22 additions & 7 deletions docs/docs/deep-dive/modules/chain-of-thought.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,30 @@ class ChainOfThought(Predict):

self.activated = activated

signature = ensure_signature(self.signature)
self.signature = signature = ensure_signature(signature)
*_keys, last_key = signature.output_fields.keys()

rationale_type = rationale_type or dspy.OutputField(
prefix="Reasoning: Let's think step by step in order to",
desc="${produce the " + last_key + "}. We ...",
)

self.extended_signature = signature.prepend("rationale", rationale_type, type_=str)
prefix = "Reasoning: Let's think step by step in order to"

if isinstance(dspy.settings.lm, dspy.LM):
desc = "${reasoning}"
elif dspy.settings.experimental:
desc = "${produce the output fields}. We ..."
else:
# For dspy <2.5
desc = f"${{produce the {last_key}}}. We ..."

rationale_type = rationale_type or dspy.OutputField(prefix=prefix, desc=desc)

# Add "rationale" field to the output signature.
if isinstance(dspy.settings.lm, dspy.LM) or dspy.settings.experimental:
extended_signature = signature.prepend("reasoning", rationale_type, type_=str)
else:
# For dspy <2.5
extended_signature = signature.prepend("rationale", rationale_type, type_=str)

self._predict = dspy.Predict(extended_signature, **config)
self._predict.extended_signature = extended_signature
```

**Parameters:**
Expand Down
13 changes: 7 additions & 6 deletions docs/docs/deep-dive/modules/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ response.completions.answer

Let's discuss the output object here.

The `dspy.ChainOfThought` module will generally inject a `rationale` before the output field(s) of your signature.
The `dspy.ChainOfThought` module will generally inject a `reasoning` before the output field(s) of your signature.

Let's inspect the (first) rationale and answer!
Let's inspect the (first) reasoning and answer!


```python
print(f"Rationale: {response.rationale}")
print(f"Reasoning: {response.reasoning}")
print(f"Answer: {response.answer}")
```

Rationale: produce the answer. We can consider the fact that ColBERT has shown to outperform other state-of-the-art retrieval models in terms of efficiency and effectiveness. It uses contextualized embeddings and performs document retrieval in a way that is both accurate and scalable.
Answer: One great thing about the ColBERT retrieval model is its superior efficiency and effectiveness compared to other models.
Reasoning: ColBERT (Contextualized Late Interaction over BERT) is a retrieval model that effectively combines the strengths of dense retrieval and traditional BM25 methods. One of its great features is that it allows for efficient and scalable retrieval by using late interaction techniques, which enables the model to leverage the contextual embeddings generated by BERT while still maintaining a fast retrieval speed. This means that it can handle large document collections more effectively than many other models, providing both high relevance in search results and efficiency in processing time.
Answer: A great feature of the ColBERT retrieval model is its ability to efficiently combine contextualized embeddings from BERT with a late interaction mechanism, allowing for scalable and high-performance document retrieval.



This is accessible whether we request one or many completions.
Expand All @@ -107,7 +108,7 @@ We can also access the different completions as a list of `Prediction`s or as se


```python
response.completions[3].rationale == response.completions.rationale[3]
response.completions[3].reasoning == response.completions.reasoning[3]
```

```text
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/deep-dive/modules/predict.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Predict(Parameter):

This method serves as a wrapper for the `forward` method. It allows making predictions using the `Predict` class by providing keyword arguments.

**Paramters:**
**Parameters:**
- `**kwargs`: Keyword arguments required for prediction.

**Returns:**
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/deep-dive/optimizers/bfrs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ In terms of API `BootstrapFewShotWithRandomSearch` teleprompter is quite similar

## Working Example

Let's take the example of optimizing a simple CoT pipeline for GSM8k dataset, we'll take the example in [BootstrapFewShot](/deep-dive/optimizers/bootstrap-fewshot) as our running example for optimizers. We're gonna assume our data and pipeline is same as the on in `BootstrapFewShot` article. So let's start by intializing the optimizer:
Let's take the example of optimizing a simple CoT pipeline for GSM8k dataset, we'll take the example in [BootstrapFewShot](/deep-dive/optimizers/bootstrap-fewshot) as our running example for optimizers. We're gonna assume our data and pipeline is same as the on in `BootstrapFewShot` article. So let's start by initializing the optimizer:

```python
from dspy.teleprompt import BootstrapFewShotWithRandomSearch
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/deep-dive/optimizers/bootstrap-fewshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ When compiling a DSPy program, we generally invoke an optimizer that takes the p

## Setting up a Sample Pipeline

We will be making a basic answer generation pipeline over GSM8K dataset that we saw in the [Minimal Example](https://dspy-docs.vercel.app/docs/quick-start/minimal-example). We won't be changing anything in it! So let's start by configuring the LM which will be OpenAI LM client with `gpt-3.5-turbo` as the LLM in use.
We will be making a basic answer generation pipeline over the GSM8K dataset. We won't be changing anything in it! So let's start by configuring the LM which will be OpenAI LM client with `gpt-3.5-turbo` as the LLM in use.

```python
import dspy
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/deep-dive/optimizers/copro.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CoTPipeline(dspy.Module):
result = self.predictor(question=question)
return dspy.Prediction(
answer=result.answer,
reasoning=result.rationale,
reasoning=result.reasoning,
)
```

Expand Down
Loading

0 comments on commit e0610a1

Please sign in to comment.