|
4 | 4 | import asyncio |
5 | 5 | import pandas as pd |
6 | 6 | from pathlib import Path |
7 | | -from typing import Optional, Tuple, Dict, Any, Callable, Type, Union |
| 7 | +from typing import Optional, Tuple, Dict, Any, Callable, Type, Union, List |
8 | 8 | from dataclasses import dataclass |
9 | 9 |
|
10 | 10 | from augmenta.utils.prompt_formatter import format_examples, substitute_template_variables, build_complete_prompt |
11 | 11 | from augmenta.agent import AugmentaAgent |
12 | 12 | from augmenta.cache import CacheManager |
13 | 13 | from augmenta.cache.process import setup_cache_handling, apply_cached_results |
14 | 14 | from augmenta.config.read_config import load_config, get_config_values |
| 15 | +from augmenta.tools.file import load_file |
15 | 16 | import logfire |
16 | 17 |
|
17 | 18 | @dataclass |
@@ -206,12 +207,34 @@ async def process_row( |
206 | 207 | """ |
207 | 208 | try: |
208 | 209 | index = row_data['index'] |
209 | | - row = row_data['data'] |
210 | | - # Build complete prompt with data from row |
| 210 | + row = row_data['data'] # Build complete prompt with data from row |
211 | 211 | prompt_user = build_complete_prompt(config, row) |
| 212 | + # Get the file column name from config (if available) |
| 213 | + file_col = config.get("file_col") |
212 | 214 |
|
213 | | - # Run prompt using the agent |
214 | | - response = await agent.run(prompt_user, response_format=response_format) |
| 215 | + # Check if a file column is specified and the row contains a file path |
| 216 | + file_path = None |
| 217 | + if file_col and file_col in row: |
| 218 | + file_path = row.get(file_col) |
| 219 | + logfire.debug(f"Using file from column '{file_col}': {file_path}") |
| 220 | + elif file_col: |
| 221 | + logfire.debug(f"File column '{file_col}' specified in config but not found in row data") |
| 222 | + else: |
| 223 | + logfire.debug("No file column specified in config") |
| 224 | + |
| 225 | + try: |
| 226 | + binary_content = load_file(file_path) if file_path is not None else None |
| 227 | + if binary_content: |
| 228 | + # If file exists, create a message list with prompt and binary content |
| 229 | + message_contents = [prompt_user, binary_content] |
| 230 | + response = await agent.run(message_contents, response_format=response_format) |
| 231 | + else: |
| 232 | + # If file doesn't exist or couldn't be loaded, just use the text prompt |
| 233 | + response = await agent.run(prompt_user, response_format=response_format) |
| 234 | + except Exception as e: |
| 235 | + logfire.warning(f"Error loading file at row {index}: {str(e)}. Proceeding with text prompt only.") |
| 236 | + # Fallback to text-only prompt if file handling fails |
| 237 | + response = await agent.run(prompt_user, response_format=response_format) |
215 | 238 |
|
216 | 239 | # Handle caching and progress tracking |
217 | 240 | handle_result_tracking( |
|
0 commit comments