403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.88
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/repo/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/repo/api/demo_article_with_search.py
#!/usr/bin/env python
"""
Demo script showing how search results enhance article generation.
This simulates what happens when research_current_events is enabled.
"""

import sys
import os

# Add the project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from app.services.chat import ChatService

def demo_article_generation():
    """Demonstrate article generation with and without search"""

    cs = ChatService()

    print("=" * 80)
    print("DEMO: Article Generation with Current Events Research")
    print("=" * 80)

    # Step 1: Search for current events
    print("\n[1] Searching for current tech news...")
    search_results = cs.search_current_events('latest AI and technology news', max_results=3)
    print(f"    Found {len(search_results)} results")

    if search_results:
        print("\n    Top result:")
        print(f"    - {search_results[0].get('title', 'N/A')[:80]}...")
        print(f"    - Published: {search_results[0].get('published_date', 'N/A')}")

    # Step 2: Show how search context is added to the prompt
    print("\n[2] Building article generation context...")

    base_human_msg = "Please write an article."

    if search_results:
        search_context = "\n\n## Current Events Research:\n\n"
        for i, result in enumerate(search_results, 1):
            title = result.get('title', 'No title')
            url = result.get('url', '')
            content = result.get('content', '')
            search_context += f"**Source {i}: {title}**\n"
            search_context += f"URL: {url}\n"
            search_context += f"Content: {content[:200]}...\n\n"

        enhanced_human_msg = f"{base_human_msg}\n\n{search_context}\n\nPlease write an article incorporating this current information."

        print(f"\n    Base message: '{base_human_msg}'")
        print(f"\n    Enhanced message includes:")
        print(f"    - {len(search_results)} news sources")
        print(f"    - Published dates for timeliness")
        print(f"    - Article excerpts for context")
        print(f"    - URLs for citation")

        print(f"\n    Message length: {len(base_human_msg)} → {len(enhanced_human_msg)} chars")
        print(f"    (+{len(enhanced_human_msg) - len(base_human_msg)} chars of current events context)")

    # Step 3: Example of what the AI receives
    print("\n[3] Example context snippet sent to AI:")
    print("-" * 80)
    if search_results:
        print(search_context[:500] + "...")
    print("-" * 80)

    print("\n[4] Benefits of current events research:")
    print("    ✓ Articles based on real, recent news")
    print("    ✓ Accurate dates and facts")
    print("    ✓ Credible sources cited")
    print("    ✓ Timely and relevant content")
    print("    ✓ Character can write about breaking news")

    print("\n" + "=" * 80)
    print("Demo complete! To test with actual article generation:")
    print("1. Set up a Character in the frontend")
    print("2. Enable 'Research Current Events' checkbox")
    print("3. Provide a topic (e.g., 'latest AI developments')")
    print("4. Watch the streaming progress include 'Researching current events...'")
    print("=" * 80)

if __name__ == "__main__":
    demo_article_generation()

Youez - 2016 - github.com/yon3zu
LinuXploit