milwright commited on
Commit
d01e9d0
Β·
1 Parent(s): 719f45f

Reorganize interface: streamline assistant configuration and improve preview feedback

Browse files

- Remove Tool Settings accordion for cleaner interface
- Move web search under Research Template with auto-enable
- Group Document RAG and URL Grounding in Assistant Configuration
- Position features logically: Research β†’ Web Search β†’ Document RAG β†’ URL Grounding β†’ Examples
- Add success notification for preview generation
- Update max tokens default to 1500

Files changed (1) hide show
  1. app.py +41 -24
app.py CHANGED
@@ -946,12 +946,24 @@ def process_documents(files, current_rag_tool):
946
  return "RAG functionality not available. Please install required dependencies.", current_rag_tool
947
 
948
  try:
 
 
 
 
 
 
 
 
 
 
949
  # Initialize RAG tool if not exists
950
  if not current_rag_tool and RAGTool is not None:
 
951
  current_rag_tool = RAGTool()
952
 
953
- # Process files
954
- result = current_rag_tool.process_uploaded_files(files)
 
955
 
956
  if result['success']:
957
  # Create status message
@@ -1108,6 +1120,9 @@ Your assistant "{name}" is now configured and ready to test in the Sandbox Previ
1108
  {examples_text if examples_text and examples_text.strip() else 'No example prompts configured'}
1109
  """
1110
 
 
 
 
1111
  return (
1112
  config_data,
1113
  gr.update(value=preview_text, visible=True),
@@ -1673,17 +1688,19 @@ def perform_web_search(query, description="Web search"):
1673
  # Code execution functionality removed - no longer supported
1674
 
1675
  def toggle_research_assistant(enable_research):
1676
- """Toggle research assistant system prompt"""
1677
  if enable_research:
1678
  combined_prompt = "You are an advanced research assistant specializing in academic literature search and analysis. Your expertise includes finding peer-reviewed sources, critically evaluating research methodology, synthesizing insights across multiple papers, and providing properly formatted citations. When responding, ground all claims in specific sources from provided URL contexts, distinguish between direct evidence and analytical interpretation, and highlight any limitations or conflicting findings. Use clear, accessible language that makes complex research understandable, and suggest related areas of inquiry when relevant. Your goal is to be a knowledgeable research partner who helps users navigate academic information with precision and clarity."
1679
  return (
1680
  gr.update(value=combined_prompt), # Update main system prompt
1681
- gr.update(value=True) # Enable dynamic URL fetching for research template
 
1682
  )
1683
  else:
1684
  return (
1685
  gr.update(value=""), # Clear main system prompt when disabling
1686
- gr.update(value=False) # Disable dynamic URL setting
 
1687
  )
1688
 
1689
 
@@ -1846,7 +1863,6 @@ with gr.Blocks(
1846
  )
1847
 
1848
  with gr.Accordion("Assistant Configuration", open=True):
1849
- gr.Markdown("### Configure your assistant's behavior and capabilities")
1850
  gr.Markdown("Define the system prompt and assistant settings. You can use pre-configured templates or custom fields.")
1851
 
1852
  # Main system prompt field - always visible
@@ -1865,22 +1881,7 @@ with gr.Blocks(
1865
  info="Enable to use pre-configured research assistant settings"
1866
  )
1867
 
1868
- examples_text = gr.Textbox(
1869
- label="Example Prompts (one per line)",
1870
- placeholder="Can you analyze this research paper: https://example.com/paper.pdf\nWhat are the latest findings on climate change adaptation?\nHelp me fact-check claims about renewable energy efficiency",
1871
- lines=3,
1872
- info="These will appear as clickable examples in the chat interface"
1873
- )
1874
-
1875
- with gr.Accordion("Tool Settings", open=True):
1876
-
1877
- enable_dynamic_urls = gr.Checkbox(
1878
- label="Enable Dynamic URL Fetching",
1879
- value=True, # Enabled by default
1880
- info="Allow the assistant to fetch additional URLs mentioned in conversations (enabled by default)",
1881
- visible=False # Hidden since it's always enabled
1882
- )
1883
-
1884
  enable_web_search = gr.Checkbox(
1885
  label="Enable Web Search",
1886
  value=False,
@@ -1895,6 +1896,7 @@ with gr.Blocks(
1895
  interactive=False
1896
  )
1897
 
 
1898
  enable_vector_rag = gr.Checkbox(
1899
  label="Enable Document RAG",
1900
  value=False,
@@ -1951,6 +1953,21 @@ with gr.Blocks(
1951
  add_url_btn = gr.Button("+ Add URLs", size="sm")
1952
  remove_url_btn = gr.Button("- Remove URLs", size="sm", visible=False)
1953
  url_count = gr.State(2) # Track number of visible URLs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1954
 
1955
  with gr.Accordion("Advanced Settings", open=False):
1956
  with gr.Row():
@@ -1967,7 +1984,7 @@ with gr.Blocks(
1967
  label="Max Response Tokens",
1968
  minimum=50,
1969
  maximum=4096,
1970
- value=500,
1971
  step=50
1972
  )
1973
 
@@ -1984,7 +2001,7 @@ with gr.Blocks(
1984
  enable_research_assistant.change(
1985
  toggle_research_assistant,
1986
  inputs=[enable_research_assistant],
1987
- outputs=[system_prompt, enable_dynamic_urls]
1988
  )
1989
 
1990
  # Connect the web search checkbox
 
946
  return "RAG functionality not available. Please install required dependencies.", current_rag_tool
947
 
948
  try:
949
+ # Check file paths are valid
950
+ file_paths = []
951
+ for file in files:
952
+ if hasattr(file, 'name'):
953
+ file_paths.append(file.name)
954
+ else:
955
+ file_paths.append(str(file))
956
+
957
+ print(f"Processing {len(file_paths)} files for RAG...")
958
+
959
  # Initialize RAG tool if not exists
960
  if not current_rag_tool and RAGTool is not None:
961
+ print("Initializing RAG tool...")
962
  current_rag_tool = RAGTool()
963
 
964
+ # Process files with progress feedback
965
+ print("Processing documents and creating embeddings...")
966
+ result = current_rag_tool.process_uploaded_files(file_paths)
967
 
968
  if result['success']:
969
  # Create status message
 
1120
  {examples_text if examples_text and examples_text.strip() else 'No example prompts configured'}
1121
  """
