import dspy
from typing import Optional

def ai(user_prompt: str, system_prompt: Optional[str] = None) -> str:
    class QA(dspy.Signature):
        __doc__ = system_prompt
        
        user_prompt: str = dspy.InputField(desc="The user's request.")
        response: str = dspy.OutputField(desc="The text response generated by the language model.")
        
    predict = dspy.Predict(QA)
    return predict(user_prompt=user_prompt).response
    