Compare commits

...

5 Commits

Author SHA1 Message Date
github-actions[bot] 54561e2dd2 chore: version packages (#1025) 2025-11-24 16:41:22 -06:00
Logan Markewich bfaec79a8f changeset 2025-11-24 16:37:58 -06:00
Logan Markewich 3e0e522a6b update ts 2025-11-24 16:36:31 -06:00
Logan Markewich f70b6d87ec update py 2025-11-24 16:31:15 -06:00
Logan Markewich 693b5b83b1 improve llama-sheets example 2025-11-24 09:44:11 -06:00
12 changed files with 80 additions and 55 deletions
@@ -24,8 +24,8 @@ from workflows import Context
dotenv.load_dotenv()
# Global context for loaded dataframes
_dataframe_context: Dict[str, Any] = {}
# Global context for executed code
_code_context: Dict[str, Any] = {}
# Helper function for initial agent context
@@ -79,36 +79,30 @@ def list_extracted_data(data_dir: str = "data") -> str:
# Agent tool for code execution against dataframes
def execute_dataframe_code(
code: str, load_files: Optional[Dict[str, str]] = None
) -> str:
def execute_code(code: str) -> str:
"""
Execute Python pandas code against LlamaSheets extracted data.
Execute Python pandas code against LlamaSheets extracted data.
This tool allows flexible data analysis by executing arbitrary pandas code.
You can load parquet files, manipulate dataframes, and return results.
This tool allows flexible data analysis by executing arbitrary pandas code.
You can load parquet files, manipulate dataframes, and return results.
The code executes in a context where:
- pandas is available as 'pd'
- json is available for formatting output
- Previously loaded dataframes are accessible by their variable names
The code executes in a context where:
- pandas is available as 'pd'
- json is available for formatting output
Args:
code: Python code to execute. Any print() statements or stdout/stderr
will be captured and returned. Optionally set a 'result' variable
for structured output.
load_files: Optional dict mapping variable names to file paths to load
Example: {"df": "data/sales_region_1.parquet",
"meta": "data/sales_metadata_1.parquet"}
Args:
code: Python code to execute. Any print() statements or stdout/stderr
will be captured and returned. Optionally set a 'result' variable
for structured output.
Returns:
String containing:
- Any stdout/stderr output from the code execution
- The 'result' variable if it was set (formatted appropriately)
- Error message if execution failed
Returns:
String containing:
- Any stdout/stderr output from the code execution
- The 'result' variable if it was set (formatted appropriately)
- Error message if execution failed
Example usage:
code = '''
Example usage:
code = '''
# Load and inspect data
df = pd.read_parquet("data/sales_region_1.parquet")
print(f"Loaded {len(df)} rows")
@@ -118,9 +112,9 @@ def execute_dataframe_code(
"columns": list(df.columns),
"sample": df.head(3).to_dict(orient="records")
}
'''
'''
"""
global _dataframe_context
global _code_context
# Capture stdout and stderr
stdout_capture = io.StringIO()
@@ -138,24 +132,17 @@ def execute_dataframe_code(
"pd": pd,
"json": json,
"Path": Path,
**_dataframe_context, # Include previously loaded dataframes
**_code_context, # Include previously loaded dataframes
}
# Load any requested files into context
if load_files:
for var_name, file_path in load_files.items():
if file_path.endswith(".parquet"):
exec_context[var_name] = pd.read_parquet(file_path)
# Also save to global context for future calls
_dataframe_context[var_name] = exec_context[var_name]
elif file_path.endswith(".json"):
with open(file_path, "r") as f:
exec_context[var_name] = json.load(f)
_dataframe_context[var_name] = exec_context[var_name]
# Execute the code
exec(code, exec_context)
# Update global context with any new variables (excluding built-ins and modules)
for key, value in exec_context.items():
if not key.startswith("_") and key not in ["pd", "json", "Path"]:
_code_context[key] = value
# Restore stdout/stderr
sys.stdout = old_stdout
sys.stderr = old_stderr
@@ -223,8 +210,8 @@ def create_llamasheets_agent(
# Initialize LLM
llm = OpenAI(model=llm_model, api_key=api_key)
# Create tools - just 4 simple but powerful tools
tools = [execute_dataframe_code]
# Create tools list
tools = [execute_code]
# System prompt to guide the agent
available_regions = list_extracted_data()
@@ -238,11 +225,8 @@ LlamaSheets extracts messy spreadsheets into clean parquet files with two types
- Type detection: data_type, is_date_like, is_percentage, is_currency
- Layout: is_in_first_row, is_merged_cell, horizontal_alignment
Your approach:
1. Use list_extracted_data() to discover available files
2. Use execute_dataframe_code() to load and analyze data with pandas
3. Use metadata to understand structure (bold = headers, colors = groups)
4. Use save_dataframe() to export results
You have access to tools that allow you to execute Python pandas code against these files.
Use these tools to load the parquet files, analyze the data, and return results.
Key tips:
- Bold cells in metadata often indicate headers
@@ -299,7 +283,7 @@ async def main():
print(ev.delta, end="", flush=True)
_ = await handler
print("=== End Query ===\n")
print("\n=== End Query ===\n")
if __name__ == "__main__":
+6
View File
@@ -1,5 +1,11 @@
# llama-cloud-services-py
## 0.6.82
### Patch Changes
- bfaec79: Update for new page number params
## 0.6.81
### Patch Changes
+7
View File
@@ -536,6 +536,10 @@ class LlamaParse(BasePydanticReader):
default=None,
description="A prefix to add to the page footer in the output markdown.",
)
extract_printed_page_number: Optional[bool] = Field(
default=None,
description="Whether to extract the printed page numbers from pages in the document.",
)
# Deprecated
bounding_box: Optional[str] = Field(
@@ -1049,6 +1053,9 @@ class LlamaParse(BasePydanticReader):
"markdown_table_multiline_header_separator"
] = self.markdown_table_multiline_header_separator
if self.extract_printed_page_number is not None:
data["extract_printed_page_number"] = self.extract_printed_page_number
# Deprecated
if self.bounding_box is not None:
data["bounding_box"] = self.bounding_box
+13
View File
@@ -250,6 +250,19 @@ class Page(SafeBaseModel):
slideSpeakerNotes: Optional[str] = Field(
default=None, description="The speaker notes for the slide."
)
confidence: Optional[float] = Field(
default=None, description="The confidence of the page parsing."
)
printedPageNumber: Optional[str] = Field(
default=None,
description="The printed page number on the page, if found and extractPrintedPageNumber is set to true.",
)
pageHeaderMarkdown: Optional[str] = Field(
default=None, description="The page header in markdown format."
)
pageFooterMarkdown: Optional[str] = Field(
default=None, description="The page footer in markdown format."
)
class JobResult(SafeBaseModel):
+7
View File
@@ -1,5 +1,12 @@
# llama_parse
## 0.6.82
### Patch Changes
- Updated dependencies [bfaec79]
- llama-cloud-services-py@0.6.82
## 0.6.81
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llama_parse",
"version": "0.6.81",
"version": "0.6.82",
"description": "",
"main": "index.js",
"private": false,
+2 -2
View File
@@ -11,13 +11,13 @@ dev = [
[project]
name = "llama-parse"
version = "0.6.81"
version = "0.6.82"
description = "Parse files into RAG-Optimized formats."
authors = [{name = "Logan Markewich", email = "logan@llamaindex.ai"}]
requires-python = ">=3.9,<4.0"
readme = "README.md"
license = "MIT"
dependencies = ["llama-cloud-services>=0.6.81"]
dependencies = ["llama-cloud-services>=0.6.82"]
[project.scripts]
llama-parse = "llama_parse.cli.main:parse"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llama-cloud-services-py",
"version": "0.6.81",
"version": "0.6.82",
"private": false,
"license": "MIT",
"scripts": {},
+1 -1
View File
@@ -22,7 +22,7 @@ dev = [
[project]
name = "llama-cloud-services"
version = "0.6.81"
version = "0.6.82"
description = "Tailored SDK clients for LlamaCloud services."
authors = [{name = "Logan Markewich", email = "logan@runllama.ai"}]
requires-python = ">=3.9,<4.0"
+6
View File
@@ -1,5 +1,11 @@
# llama-cloud-services
## 0.4.2
### Patch Changes
- bfaec79: Update for new page number params
## 0.4.1
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "llama-cloud-services",
"version": "0.4.1",
"version": "0.4.2",
"type": "module",
"license": "MIT",
"scripts": {
+2
View File
@@ -185,6 +185,7 @@ export class LlamaParseReader extends FileReader {
page_footer_prefix?: string | undefined;
page_footer_suffix?: string | undefined;
merge_tables_across_pages_in_markdown?: boolean | undefined;
extract_printed_page_number?: boolean | undefined;
constructor(
params: Partial<Omit<LlamaParseReader, "language" | "apiKey">> & {
@@ -381,6 +382,7 @@ export class LlamaParseReader extends FileReader {
page_footer_suffix: this.page_footer_suffix,
merge_tables_across_pages_in_markdown:
this.merge_tables_across_pages_in_markdown,
extract_printed_page_number: this.extract_printed_page_number,
} satisfies {
[Key in keyof BodyUploadFileApiParsingUploadPost]-?:
| BodyUploadFileApiParsingUploadPost[Key]