1122
 
1123
+ # Show success notification
1124
+ gr.Info(f"βœ… Preview generated successfully for '{name}'! Switch to the Sandbox Preview tab to test your assistant.")
1125
+
1126
  return (
1127
  config_data,
1128
  gr.update(value=preview_text, visible=True),
 
1688
  # Code execution functionality removed - no longer supported
1689
 
1690
  def toggle_research_assistant(enable_research):
1691
+ """Toggle research assistant system prompt and web search"""
1692
  if enable_research:
1693
  combined_prompt = "You are an advanced research assistant specializing in academic literature search and analysis. Your expertise includes finding peer-reviewed sources, critically evaluating research methodology, synthesizing insights across multiple papers, and providing properly formatted citations. When responding, ground all claims in specific sources from provided URL contexts, distinguish between direct evidence and analytical interpretation, and highlight any limitations or conflicting findings. Use clear, accessible language that makes complex research understandable, and suggest related areas of inquiry when relevant. Your goal is to be a knowledgeable research partner who helps users navigate academic information with precision and clarity."
1694
  return (
1695
  gr.update(value=combined_prompt), # Update main system prompt
1696
+ gr.update(value=True), # Enable dynamic URL fetching for research template
1697
+ gr.update(value=True) # Enable web search for research template
1698
  )
1699
  else:
1700
  return (
1701
  gr.update(value=""), # Clear main system prompt when disabling
1702
+ gr.update(value=False), # Disable dynamic URL setting
1703
+ gr.update(value=False) # Disable web search
1704
  )
1705
 
1706
 
 
1863
  )
1864
 
1865
  with gr.Accordion("Assistant Configuration", open=True):
 
1866
  gr.Markdown("Define the system prompt and assistant settings. You can use pre-configured templates or custom fields.")
1867
 
1868
  # Main system prompt field - always visible
 
1881
  info="Enable to use pre-configured research assistant settings"
1882
  )
1883
 
1884
+ # Web search under research template
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1885
  enable_web_search = gr.Checkbox(
1886
  label="Enable Web Search",
1887
  value=False,
 
1896
  interactive=False
1897
  )
1898
 
1899
+ # Document RAG section
1900
  enable_vector_rag = gr.Checkbox(
1901
  label="Enable Document RAG",
1902
  value=False,
 
1953
  add_url_btn = gr.Button("+ Add URLs", size="sm")
1954
  remove_url_btn = gr.Button("- Remove URLs", size="sm", visible=False)
1955
  url_count = gr.State(2) # Track number of visible URLs
1956
+
1957
+ examples_text = gr.Textbox(
1958
+ label="Example Prompts (one per line)",
1959
+ placeholder="Can you analyze this research paper: https://example.com/paper.pdf\nWhat are the latest findings on climate change adaptation?\nHelp me fact-check claims about renewable energy efficiency",
1960
+ lines=3,
1961
+ info="These will appear as clickable examples in the chat interface"
1962
+ )
1963
+
1964
+ # Hidden field for dynamic URLs (always enabled)
1965
+ enable_dynamic_urls = gr.Checkbox(
1966
+ label="Enable Dynamic URL Fetching",
1967
+ value=True, # Enabled by default
1968
+ info="Allow the assistant to fetch additional URLs mentioned in conversations (enabled by default)",
1969
+ visible=False # Hidden since it's always enabled
1970
+ )
1971
 
1972
  with gr.Accordion("Advanced Settings", open=False):
1973
  with gr.Row():
 
1984
  label="Max Response Tokens",
1985
  minimum=50,
1986
  maximum=4096,
1987
+ value=1500,
1988
  step=50
1989
  )
1990
 
 
2001
  enable_research_assistant.change(
2002
  toggle_research_assistant,
2003
  inputs=[enable_research_assistant],
2004
+ outputs=[system_prompt, enable_dynamic_urls, enable_web_search]
2005
  )
2006
 
2007
  # Connect the web search checkbox