From 40fcbe88a4ed8cd090486229c1ef9757f7a0d8cf Mon Sep 17 00:00:00 2001 From: Madhu Date: Sun, 26 Jan 2025 19:18:49 +0530 Subject: [PATCH] broswer use with anthropic working fine --- .../ai_meme_generator_browseruse/main.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ai_agent_tutorials/ai_meme_generator_browseruse/main.py diff --git a/ai_agent_tutorials/ai_meme_generator_browseruse/main.py b/ai_agent_tutorials/ai_meme_generator_browseruse/main.py new file mode 100644 index 0000000..1c24ee0 --- /dev/null +++ b/ai_agent_tutorials/ai_meme_generator_browseruse/main.py @@ -0,0 +1,37 @@ +import asyncio +from browser_use import Agent, SystemPrompt +from langchain_google_genai import ChatGoogleGenerativeAI +from langchain_openai import ChatOpenAI +from langchain_anthropic import ChatAnthropic + +async def generate_meme(query: str) -> None: + api_key = "A" # Replace with your actual DeepSeek API key + llm = ChatAnthropic( + model="claude-3-5-sonnet-20240620", + api_key=api_key + ) + + task_description = ( + "You are a meme generator expert. You are given a query and you need to generate a meme for it.\n" + "1. Go to https://imgflip.com/memetemplates \n" + "2. Click on the Search bar in the middle and search for ONLY ONE MAIN ACTION VERB (like 'bully', 'laugh', 'cry') in this query: '{0}'\n" + "3. Choose any meme template that metaphorically fits the meme topic: '{0}'\n" + " by clicking on the 'Add Caption' button below it\n" + "4. Write a Top Text (setup/context) and Bottom Text (punchline/outcome) related to '{0}'.\n" + "5. Check the preview making sure it is funny and a meaningful meme. Adjust text directly if needed. \n" + "6. Look at the meme and text on it, if it doesnt make sense, PLEASE retry by filling the text boxes with different text. \n" + "7. Click on the Generate meme button to generate the meme\n" + ).format(query) + + agent = Agent( + task=task_description, + llm=llm, + max_actions_per_step=5, + max_failures=25 + ) + + await agent.run() + +if __name__ == '__main__': + query = "Elon Musk bullying sam altman about trump winning the election" + asyncio.run(generate_meme(query))