Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve module produces error when using model with dspy.AzureOpenAI #1070

Open
FPirazz opened this issue May 28, 2024 · 1 comment
Open

Comments

@FPirazz
Copy link

FPirazz commented May 28, 2024

Hello everybody,
I've been having this error that's presents itself while using an Azure model that's been loaded with dspy's AzureOpenAI, that being that when using the Retrieve module, an error message is produced regarding an unexpected keyword (more details below), other modules work perfectly fine. I've also tried two different models, again both from Azure, again loaded with AzureOpenAI, while also trying different versions of both dspy's and the openai package but again with no solution. As of the post time, versions used are:

  • dspy-ai 2.4.9
  • openai 1.30.4.

Code to reproduce:

import dspy

turbo = dspy.AzureOpenAI(model="mg-gpt35-turbo",
                    api_key=API_KEY,
                    api_base=API_BASE,
                    api_version=API_VERSION)

dspy.settings.configure(lm=turbo)

Or

import dspy

turbo = dspy.AzureOpenAI(model="mg-gpt-4-0613",
                    api_key=API_KEY,
                    api_base=API_BASE,
                    api_version=API_VERSION)

dspy.settings.configure(lm=turbo)

To instantiate the model, while below a basic Retrieve example gotten straight from dspy's tutorial colabs:
For the dataset:

from dspy.datasets import HotPotQA

# Load the dataset.
dataset = HotPotQA(train_seed=1, train_size=20, eval_seed=2023, dev_size=50, test_size=0)

# Tell DSPy that the 'question' field is the input. Any other fields are labels and/or metadata.
trainset = [x.with_inputs('question') for x in dataset.train]
devset = [x.with_inputs('question') for x in dataset.dev]

len(trainset), len(devset)

The Retrieve module:

dev_example = devset[0]

retrieve = dspy.Retrieve(k=3)
topK_passages = retrieve(dev_example.question).passages

print(f"Top {retrieve.k} passages for question: {dev_example.question} \n", '-' * 30, '\n')

for idx, passage in enumerate(topK_passages):
    print(f'{idx+1}]', passage, '\n')

The last code block will otuput this message block error (I only copied the end of the error block):

File /opt/conda/envs/dspy/lib/python3.10/site-packages/joblib/memory.py:856, in MemorizedFunc.call(self, *args, **kwargs)
    854 if self._verbose > 0:
    855     print(format_call(self.func, args, kwargs))
--> 856 output = self.func(*args, **kwargs)
    857 self.store_backend.dump_item(
    858     [func_id, args_id], output, verbose=self._verbose)
    860 duration = time.time() - start_time

File /opt/conda/envs/dspy/lib/python3.10/site-packages/dsp/modules/azure_openai.py:278, in v1_chat_request.<locals>.v1_cached_gpt3_turbo_request_v2_wrapped.<locals>.v1_cached_gpt3_turbo_request_v2(**kwargs)
    276 if "stringify_request" in kwargs:
    277     kwargs = json.loads(kwargs["stringify_request"])
--> 278 return client.chat.completions.create(**kwargs)

File /opt/conda/envs/dspy/lib/python3.10/site-packages/openai/_utils/_utils.py:277, in required_args.<locals>.inner.<locals>.wrapper(*args, **kwargs)
    275             msg = f"Missing required argument: {quote(missing[0])}"
    276     raise TypeError(msg)
--> 277 return func(*args, **kwargs)

TypeError: Completions.create() got an unexpected keyword argument 'k'
@arnavsinghvi11
Copy link
Collaborator

arnavsinghvi11 commented Jun 19, 2024

Hi @FPirazz , there's an error with the retriever cell because you haven't configured an rm for the retriever to use (dspy.settings.configure(rm = ...)). Weird that the LM is getting triggered with the retrieve call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants