(no commit message)
This commit is contained in:
18
main.py
18
main.py
@@ -24,7 +24,6 @@ class PromptToSignatureAgent(PrecompiledAgent):
|
|||||||
threshold=1.0,
|
threshold=1.0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
lm = dspy.LM(
|
lm = dspy.LM(
|
||||||
model=config.lm,
|
model=config.lm,
|
||||||
max_tokens=config.max_tokens,
|
max_tokens=config.max_tokens,
|
||||||
@@ -39,8 +38,9 @@ class PromptToSignatureAgent(PrecompiledAgent):
|
|||||||
self.signature_generator.set_lm(lm)
|
self.signature_generator.set_lm(lm)
|
||||||
self.signature_refiner.set_lm(refine_lm)
|
self.signature_refiner.set_lm(refine_lm)
|
||||||
|
|
||||||
def forward(self, prompt: str, as_dict: bool = False) -> dspy.Prediction: # returns dspy.Prediction object or dict
|
def forward(
|
||||||
|
self, prompt: str, as_dict: bool = False
|
||||||
|
) -> dspy.Prediction: # returns dspy.Prediction object or dict
|
||||||
return (
|
return (
|
||||||
self.signature_generator.generate_signature(prompt)
|
self.signature_generator.generate_signature(prompt)
|
||||||
if as_dict
|
if as_dict
|
||||||
@@ -50,7 +50,9 @@ class PromptToSignatureAgent(PrecompiledAgent):
|
|||||||
def generate_code(self, prediction: dspy.Prediction) -> str:
|
def generate_code(self, prediction: dspy.Prediction) -> str:
|
||||||
return self.signature_generator.generate_code(prediction)
|
return self.signature_generator.generate_code(prediction)
|
||||||
|
|
||||||
def validate_signature_with_feedback(self, args, pred, feedback = None, satisfied_with_score = True):
|
def validate_signature_with_feedback(
|
||||||
|
self, args, pred, feedback=None, satisfied_with_score=True
|
||||||
|
):
|
||||||
"""Validation function for dspy.Refine that asks user for feedback"""
|
"""Validation function for dspy.Refine that asks user for feedback"""
|
||||||
|
|
||||||
# Display the generated signature
|
# Display the generated signature
|
||||||
@@ -75,7 +77,9 @@ class PromptToSignatureAgent(PrecompiledAgent):
|
|||||||
return 1.0
|
return 1.0
|
||||||
else:
|
else:
|
||||||
if not feedback:
|
if not feedback:
|
||||||
raise ValueError("Feedback is required if you are not satisfied with the signature!")
|
raise ValueError(
|
||||||
|
"Feedback is required if you are not satisfied with the signature!"
|
||||||
|
)
|
||||||
|
|
||||||
print(f"📝 Feedback recorded: {feedback}")
|
print(f"📝 Feedback recorded: {feedback}")
|
||||||
return dspy.Prediction(score=0.0, feedback=feedback)
|
return dspy.Prediction(score=0.0, feedback=feedback)
|
||||||
@@ -88,8 +92,8 @@ def main():
|
|||||||
agent.push_to_hub("fadeleke/prompt-to-signature", with_code=True)
|
agent.push_to_hub("fadeleke/prompt-to-signature", with_code=True)
|
||||||
|
|
||||||
result = agent(prompt="Generate jokes by prompt")
|
result = agent(prompt="Generate jokes by prompt")
|
||||||
|
print("RESULT: ", result)
|
||||||
# Print the generated Python code
|
print("GENERATED CODE:\n\n")
|
||||||
print(agent.generate_code(result))
|
print(agent.generate_code(result))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user