Fix six starter/advanced_llm Python apps that crash or corrupt data

- ai_music_generator_agent + chat_arxiv_llama3: drop Agent(show_tool_calls=True);
  agno 2.x removed the parameter, so both crash with TypeError on startup
  (chat_arxiv_llama3 at import; sibling chat_arxiv.py already omits it).
- cursor_ai_experiments/multi_agent_researcher: Crew(verbose=2) -> verbose=True;
  current CrewAI's verbose is a strict pydantic bool, so 2 raises ValidationError
  and the crew never runs.
- toonify_token_optimization/{toonify_app,toonify_demo}: guard
  tiktoken.encoding_for_model with try/except KeyError -> cl100k_base; selecting a
  claude-3-* model (offered in the UI) otherwise crashes the token-count tab.
- ai_data_visualisation_agent: uploaded_file.seek(0) before uploading to the
  sandbox; pd.read_csv had already consumed the stream to EOF, so a 0-byte file
  was uploaded and every analysis read an empty dataset.
- ai_data_analysis_agent: remove the manual '"' -> '""' replacement; csv.QUOTE_ALL
  already escapes quotes, so the two together double-escaped every quoted cell.
  Verified round-trip: 'He said "hi"' now preserved (was 'He said ""hi""').

All seven files compile-check clean.
This commit is contained in:
thejesh23
2026-07-31 23:07:10 -07:00
parent 9f1f80a584
commit e97e40d66c
7 changed files with 17 additions and 9 deletions
@@ -11,7 +11,7 @@ st.caption("This app allows you to chat with arXiv research papers using Llama-3
# Create an instance of the Assistant
assistant = Agent(
model=Ollama(
id="llama3.1:8b") , tools=[ArxivTools()], show_tool_calls=True
id="llama3.1:8b") , tools=[ArxivTools()]
)
# Get the search query from the user
@@ -82,7 +82,7 @@ def create_article_crew(topic):
crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, writing_task, editing_task],
verbose=2,
verbose=True,
process=Process.sequential
)
@@ -12,7 +12,12 @@ import pandas as pd
def count_tokens(text: str, model: str = "gpt-4") -> int:
"""Count tokens in text."""
encoding = tiktoken.encoding_for_model(model)
try:
encoding = tiktoken.encoding_for_model(model)
except KeyError:
# tiktoken can't map non-OpenAI model names (e.g. claude-3-*); fall back
# to the modern OpenAI encoding so the token count still renders.
encoding = tiktoken.get_encoding("cl100k_base")
return len(encoding.encode(text))
@@ -13,7 +13,11 @@ import os
def count_tokens(text: str, model: str = "gpt-4") -> int:
"""Count the number of tokens in a text string."""
encoding = tiktoken.encoding_for_model(model)
try:
encoding = tiktoken.encoding_for_model(model)
except KeyError:
# tiktoken can't map non-OpenAI model names (e.g. claude-3-*); fall back.
encoding = tiktoken.get_encoding("cl100k_base")
return len(encoding.encode(text))
@@ -19,10 +19,6 @@ def preprocess_and_save(file):
st.error("Unsupported file format. Please upload a CSV or Excel file.")
return None, None, None
# Ensure string columns are properly quoted
for col in df.select_dtypes(include=['object']):
df[col] = df[col].astype(str).replace({r'"': '""'}, regex=True)
# Parse dates and numeric columns
for col in df.columns:
if 'date' in col.lower():
@@ -80,6 +80,10 @@ def upload_dataset(code_interpreter: Sandbox, uploaded_file) -> str:
dataset_path = f"./{uploaded_file.name}"
try:
# The Streamlit upload was already read to EOF by pd.read_csv earlier in
# the run, so rewind before uploading — otherwise a 0-byte file reaches the
# sandbox and every analysis reads an empty dataset.
uploaded_file.seek(0)
code_interpreter.files.write(dataset_path, uploaded_file)
return dataset_path
except Exception as error:
@@ -24,7 +24,6 @@ if openai_api_key and models_lab_api_key:
name="ModelsLab Music Agent",
agent_id="ml_music_agent",
model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
show_tool_calls=True,
tools=[ModelsLabTools(api_key=models_lab_api_key, wait_for_completion=True, file_type=FileType.MP3)],
description="You are an AI agent that can generate music using the ModelsLabs API.",
instructions=[