parent
efd2b9b22f
commit
b1d3aa54a8
After Width: | Height: | Size: 74 KiB |
@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from swarms.models.gpt4_vision_api import GPT4VisionAPI
|
||||||
|
from swarms.prompts.visual_cot import VISUAL_CHAIN_OF_THOUGHT
|
||||||
|
from swarms.structs import Agent
|
||||||
|
|
||||||
|
# Load the environment variables
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# Get the API key from the environment
|
||||||
|
api_key = os.environ.get("OPENAI_API_KEY")
|
||||||
|
|
||||||
|
# Initialize the language model
|
||||||
|
llm = GPT4VisionAPI(
|
||||||
|
openai_api_key=api_key,
|
||||||
|
max_tokens=500,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Initialize the task
|
||||||
|
task = "This is an eye test. What do you see?"
|
||||||
|
img = "playground/demos/multi_modal_chain_of_thought/eyetest.jpg"
|
||||||
|
|
||||||
|
## Initialize the workflow
|
||||||
|
agent = Agent(
|
||||||
|
llm=llm,
|
||||||
|
max_loops=2,
|
||||||
|
autosave=True,
|
||||||
|
sop=VISUAL_CHAIN_OF_THOUGHT,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the workflow on a task
|
||||||
|
out = agent.run(task=task, img=img)
|
||||||
|
print(out)
|
@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
def react_prompt(task: str = None):
|
||||||
|
REACT = f"""
|
||||||
|
Task Description:
|
||||||
|
Accomplish the following {task} using the reasoning guidelines below.
|
||||||
|
|
||||||
|
|
||||||
|
######### REASONING GUIDELINES #########
|
||||||
|
You're an autonomous agent that has been tasked with {task}. You have been given a set of guidelines to follow to accomplish this task. You must follow the guidelines exactly.
|
||||||
|
|
||||||
|
Step 1: Observation
|
||||||
|
|
||||||
|
Begin by carefully observing the situation or problem at hand. Describe what you see, identify key elements, and note any relevant details.
|
||||||
|
|
||||||
|
Use <observation>...</observation> tokens to encapsulate your observations.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
<observation> [Describe your initial observations of the task or problem here.] </observation>
|
||||||
|
|
||||||
|
Step 2: Thought Process
|
||||||
|
|
||||||
|
Analyze the observations. Consider different angles, potential challenges, and any underlying patterns or connections.
|
||||||
|
|
||||||
|
Think about possible solutions or approaches to address the task.
|
||||||
|
|
||||||
|
Use <thought>...</thought> tokens to encapsulate your thinking process.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
<thought> [Explain your analysis of the observations, your reasoning behind potential solutions, and any assumptions or considerations you are making.] </thought>
|
||||||
|
|
||||||
|
Step 3: Action Planning
|
||||||
|
|
||||||
|
Based on your thoughts and analysis, plan a series of actions to solve the problem or complete the task.
|
||||||
|
|
||||||
|
Detail the steps you intend to take, resources you will use, and how these actions will address the key elements identified in your observations.
|
||||||
|
|
||||||
|
Use <action>...</action> tokens to encapsulate your action plan.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
<action> [List the specific actions you plan to take, including any steps to gather more information or implement a solution.] </action>
|
||||||
|
|
||||||
|
Step 4: Execute and Reflect
|
||||||
|
|
||||||
|
Implement your action plan. As you proceed, continue to observe and think, adjusting your actions as needed.
|
||||||
|
|
||||||
|
Reflect on the effectiveness of your actions and the outcome. Consider what worked well and what could be improved.
|
||||||
|
|
||||||
|
Use <observation>...</observation>, <thought>...</thought>, and <action>...</action> tokens as needed to describe this ongoing process.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
<observation> [New observations during action implementation.] </observation>
|
||||||
|
<thought> [Thoughts on how the actions are affecting the situation, adjustments needed, etc.] </thought>
|
||||||
|
<action> [Adjusted or continued actions to complete the task.] </action>
|
||||||
|
|
||||||
|
Guidance:
|
||||||
|
Remember, your goal is to provide a transparent and logical process that leads from observation to effective action. Your responses should demonstrate clear thinking, an understanding of the problem, and a rational approach to solving it. The use of tokens helps to structure your response and clarify the different stages of your reasoning and action.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return REACT
|
Loading…
Reference in new issue