A programming framework for agentic AI
Re-added multimodality to mdconvert. (#330)
afourneyecde17a255a4
diff --git a/python/benchmarks/GAIA/Templates/TeamOne/scenario.py b/python/benchmarks/GAIA/Templates/TeamOne/scenario.pyindex f654c3f27..ac7a3bfb5 100644--- a/python/benchmarks/GAIA/Templates/TeamOne/scenario.py+++ b/python/benchmarks/GAIA/Templates/TeamOne/scenario.py@@ -2,6 +2,8 @@ import asyncioimport loggingimport os+from openai import AzureOpenAI+from typing import Listfrom agnext.application import SingleThreadedAgentRuntimefrom agnext.application.logging import EVENT_LOGGER_NAME@@ -122,7 +124,6 @@ async def main() -> None:runtime = SingleThreadedAgentRuntime()# Create the AzureOpenAI client, with AAD auth- # token_provider = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")client = AzureOpenAIChatCompletionClient(api_version="2024-02-15-preview",azure_endpoint="https://aif-complex-tasks-west-us-3.openai.azure.com/",@@ -130,7 +131,11 @@ async def main() -> None:model_capabilities=ModelCapabilities(function_calling=True, json_output=True, vision=True),- # azure_ad_token_provider=token_provider+ )++ mlm_client = AzureOpenAI(+ api_version="2024-02-15-preview",+ azure_endpoint="https://aif-complex-tasks-west-us-3.openai.azure.com/",)# Register agents.@@ -175,21 +180,20 @@ async def main() -> None:filename_prompt = f"The question is about a file, document or image, which can be accessed by the filename '{filename}' in the current working directory."+ mlm_prompt = f"""Write a detailed caption for this image. Pay special attention to any details that might be useful for someone answering the following:++{prompt}+""".strip()+try:- mdconverter = MarkdownConverter()- res = mdconverter.convert(filename)+ mdconverter = MarkdownConverter(mlm_client=mlm_client, mlm_model="gpt-4o-2024-05-13")+ res = mdconverter.convert(filename, mlm_prompt=mlm_prompt)if res.text_content:if count_token(res.text_content) < 8000: # Don't put overly-large documents into the promptfilename_prompt += "\n\nHere are the file's contents:\n\n" + res.text_contentexcept UnsupportedFormatException:pass- #mdconverter = MarkdownConverter(mlm_client=client)- #mlm_prompt = f"""Write a detailed caption for this image. Pay special attention to any details that might be useful for someone answering the following:--#{PROMPT}-#""".strip()-task = f"{prompt}\n\n{filename_prompt}"await runtime.publish_message(diff --git a/python/teams/team-one/src/team_one/markdown_browser/mdconvert.py b/python/teams/team-one/src/team_one/markdown_browser/mdconvert.pyindex 2764e14e9..198ee6233 100644--- a/python/teams/team-one/src/team_one/markdown_browser/mdconvert.py+++ b/python/teams/team-one/src/team_one/markdown_browser/mdconvert.py@@ -754,10 +754,13 @@ class ImageConverter(MediaConverter):# Try describing the image with GPTVmlm_client = kwargs.get("mlm_client")- if mlm_client is not None:+ mlm_model = kwargs.get("mlm_model")+ if mlm_client is not None and mlm_model is not None:md_content += ("\n# Description:\n"- + self._get_mlm_description(local_path, extension, mlm_client, prompt=kwargs.get("mlm_prompt")).strip()+ + self._get_mlm_description(+ local_path, extension, mlm_client, mlm_model, prompt=kwargs.get("mlm_prompt")+ ).strip()+ "\n")@@ -785,7 +788,7 @@ class ImageConverter(MediaConverter):text_content=md_content,)- def _get_mlm_description(self, local_path, extension, client, prompt=None):+ def _get_mlm_description(self, local_path, extension, client, model, prompt=None):if prompt is None or prompt.strip() == "":prompt = "Write a detailed caption for this image."@@ -799,23 +802,23 @@ class ImageConverter(MediaConverter):image_base64 = base64.b64encode(image_file.read()).decode("utf-8")data_uri = f"data:{content_type};base64,{image_base64}"- messages = [- {- "role": "user",- "content": [- {"type": "text", "text": prompt},- {- "type": "image_url",- "image_url": {- "url": data_uri,- },+ messages = [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": prompt},+ {+ "type": "image_url",+ "image_url": {+ "url": data_uri,},- ],- }- ]+ },+ ],+ }+ ]- response = client.create(messages=messages)- return client.extract_text_or_completion_object(response)[0]+ response = client.chat.completions.create(model=model, messages=messages)+ return response.choices[0].message.contentclass FileConversionException(BaseException):@@ -834,6 +837,7 @@ class MarkdownConverter:self,requests_session: Optional[requests.Session] = None,mlm_client: Optional[Any] = None,+ mlm_model: Optional[Any] = None,):if requests_session is None:self._requests_session = requests.Session()@@ -841,6 +845,7 @@ class MarkdownConverter:self._requests_session = requests_sessionself._mlm_client = mlm_client+ self._mlm_model = mlm_modelself._page_converters: List[DocumentConverter] = []@@ -996,6 +1001,9 @@ class MarkdownConverter:if "mlm_client" not in _kwargs and self._mlm_client is not None:_kwargs["mlm_client"] = self._mlm_client+ if "mlm_model" not in _kwargs and self._mlm_model is not None:+ _kwargs["mlm_model"] = self._mlm_model+# If we hit an error log it and keep trying# try:res = converter.convert(local_path, **_kwargs)