get_ipython().run_line_magic('load_ext', 'autoreload')
get_ipython().run_line_magic('autoreload', '2')
get_ipython().run_line_magic('pip', 'install datasets')



import datasets
ds = datasets.load_dataset("openai_humaneval")
ds['test'][0]



import dspy, dotenv, os
dotenv.load_dotenv(os.path.expanduser("~/.env"))  # load OpenAI API key from .env file
lm = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=4000)
dspy.settings.configure(lm=lm)

predictor = dspy.Predict("question -> answer")
print(predictor(question="What is the capital of France?"))



from dspy import InputField, OutputField, Signature
from dspy.functional import TypedPredictor
import pydantic

class PythonCode(pydantic.BaseModel):
    code: str

    @pydantic.field_validator('code')
    def check_syntax(cls, v):
        try:
            compile(v, "<string>", "exec")
        except SyntaxError as e:
            raise ValueError(f"Code is not syntactically valid: {e}")
            
        return v

class CodeSignature(Signature):
    prompt: str = InputField()
    test: PythonCode = 
InputField()