Skip to content

Commit c4ef98f

Browse files
Ryzhtusanakin87
andauthored
feat: add DSPySignatureChatGenerator (#2831)
* Draft DSPy generators implementation * Addded tests * Remove generator, tests, and updates as discussed * Applied formatting * Add pydoc * Updates after review: imports, tests, project file * PR Review fixes * ReAct and Serialization/Deserializaion examples * Renamed DSPyChatGenerator into DSPySignatureChatGenerator * Add author * Fmt lint * Remove streaming_callback logic for now * Remove init files * Added an empty py.typed file * Add Github workflow * Fix linter warnings and errors * Remove double backticks * Update github workflow * Explicit type serialization * Fix silent fallbacks and added tests for such cases * Update .github/workflows/dspy.yml * Update .github/workflows/dspy.yml * Removed signature serialization example * Added ruff rules related to docstrings * Fix dspy version and avoid malicious litellm versions * Added "D102", "D103" to the test file ignores * test coverage support * llm set on the module level, not global --------- Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com>
1 parent 9e0f6ec commit c4ef98f

15 files changed

Lines changed: 1566 additions & 0 deletions

File tree

.github/workflows/CI_coverage_comment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- "Test / cohere"
1616
- "Test / cometapi"
1717
- "Test / deepeval"
18+
- "Test / dspy"
1819
- "Test / elasticsearch"
1920
- "Test / faiss"
2021
- "Test / fastembed"

.github/workflows/dspy.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# This workflow comes from https://github.com/ofek/hatch-mypyc
2+
# https://github.com/ofek/hatch-mypyc/blob/5a198c0ba8660494d02716cfc9d79ce4adfb1442/.github/workflows/test.yml
3+
name: Test / dspy
4+
5+
on:
6+
schedule:
7+
- cron: "0 0 * * *"
8+
pull_request:
9+
paths:
10+
- "integrations/dspy/**"
11+
- "!integrations/dspy/*.md"
12+
- ".github/workflows/dspy.yml"
13+
push:
14+
branches:
15+
- main
16+
paths:
17+
- "integrations/dspy/**"
18+
- "!integrations/dspy/*.md"
19+
- ".github/workflows/dspy.yml"
20+
21+
defaults:
22+
run:
23+
working-directory: integrations/dspy
24+
25+
concurrency:
26+
group: dspy-${{ github.head_ref || github.sha }}
27+
cancel-in-progress: true
28+
29+
env:
30+
PYTHONUNBUFFERED: "1"
31+
FORCE_COLOR: "1"
32+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
33+
TEST_MATRIX_OS: '["ubuntu-latest", "windows-latest", "macos-latest"]'
34+
TEST_MATRIX_PYTHON: '["3.10", "3.14"]'
35+
36+
jobs:
37+
compute-test-matrix:
38+
runs-on: ubuntu-slim
39+
defaults:
40+
run:
41+
working-directory: .
42+
outputs:
43+
os: ${{ steps.set.outputs.os }}
44+
python-version: ${{ steps.set.outputs.python-version }}
45+
steps:
46+
- id: set
47+
run: |
48+
echo 'os=${{ github.event_name == 'push' && '["ubuntu-latest"]' || env.TEST_MATRIX_OS }}' >> "$GITHUB_OUTPUT"
49+
echo 'python-version=${{ github.event_name == 'push' && '["3.10"]' || env.TEST_MATRIX_PYTHON }}' >> "$GITHUB_OUTPUT"
50+
51+
run:
52+
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
53+
needs: compute-test-matrix
54+
runs-on: ${{ matrix.os }}
55+
permissions:
56+
contents: write
57+
pull-requests: write
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
os: ${{ fromJSON(needs.compute-test-matrix.outputs.os) }}
62+
python-version: ${{ fromJSON(needs.compute-test-matrix.outputs.python-version) }}
63+
64+
steps:
65+
- name: Support longpaths
66+
if: matrix.os == 'windows-latest'
67+
working-directory: .
68+
run: git config --system core.longpaths true
69+
70+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
71+
72+
- name: Set up Python ${{ matrix.python-version }}
73+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
74+
with:
75+
python-version: ${{ matrix.python-version }}
76+
77+
- name: Install Hatch
78+
run: pip install hatch
79+
80+
- name: Lint
81+
if: github.event_name != 'push' && matrix.python-version == '3.10' && runner.os == 'Linux'
82+
run: hatch run fmt-check && hatch run test:types
83+
84+
- name: Run unit tests
85+
run: hatch run test:unit-cov-retry
86+
87+
# On PR: generates coverage comment artifact. On push to main: stores coverage baseline on data branch.
88+
- name: Store unit tests coverage
89+
if: matrix.python-version == '3.10' && runner.os == 'Linux' && github.event_name != 'schedule'
90+
uses: py-cov-action/python-coverage-comment-action@7188638f871f721a365d644f505d1ff3df20d683 # v3.40
91+
with:
92+
GITHUB_TOKEN: ${{ github.token }}
93+
COVERAGE_PATH: integrations/dspy
94+
SUBPROJECT_ID: dspy
95+
COMMENT_ARTIFACT_NAME: coverage-comment-dspy
96+
97+
- name: Run integration tests
98+
run: hatch run test:integration-cov-append-retry
99+
100+
- name: Store combined coverage
101+
if: github.event_name == 'push'
102+
uses: py-cov-action/python-coverage-comment-action@7188638f871f721a365d644f505d1ff3df20d683 # v3.40
103+
with:
104+
GITHUB_TOKEN: ${{ github.token }}
105+
COVERAGE_PATH: integrations/dspy
106+
SUBPROJECT_ID: dspy-combined
107+
COMMENT_ARTIFACT_NAME: coverage-comment-dspy-combined
108+
109+
- name: Run unit tests with lowest direct dependencies
110+
if: github.event_name != 'push'
111+
run: |
112+
hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt
113+
hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt
114+
hatch run test:unit
115+
116+
- name: Nightly - run unit tests with Haystack main branch
117+
if: github.event_name == 'schedule'
118+
run: |
119+
hatch env prune
120+
hatch -e test env run -- uv pip install git+https://github.com/deepset-ai/haystack.git@main
121+
hatch run test:unit
122+
123+
notify-slack-on-failure:
124+
needs: run
125+
if: failure() && github.event_name == 'schedule'
126+
runs-on: ubuntu-slim
127+
steps:
128+
- uses: deepset-ai/notify-slack-action@3cda73b77a148f16f703274198e7771340cf862b # v1
129+
with:
130+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL_NOTIFICATIONS }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Please check out our [Contribution Guidelines](CONTRIBUTING.md) for all the deta
3737
| [cohere-haystack](integrations/cohere/) | Embedder, Generator, Ranker | [![PyPI - Version](https://img.shields.io/pypi/v/cohere-haystack.svg)](https://pypi.org/project/cohere-haystack) | [![Test / cohere](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/cohere.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/cohere.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-cohere/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-cohere/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-cohere-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-cohere-combined/htmlcov/index.html) |
3838
| [cometapi-haystack](integrations/cometapi/) | Generator | [![PyPI - Version](https://img.shields.io/pypi/v/cometapi-haystack.svg)](https://pypi.org/project/cometapi-haystack) | [![Test / cometapi](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/cometapi.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/cometapi.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-cometapi/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-cometapi/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-cometapi-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-cometapi-combined/htmlcov/index.html) |
3939
| [deepeval-haystack](integrations/deepeval/) | Evaluator | [![PyPI - Version](https://img.shields.io/pypi/v/deepeval-haystack.svg)](https://pypi.org/project/deepeval-haystack) | [![Test / deepeval](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/deepeval.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/deepeval.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-deepeval/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-deepeval/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-deepeval-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-deepeval-combined/htmlcov/index.html) |
40+
| [dspy-haystack](integrations/dspy/) | Generator | [![PyPI - Version](https://img.shields.io/pypi/v/dspy-haystack.svg)](https://pypi.org/project/dspy-haystack) | [![Test / dspy](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/dspy.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/dspy.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-dspy/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-dspy/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-dspy-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-dspy-combined/htmlcov/index.html) |
4041
| [elasticsearch-haystack](integrations/elasticsearch/) | Document Store | [![PyPI - Version](https://img.shields.io/pypi/v/elasticsearch-haystack.svg)](https://pypi.org/project/elasticsearch-haystack) | [![Test / elasticsearch](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/elasticsearch.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/elasticsearch.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-elasticsearch/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-elasticsearch/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-elasticsearch-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-elasticsearch-combined/htmlcov/index.html) |
4142
| [faiss-haystack](integrations/faiss/) | Document Store | [![PyPI - Version](https://img.shields.io/pypi/v/faiss-haystack.svg)](https://pypi.org/project/faiss-haystack) | [![Test / faiss](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/faiss.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/faiss.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-faiss/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-faiss/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-faiss-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-faiss-combined/htmlcov/index.html) |
4243
| [fastembed-haystack](integrations/fastembed/) | Embedder, Ranker | [![PyPI - Version](https://img.shields.io/pypi/v/fastembed-haystack.svg)](https://pypi.org/project/fastembed-haystack/) | [![Test / fastembed](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/fastembed.yml/badge.svg)](https://github.com/deepset-ai/haystack-core-integrations/actions/workflows/fastembed.yml) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-fastembed/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-fastembed/htmlcov/index.html) | [![Coverage badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/deepset-ai/haystack-core-integrations/python-coverage-comment-action-data-fastembed-combined/endpoint.json&label=)](https://htmlpreview.github.io/?https://github.com/deepset-ai/haystack-core-integrations/blob/python-coverage-comment-action-data-fastembed-combined/htmlcov/index.html) |

0 commit comments

Comments
 (0)