dspy
dspy copied to clipboard
feat(core): add gradle plugin
Here's my simple example program.
import dspy
from dspy.predict.retry import Retry
from dspy.primitives.assertions import (
assert_transform_module,
suggest_backtrack_handler,
)
turbo = dspy.OpenAI(model="gpt-3.5-turbo", max_tokens=1000)
dspy.settings.configure(lm=turbo, trace=[])
class GenerateQuestions(dspy.Signature):
concept = dspy.InputField(desc="a concept to generate questions for")
questions_and_answers = dspy.OutputField(
desc="five questions and answers about the concept in the form 'question = answer'",
format=lambda x: x,
)
class Program(dspy.Module):
def __init__(self):
super().__init__()
self.generate_questions = dspy.Predict(GenerateQuestions)
def forward(self, concept):
qas = self.generate_questions(
concept=concept
).questions_and_answers.splitlines()
dspy.Suggest(
len(qas) == 5,
f"Generate five questions about that concept. Found {len(qas)} questions.",
)
dspy.Suggest(
all("?" not in qa for qa in qas),
f"Questions should not end with a question mark.",
)
dspy.Suggest(
all(len(qa.split(" ")) <= "3" for qa in qas),
f"Questions should be heavily abbreviated and less than or equal to 3 words long.",
)
return dspy.Prediction(questions_and_answers=qas)
program = assert_transform_module(
Program().map_named_predictors(Retry), suggest_backtrack_handler
)
program(concept="the moon")
turbo.inspect_history(n=1)
When the program backtracks when one of the assertions fails, calling self.generate_questions
in Program
's forward
method fails with the following error message:
Exception has occurred: TypeError
'dict' object is not callable
File "/Users/james/Projects/Python/dspy-experiments/test.py", line 26, in forward
qas = self.generate_questions(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/james/Projects/Python/dspy-experiments/test.py", line 47, in <module>
program(concept="the moon")
TypeError: 'dict' object is not callable
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Updated (UTC) |
---|---|---|---|
nx-dev | ✅ Ready (Inspect) | Visit Preview | Feb 29, 2024 5:06pm |
☁️ Nx Cloud Report
CI is running/has finished running commands for commit 6002092f0dd881c25dfa152c46273fb2a1937ff7. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this CI Pipeline Execution
✅ Successfully ran 6 targets
-
nx affected --target=e2e --base=5971ae17f619acfa5d6801cd7fd991877b8d4cd1 --head=6002092f0dd881c25dfa152c46273fb2a1937ff7 --parallel=1
-
nx affected --targets=lint,test,build --base=5971ae17f619acfa5d6801cd7fd991877b8d4cd1 --head=6002092f0dd881c25dfa152c46273fb2a1937ff7 --parallel=3
-
nx run-many -t check-imports check-commit check-lock-files check-codeowners documentation --parallel=1 --no-dte
-
nx-cloud record -- nx format:check --base=5971ae17f619acfa5d6801cd7fd991877b8d4cd1 --head=6002092f0dd881c25dfa152c46273fb2a1937ff7
-
nx documentation --no-dte
-
nx affected -t e2e-macos --parallel=1 --base=5971ae17f619acfa5d6801cd7fd991877b8d4cd1 --head=6002092f0dd881c25dfa152c46273fb2a1937ff7
Sent with 💌 from NxCloud.
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.