Skip to content

Commit

Permalink
Merge pull request #1546 from stanfordnlp/typed-predictor-lm-compatib…
Browse files Browse the repository at this point in the history
…ility

Make output processing in typed Pred compatible to LM Module
  • Loading branch information
okhat authored Sep 27, 2024
2 parents 3ba9e66 + e8c7db8 commit dac7030
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dspy/functional/functional.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import inspect
import json
import ujson
import typing
from typing import Annotated, Callable, List, Tuple, Union # noqa: UP035

import inspect
import pydantic
import ujson

from pydantic.fields import FieldInfo
from typing import Annotated, Callable, List, Tuple, Union # noqa: UP035

import dsp
import dspy
from dsp.adapters import passages2text
from dspy.primitives.prediction import Prediction
Expand Down Expand Up @@ -400,7 +401,12 @@ def _func_to_signature(func):

def _unwrap_json(output, from_json: Callable[[str], Union[pydantic.BaseModel, str, None]]):
try:
parsing_result = from_json(output)
parsing_result = None
if isinstance(dsp.settings.lm, dspy.LM):
parsing_result = output
else:
parsing_result = from_json(output)

if isinstance(parsing_result, pydantic.BaseModel):
return parsing_result.model_dump_json()
else:
Expand Down

0 comments on commit dac7030

Please sign in to comment.