Update crew.py
Browse files
crew.py
CHANGED
@@ -61,16 +61,49 @@ def run_crew(question, file_path):
|
|
61 |
transcript = client.audio.transcriptions.create(
|
62 |
file=open(file_path, "rb"),
|
63 |
model=AUDIO_MODEL,
|
64 |
-
prompt=question
|
65 |
)
|
66 |
|
67 |
return transcript.text
|
68 |
except Exception as e:
|
69 |
raise RuntimeError(f"Failed to process audio: {str(e)}")
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
# Built-in tools
|
72 |
|
73 |
-
image_analysis_tool = VisionTool()
|
74 |
python_coding_tool = CodeInterpreterTool()
|
75 |
video_analysis_tool = YoutubeVideoSearchTool()
|
76 |
web_search_tool = SerperDevTool()
|
|
|
61 |
transcript = client.audio.transcriptions.create(
|
62 |
file=open(file_path, "rb"),
|
63 |
model=AUDIO_MODEL,
|
64 |
+
prompt=f"{question} Think step by step."
|
65 |
)
|
66 |
|
67 |
return transcript.text
|
68 |
except Exception as e:
|
69 |
raise RuntimeError(f"Failed to process audio: {str(e)}")
|
70 |
+
|
71 |
+
@tool("Image Analysis Tool")
|
72 |
+
def image_analysis_tool(question: str, file_path: str) -> str:
|
73 |
+
"""Answer a question about an image file.
|
74 |
+
|
75 |
+
Args:
|
76 |
+
question (str): Question about the image file
|
77 |
+
file_path (str): Path of the image file
|
78 |
+
|
79 |
+
Returns:
|
80 |
+
str: Answer to the question about the image file
|
81 |
+
|
82 |
+
Raises:
|
83 |
+
FileNotFoundError: If the image file does not exist
|
84 |
+
RuntimeError: If processing fails"""
|
85 |
+
if not os.path.exists(file_path):
|
86 |
+
raise FileNotFoundError(f"Image file not found: {file_path}")
|
87 |
+
|
88 |
+
try:
|
89 |
+
img_b64 = get_img_b64(file_path)
|
90 |
+
|
91 |
+
client = OpenAI()
|
92 |
+
|
93 |
+
completion = client.chat.completions.create(
|
94 |
+
messages=[{"role": "user",
|
95 |
+
"content": [{"type": "text", "text": f"{question} Think step by step."},
|
96 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{img_b64}"}}]}],
|
97 |
+
model=IMAGE_MODEL
|
98 |
+
)
|
99 |
+
|
100 |
+
return completion.choices[0].message.content
|
101 |
+
except Exception as e:
|
102 |
+
raise RuntimeError(f"Failed to process image: {str(e)}")
|
103 |
+
|
104 |
# Built-in tools
|
105 |
|
106 |
+
#image_analysis_tool = VisionTool()
|
107 |
python_coding_tool = CodeInterpreterTool()
|
108 |
video_analysis_tool = YoutubeVideoSearchTool()
|
109 |
web_search_tool = SerperDevTool()
|