Unit4_Final / image_question_answer_tool.py
edwin_ang_ph
update image_qa
28dbbfb
Raw
History Blame Contribute Delete
672 Bytes
from langchain_core.tools import BaseTool
from image_question_answer import ImageQuestionAnswer
from pydantic import BaseModel, Field
from typing import Type
class ImageQuestionAnswerToolArgs(BaseModel):
file_path: str = Field(description="The path to the image file")
question: str = Field(description="The question to answer")
class ImageQuestionAnswerTool(BaseTool):
name: str = "image_question_answer"
description: str = "Answer the question based on the image."
args_schema: Type[BaseModel] = ImageQuestionAnswerToolArgs
def _run(self, file_path: str, question: str) -> str:
return ImageQuestionAnswer().answer(file_path, question)