stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy-docs.vercel.app/
MIT License
18.6k stars 1.43k forks source link

NameError: name 'mistralai_api_error' is not defined #1505

Closed gideon772 closed 1 month ago

gideon772 commented 1 month ago

NameError: name 'mistralai_api_error' is not defined

Description

When trying to import MilvusRM from dspy.retrieve.milvus_rm, a NameError is raised indicating that mistralai_api_error is not defined. This error occurs in the dsp module, specifically in the Mistral class definition.

Code

from dspy.retrieve.milvus_rm import MilvusRM
from dotenv import load_dotenv
import os

load_dotenv()

retriever = MilvusRM(
    collection_name=os.getenv("ZILLIZ_CLOUD_SNOWFLAKE_COLLECTION_TABLE"),
    uri=os.getenv("MILVUS_URI"),
)

results = retriever("some question", k=5)

for result in results:
    print("Document:", result.long_text, "\n")

Error Message

NameError: name 'mistralai_api_error' is not defined

Traceback

NameError                                 Traceback (most recent call last)
Cell In[9], [line 1](vscode-notebook-cell:?execution_count=9&line=1)
----> [1](vscode-notebook-cell:?execution_count=9&line=1) from dspy.retrieve.milvus_rm import MilvusRM
      [2](vscode-notebook-cell:?execution_count=9&line=2) from dotenv import load_dotenv
      [3](vscode-notebook-cell:?execution_count=9&line=3) import os

File ~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dspy/__init__.py:1
----> [1](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dspy/__init__.py:1) import dsp
      [2](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dspy/__init__.py:2) from dsp.modules.hf_client import ChatModuleClient, HFClientSGLang, HFClientVLLM, HFServerTGI
      [4](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dspy/__init__.py:4) from .predict import *

File ~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/__init__.py:[1](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/__init__.py:1)
----> 1 from .modules import *  # noqa
      [2](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/__init__.py:2) from .primitives import *  # noqa
      [3](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/__init__.py:3) from .adapters import *  # noqa

File ~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/__init__.py:22
     [20](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/__init__.py:20) from .hf_client import Anyscale, HFClientTGI, Together
     [21](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/__init__.py:21) from .llama import *
---> [22](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/__init__.py:22) from .mistral import *
     [23](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/__init__.py:23) from .ollama import *
     [24](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/__init__.py:24) from .multi_openai import MultiOpenAI

File ~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:31
     [27](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:27)         return False
     [28](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:28)     return True
---> [31](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:31) class Mistral(LM):
     [32](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:32)     """Wrapper around Mistral AI's API.
     [33](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:33) 
     [34](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:34)     Currently supported models include `mistral-small-latest`, `mistral-medium-latest`, `mistral-large-latest`.
     [35](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:35)     """
     [37](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:37)     def __init__(
     [38](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:38)         self,
     [39](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:39)         model: str = "mistral-medium-latest",
     [40](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:40)         api_key: Optional[str] = None,
     [41](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:41)         **kwargs,
     [42](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:42)     ):

File ~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:101, in Mistral()
     [95](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:95)     self.history.append(history)
     [97](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:97)     return response
     [99](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:99) @backoff.on_exception(
    [100](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:100)     backoff.expo,
--> [101](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:101)     (mistralai_api_error),
    [102](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:102)     max_time=settings.backoff_time,
    [103](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:103)     on_backoff=backoff_hdlr,
    [104](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:104)     giveup=giveup_hdlr,
    [105](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:105) )
    [106](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:106) def request(self, prompt: str, **kwargs):
    [107](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:107)     """Handles retrieval of completions from Mistral AI whilst handling API errors."""
    [108](https://vscode-remote+ssh-002dremote-002b116-002e74-002e253-002e227.vscode-resource.vscode-cdn.net/home/ameya/gideon/ameya-service-database/examples/~/.virtualenvs/ameya-service-database/lib/python3.11/site-packages/dsp/modules/mistral.py:108)     prompt = prompt + "Follow the format only once !"

NameError: name 'mistralai_api_error' is not defined

Steps to Reproduce

  1. Set up a Python environment with dspy installed
  2. Attempt to import MilvusRM from dspy.retrieve.milvus_rm

Environment

gideon772 commented 1 month ago

Hi I figured out what is the problem can I work on that?

arnavsinghvi11 commented 1 month ago

Hi @gideon772 , is this resolved with #1437 ?

gideon772 commented 1 month ago

Yes, the changes made in #1437 are correct. Why is it still in the package, even though I installed the recent version?