DSPy: The framework for programming—not prompting—language models
Python
(feature) Adding support for Mistral AI's API
Franck Stephane Ndzomga8bdb703ac763
diff --git a/dsp/modules/mistral.py b/dsp/modules/mistral.pyindex 6c9573cbf..dc06bdffd 100644--- a/dsp/modules/mistral.py+++ b/dsp/modules/mistral.py@@ -5,13 +5,20 @@ import backofffrom dsp.modules.lm import LMtry:+ import mistralaifrom mistralai.client import MistralClientfrom mistralai.exceptions import MistralAPIExceptionfrom mistralai.models.chat_completion import ChatCompletionResponse, ChatMessagemistralai_api_error = MistralAPIExceptionexcept ImportError:mistralai_api_error = Exception- print("Not loading Mistral AI because it is not installed.")+ mistralai = None+++if mistralai is None:+ raise ImportError(+ "Not loading Mistral AI because it is not installed. Install it with `pip install mistralai`.",+ )def backoff_hdlr(details):diff --git a/pyproject.toml b/pyproject.tomlindex 88322d2db..2f17b37f0 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -30,7 +30,7 @@ dependencies = ["datasets~=2.14.6,<3.0.0","requests","optuna",- "pydantic~=2.5.0,<2.5.3",+ "pydantic==2.5.0",][project.optional-dependencies]@@ -39,6 +39,7 @@ qdrant = ["qdrant-client~=1.6.2", "fastembed~=0.1.0"]marqo = ["marqo"]pinecone = ["pinecone-client~=2.2.4"]weaviate = ["weaviate-client~=3.26.1"]+mistralai = ["mistralai~=0.1.3"]docs = ["sphinx>=4.3.0","furo>=2023.3.27",@@ -102,7 +103,7 @@ sphinx_rtd_theme = { version = "*", optional = true }autodoc_pydantic = { version = "*", optional = true }sphinx-reredirects = { version = "^0.1.2", optional = true }sphinx-automodapi = { version = "0.16.0", optional = true }-mistralai = "^0.1.3"+mistralai = { version = "0.1.3", optional = true }[tool.poetry.group.dev.dependencies]@@ -116,6 +117,7 @@ qdrant = ["qdrant-client", "fastembed"]marqo = ["marqo"]pinecone = ["pinecone-client"]weaviate = ["weaviate-client"]+mistralai = ["mistralai"]docs = ["sphinx","furo",diff --git a/requirements.txt b/requirements.txtindex add0db1d7..dcf93932a 100644--- a/requirements.txt+++ b/requirements.txt@@ -8,6 +8,5 @@ tqdmdatasetsrequestsoptuna-pydantic==2.5.0,<2.5.3-mistralai+pydantic==2.5.0# To be deleteddiff --git a/setup.py b/setup.pyindex 3f3bb1858..44b005156 100644--- a/setup.py+++ b/setup.py@@ -1,42 +1,43 @@from setuptools import find_packages, setup-# Read the content of the README file-with open('README.md', encoding='utf-8') as f:- long_description = f.read()+# Read the content of the README file+with open('README.md', encoding='utf-8') as f:+ long_description = f.read()-# Read the content of the requirements.txt file-with open('requirements.txt', encoding='utf-8') as f:- requirements = f.read().splitlines()+# Read the content of the requirements.txt file+with open('requirements.txt', encoding='utf-8') as f:+ requirements = f.read().splitlines()-setup(- name="dspy-ai",- version="2.3.6",- description="DSPy",- long_description=long_description,- long_description_content_type='text/markdown',- url="https://github.com/stanfordnlp/dsp",- author="Omar Khattab",- author_email="[email protected]",- license="MIT License",- packages=find_packages(include=['dsp.*', 'dspy.*', 'dsp', 'dspy']),- python_requires='>=3.9',- install_requires=requirements,+setup(+ name="dspy-ai",+ version="2.3.6",+ description="DSPy",+ long_description=long_description,+ long_description_content_type='text/markdown',+ url="https://github.com/stanfordnlp/dsp",+ author="Omar Khattab",+ author_email="[email protected]",+ license="MIT License",+ packages=find_packages(include=['dsp.*', 'dspy.*', 'dsp', 'dspy']),+ python_requires='>=3.9',+ install_requires=requirements,extras_require={"chromadb": ["chromadb~=0.4.14"],"qdrant": ["qdrant-client", "fastembed"],"marqo": ["marqo~=3.1.0"],- "mongodb": ["pymongo~=3.12.0"],- "pinecone": ["pinecone-client~=2.2.4"],- "weaviate": ["weaviate-client~=3.26.1"],+ "mongodb": ["pymongo~=3.12.0"],+ "pinecone": ["pinecone-client~=2.2.4"],+ "weaviate": ["weaviate-client~=3.26.1"],"faiss-cpu": ["sentence_transformers", "faiss-cpu"],- },- classifiers=[- "Development Status :: 3 - Alpha",- "Intended Audience :: Science/Research",- "License :: OSI Approved :: MIT License",- "Operating System :: POSIX :: Linux",- "Programming Language :: Python :: 3",- "Programming Language :: Python :: 3.8",- "Programming Language :: Python :: 3.9",- ],-)+ "mistralai": ["mistralai~=0.1.3"],+ },+ classifiers=[+ "Development Status :: 3 - Alpha",+ "Intended Audience :: Science/Research",+ "License :: OSI Approved :: MIT License",+ "Operating System :: POSIX :: Linux",+ "Programming Language :: Python :: 3",+ "Programming Language :: Python :: 3.8",+ "Programming Language :: Python :: 3.9",+ ],+)