The RexiaAIImageAnalysis class is a specialized tool in the ReXia.AI framework designed to analyze images. It works with any vision or multimodal model and has been tested on GPT-4o and llava phi 3. This tool allows text-based models to call a vision model to analyze images.
api_key: The API key for OpenAI.vision_model_base_url: The base URL for the vision model.vision_model: The name of the vision model.
Initializes a RexiaAIImageAnalysis instance.
Parameters:
vision_model_base_url: The base URL for the vision model.vision_model: The name of the vision model.api_key: The API key for OpenAI.
Processes an image and gets a response.
Parameters:
query: The query to analyze.image_path: The path to the image file.
Returns:
- The analysis result.
Gets image data from a URL or a local path.
Parameters:
image_path: The path to the image file.
Returns:
- The image data.
Returns the tool as a JSON object for ReXia.AI.
Returns:
- The tool as a JSON object.
Returns the tool as a dictionary object for ReXia.AI.
Returns:
- The tool as a dictionary object.
Here's an example of how to use the RexiaAIImageAnalysis class:
from rexia_ai.tools import RexiaAIImageAnalysis
from rexia_ai.agent import Agent
from rexia_ai.workflows import SimpleToolWorkflow
# Initialize the RexiaAIImageAnalysis instance
image_analysis_tool = RexiaAIImageAnalysis(
vision_model_base_url="https://api.openai.com/v1",
vision_model="gpt-4-vision-preview",
api_key="your-openai-api-key"
)
# Create an Agent instance with SimpleToolWorkflow and the image analysis tool
agent = Agent(
llm=..., # Your language model instance
task="Analyze the content of this image",
workflow=SimpleToolWorkflow,
verbose=True,
tools={"image_analysis": image_analysis_tool}
)
# Run the agent
result = agent.invoke(
"What is the main topic of this image?",
image_path="https://example.com/image.jpg"
)
print(result)base64requestsopenai- ReXia.AI components (
BaseTool,LLMOutput)
Ensure all dependencies are installed and properly imported.
We welcome contributions to improve the ReXia.AI framework. Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes.
- Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.