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

AttributeError: 'NoneType' object has no attribute 'splitlines' #2046

Open
DSLituiev opened this issue Jan 14, 2025 · 2 comments
Open

AttributeError: 'NoneType' object has no attribute 'splitlines' #2046

DSLituiev opened this issue Jan 14, 2025 · 2 comments

Comments

@DSLituiev
Copy link

I am getting this strange error with Azure GPT4-o

llm_gpt_4o = dspy.LM(
    model="azure/gpt-4o",
    api_version=os.environ["OPENAI_API_VERSION"],
    api_base=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    max_tokens=3000,
)
dspy.configure(lm=llm_gpt_4o)

_extractor =  dspy.TypedPredictor(ExtractFromReport)

res = _extractor(query=query, source=source, cache=False, temperature = 0.03)
File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234), in with_callbacks.<locals>.wrapper(instance, *args, **kwargs)
    [232](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:232) # If no callbacks are provided, just call the function
    [233](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:233) if not callbacks:
--> [234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234)     return fn(instance, *args, **kwargs)
    [236](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:236) # Generate call ID as the unique identifier for the call, this is useful for instrumentation.
    [237](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:237) call_id = uuid.uuid4().hex

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/primitives/program.py:24](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/primitives/program.py:24), in Module.__call__(self, *args, **kwargs)
     [22](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/primitives/program.py:22) @with_callbacks
     [23](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/primitives/program.py:23) def __call__(self, *args, **kwargs):
---> [24](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/primitives/program.py:24)     return self.forward(*args, **kwargs)

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:322](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:322), in TypedPredictor.forward(self, **kwargs)
    [320](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:320) signature = self._prepare_signature()
    [321](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:321) for try_i in range(self.max_retries):
--> [322](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:322)     result = self.predictor(**modified_kwargs, new_signature=signature)
    [323](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:323)     errors = {}
    [324](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/functional/functional.py:324)     parsed_results = []

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234), in with_callbacks.<locals>.wrapper(instance, *args, **kwargs)
    [232](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:232) # If no callbacks are provided, just call the function
    [233](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:233) if not callbacks:
--> [234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234)     return fn(instance, *args, **kwargs)
    [236](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:236) # Generate call ID as the unique identifier for the call, this is useful for instrumentation.
    [237](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:237) call_id = uuid.uuid4().hex

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:93](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:93), in Predict.__call__(self, **kwargs)
     [91](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:91) @with_callbacks
     [92](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:92) def __call__(self, **kwargs):
---> [93](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:93)     return self.forward(**kwargs)

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:127](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:127), in Predict.forward(self, **kwargs)
    [124](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:124) import dspy
    [126](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:126) if isinstance(lm, dspy.LM):
--> [127](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:127)     completions = v2_5_generate(lm, config, signature, demos, kwargs, _parse_values=self._parse_values)
    [128](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:128) else:
    [129](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:129)     warn_once(
    [130](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:130)         "\t*** In DSPy 2.5, all LM clients except `dspy.LM` are deprecated, "
    [131](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:131)         "underperform, and are about to be deleted. ***\n"
   (...)
    [136](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:136)         " \t\thttps://github.com/stanfordnlp/dspy/blob/main/examples/migration.ipynb"
    [137](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:137)     )

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:234), in v2_5_generate(lm, lm_kwargs, signature, demos, inputs, _parse_values)
    [230](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:230) import dspy
    [232](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:232) adapter = dspy.settings.adapter or dspy.ChatAdapter()
--> [234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:234) return adapter(
    [235](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:235)     lm, lm_kwargs=lm_kwargs, signature=signature, demos=demos, inputs=inputs, _parse_values=_parse_values
    [236](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/predict/predict.py:236) )

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:46](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:46), in Adapter.__call__(self, lm, lm_kwargs, signature, demos, inputs, _parse_values)
     [44](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:44) if _parse_values and not isinstance(self, JSONAdapter):
     [45](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:45)     return JSONAdapter()(lm, lm_kwargs, signature, demos, inputs, _parse_values=_parse_values)
---> [46](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:46) raise e

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:30](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:30), in Adapter.__call__(self, lm, lm_kwargs, signature, demos, inputs, _parse_values)
     [27](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:27) if isinstance(output, dict):
     [28](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:28)     output, output_logprobs = output["text"], output["logprobs"]
---> [30](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:30) value = self.parse(signature, output, _parse_values=_parse_values)
     [32](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:32) assert set(value.keys()) == set(signature.output_fields.keys()), \
     [33](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:33)     f"Expected {signature.output_fields.keys()} but got {value.keys()}"
     [35](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/base.py:35) if output_logprobs is not None:

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234), in with_callbacks.<locals>.wrapper(instance, *args, **kwargs)
    [232](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:232) # If no callbacks are provided, just call the function
    [233](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:233) if not callbacks:
--> [234](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:234)     return fn(instance, *args, **kwargs)
    [236](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:236) # Generate call ID as the unique identifier for the call, this is useful for instrumentation.
    [237](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/utils/callback.py:237) call_id = uuid.uuid4().hex

File [~/Library/r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:65](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:65), in ChatAdapter.parse(self, signature, completion, _parse_values)
     [62](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:62) def parse(self, signature, completion, _parse_values=True):
     [63](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:63)     sections = [(None, [])]
---> [65](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:65)     for line in completion.splitlines():
     [66](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:66)         match = field_header_pattern.match(line.strip())
     [67](r-miniconda-arm64/dspy/lib/python3.11/site-packages/dspy/adapters/chat_adapter.py:67)         if match:

AttributeError: 'NoneType' object has no attribute 'splitlines'

Unfortunately I cannot share the prompt

@DSLituiev
Copy link
Author

pip freeze | grep dspy

dspy==2.5.43
dspy-ai==2.5.43

@christopher-hoernle
Copy link

christopher-hoernle commented Jan 15, 2025

I can not reproduce this. For me "TypedPredictor" works although its depricated.
Both of the following is working (also with your version):

import dspy

llm = dspy.LM("azure/gpt-4o", api_key=azure_api_key, api_version=api_version, api_base=api_base_url)

class BasicQA(dspy.Signature):
    """Answer questions with short factoid answers."""
    question = dspy.InputField()
    answer = dspy.OutputField(desc="often between 1 and 5 words")

generate_answer = dspy.Predict(BasicQA)

answer = generate_answer(question="What is the capital of France?")
print(answer)
class BasicQA(dspy.Signature):
    """Answer questions with short factoid answers."""
    question: str = dspy.InputField()
    answer: str = dspy.OutputField(desc="often between 1 and 5 words")

#Pass signature to Predict module
generate_answer = dspy.TypedPredictor(BasicQA)

answer = generate_answer(question="What is the capital of France?")
print(answer)

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