66from langchain_core .language_models import BaseChatModel
77from langchain_core .messages import AIMessage , AnyMessage , HumanMessage
88
9- from . file_type_handler import build_message_content_part_from_data
9+ from uipath_langchain . llm import get_content_builder
1010
1111
1212@dataclass
@@ -18,29 +18,24 @@ class FileInfo:
1818 mime_type : str
1919
2020
21- def _get_model_name (model : BaseChatModel ) -> str :
22- """Extract model name from a BaseChatModel instance."""
23- for attr in ["model_name" , "_model_name" , "model" , "model_id" ]:
24- value = getattr (model , attr , None )
25- if value and isinstance (value , str ):
26- return value
27- raise ValueError (f"Model name not found in model { model } " )
28-
29-
30- async def create_part_for_file (
21+ async def build_file_content_part (
3122 file_info : FileInfo ,
3223 model : BaseChatModel ,
3324) -> dict [str , Any ]:
34- """Create a provider-specific message content part for a file attachment.
25+ """Build a provider-specific message content part for a file attachment.
26+
27+ Args:
28+ file_info: File URL, name, and MIME type.
29+ model: The LLM model instance (must have llm_provider and api_flavor attributes).
3530
36- Downloads the file from file_info.url and formats it for the model's provider.
31+ Returns:
32+ Provider-specific content part dictionary.
3733 """
38- model_name = _get_model_name (model )
39- return await build_message_content_part_from_data (
34+ builder = get_content_builder (model )
35+ return await builder . build_file_content_part (
4036 url = file_info .url ,
4137 filename = file_info .name ,
4238 mime_type = file_info .mime_type ,
43- model = model_name ,
4439 )
4540
4641
@@ -64,7 +59,7 @@ async def llm_call_with_files(
6459
6560 content_parts : list [str | dict [Any , Any ]] = []
6661 for file_info in files :
67- content_part = await create_part_for_file (file_info , model )
62+ content_part = await build_file_content_part (file_info , model )
6863 content_parts .append (content_part )
6964
7065 file_message = HumanMessage (content = content_parts )
0 commit comments