File size: 2,490 Bytes
4d521f6
 
 
 
 
 
e2c04b6
5d480b1
 
 
4d521f6
5d480b1
7b0bd9a
 
 
 
 
 
4d521f6
5d480b1
4d521f6
5d480b1
4d521f6
5d480b1
 
a75a9dc
5d480b1
4d521f6
 
 
 
 
 
e2c04b6
4d521f6
5d480b1
4d521f6
 
 
 
 
7b0bd9a
4d521f6
5d480b1
7b0bd9a
4d521f6
 
7b0bd9a
4d521f6
 
7b0bd9a
4d521f6
 
7b0bd9a
4d521f6
 
7b0bd9a
4d521f6
 
7b0bd9a
4d521f6
5d480b1
 
7b0bd9a
4d521f6
 
7b0bd9a
4d521f6
a75a9dc
5d480b1
 
 
4d521f6
5d480b1
 
4d521f6
5d480b1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# genesis/pipeline.py
"""
GENESIS-AI Research Pipeline
Coordinates ontology expansion, literature retrieval, summaries, citations, structure fetching, graphDB storage, and narration.
"""

import os
from datetime import datetime

from .ontology import expand_terms_with_ontology
from .molecule_viewer import fetch_structure
from .narration import narrate_text
from .providers import (
    run_deepseek_summary,
    run_gemini_polish,
    run_openai_image,
    pubmed_fallback_search
)
from .graphdb import write_topic_and_papers

# ENV
ELEVEN_LABS_API_KEY = os.getenv("ELEVEN_LABS_API_KEY")
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
NEO4J_URI = os.getenv("NEO4J_URI")

SYNBIO_MODE = True

def synthetic_biology_prompt_inject(query, expanded_terms):
    """Injects domain-specific bias toward synthetic biology research."""
    context = (
        "You are an expert in synthetic biology. Focus on CRISPR, metabolic engineering, "
        "living therapeutics, protein design, biosensors, and biosecurity. Include literature, "
        "structures, market trends, and regulatory insights with citations."
    )
    return f"{context}\n\nQuery: {query}\nExpanded terms: {', '.join(expanded_terms)}"

def research_once(query, graph_preview=True, narration=True):
    """Runs the GENESIS-AI pipeline for a given research query."""
    
    # 1. Expand ontology
    expanded_terms = expand_terms_with_ontology(query)

    # 2. Domain injection
    enriched_query = synthetic_biology_prompt_inject(query, expanded_terms) if SYNBIO_MODE else query

    # 3. Summarize (DeepSeek)
    summary_raw = run_deepseek_summary(enriched_query)

    # 4. Polish (Gemini)
    summary_polished = run_gemini_polish(summary_raw)

    # 5. Citations
    citations = pubmed_fallback_search(query)

    # 6. Structures
    structures = [fetch_structure(term) for term in expanded_terms]

    # 7. Visual (OpenAI Image)
    image_url = run_openai_image(query)

    # 8. GraphDB
    if graph_preview and NEO4J_URI:
        write_topic_and_papers(query, citations, expanded_terms)

    # 9. Narration
    audio_url = narrate_text(summary_polished) if narration and ELEVEN_LABS_API_KEY else None

    # 10. Output
    return {
        "timestamp": datetime.utcnow().isoformat(),
        "query": query,
        "expanded_terms": expanded_terms,
        "summary": summary_polished,
        "citations": citations,
        "structures": structures,
        "image_url": image_url,
        "audio_url": audio_url
    }