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