50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from agent.agent import TweetOptimizerAgent, TweetOptimizerConfig
|
|
|
|
def main():
|
|
# create agent with default config
|
|
config = TweetOptimizerConfig()
|
|
tweet_optimizer = TweetOptimizerAgent(config)
|
|
import os
|
|
|
|
# set up test environment (replace with real API key for actual usage)
|
|
if not os.getenv("OPENROUTER_API_KEY"):
|
|
raise ValueError("OPENROUTER_API_KEY environment variable is not set")
|
|
|
|
# full optimization process
|
|
print("\n=== Full Optimization Process ===")
|
|
try:
|
|
results = tweet_optimizer(
|
|
input_text="Anthropic added a new OSS model on HuggingFace.",
|
|
iterations=10, # Reduced for testing
|
|
patience=8
|
|
)
|
|
print(f"Initial text: {results['initial_text']}")
|
|
print(f"Final tweet: {results['final_tweet']}")
|
|
print(f"Best score: {results['best_score']:.2f}")
|
|
print(f"Iterations run: {results['iterations_run']}")
|
|
print(f"Improvements found: {results['improvement_count']}")
|
|
print(f"Early stopped: {results['early_stopped']}")
|
|
except Exception as e:
|
|
print(f"Error in optimization: {e}")
|
|
|
|
# push to hub
|
|
print("\n=== Push to Hub ===")
|
|
try:
|
|
tweet_optimizer.push_to_hub(
|
|
"farouk1/tweet-optimizer-v2",
|
|
commit_message="Complete Migration",
|
|
with_code=True
|
|
)
|
|
print("Successfully pushed to hub!")
|
|
except Exception as e:
|
|
print(f"Error pushing to hub: {e}")
|
|
|
|
print("\n=== Agent Configuration ===")
|
|
print(f"Model: {config.lm}")
|
|
print(f"Categories: {config.categories}")
|
|
print(f"Max iterations: {config.max_iterations}")
|
|
print(f"Patience: {config.patience}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|