Complete Migration
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# DSPy Tweet Optimizer
|
||||
# DSPy Tweet Optimizer - Modaic Agent
|
||||
|
||||

|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from .index import TweetOptimizerAgent, TweetOptimizerConfig
|
||||
|
||||
__all__ = ["TweetOptimizerAgent", "TweetOptimizerConfig"]
|
||||
|
||||
@@ -32,7 +32,7 @@ class HillClimbingOptimizer:
|
||||
Yields:
|
||||
Tuple of (current_tweet, evaluation_result, is_improvement, patience_counter, generator_inputs, evaluator_inputs)
|
||||
"""
|
||||
# Generate initial tweet
|
||||
# generate initial tweet
|
||||
generator_inputs = {
|
||||
"input_text": initial_text,
|
||||
"current_tweet": "",
|
||||
@@ -67,10 +67,10 @@ class HillClimbingOptimizer:
|
||||
evaluator_inputs,
|
||||
)
|
||||
|
||||
for iteration in range(1, self.max_iterations):
|
||||
# Generate improved tweet with previous evaluation as feedback
|
||||
for _ in range(1, self.max_iterations):
|
||||
# generate improved tweet with previous evaluation as feedback
|
||||
try:
|
||||
# Format evaluation for display in generator inputs
|
||||
# format evaluation for display in generator inputs
|
||||
eval_text = format_evaluation_for_generator(best_score)
|
||||
|
||||
generator_inputs = {
|
||||
@@ -85,7 +85,7 @@ class HillClimbingOptimizer:
|
||||
previous_evaluation=best_score,
|
||||
)
|
||||
|
||||
# Evaluate candidate
|
||||
# evaluate candidate
|
||||
evaluator_inputs = {
|
||||
"original_text": initial_text,
|
||||
"current_best_tweet": best_tweet,
|
||||
@@ -98,7 +98,7 @@ class HillClimbingOptimizer:
|
||||
current_best_tweet=best_tweet,
|
||||
)
|
||||
|
||||
# Check if candidate is better (hill climbing condition)
|
||||
# check if candidate is better (hill climbing condition)
|
||||
is_improvement = candidate_score > best_score
|
||||
|
||||
if is_improvement:
|
||||
@@ -124,12 +124,12 @@ class HillClimbingOptimizer:
|
||||
evaluator_inputs,
|
||||
)
|
||||
|
||||
# Early stopping if no improvement for 'patience' iterations
|
||||
# early stopping if no improvement for 'patience' iterations
|
||||
if patience_counter >= self.patience:
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
# If generation fails, yield current best
|
||||
# if generation fails, yield current best
|
||||
patience_counter += 1
|
||||
evaluator_inputs = {
|
||||
"original_text": initial_text,
|
||||
|
||||
Reference in New Issue
Block a user