Skip to content

Integrate uniprot #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5af1b04
download, cleanup and make embeddings for uniprot
heliamoh Feb 11, 2025
6be0417
download, cleanup and make embeddings for uniprot
heliamoh Feb 11, 2025
fcedb3c
modified uniprot data download pipeline
heliamoh Feb 12, 2025
b495303
modified uniprot data download pipeline
heliamoh Feb 12, 2025
237db4e
reorganized Reactome and pre/post-processing prompts. Added UniProt p…
heliamoh Feb 18, 2025
0f3d833
reorganized Reactome and pre/post-processing prompts. Added UniProt p…
heliamoh Feb 18, 2025
f2a7760
Refactor create_retrieval_chain to support dynamic metadata handling …
heliamoh Feb 18, 2025
ef45c0a
changed reactome descriptions_info and field_info names
heliamoh Feb 18, 2025
67582b5
Refactor RAGGraphWithMemory and create_rag_chain to support integrati…
heliamoh Feb 18, 2025
bac9c57
renamed create_retrieval_chain to create_retriever and modified it to…
heliamoh Feb 24, 2025
07dee88
added qa_prompt to create_rag_chain to to support integration of mult…
heliamoh Feb 24, 2025
443f025
added qa_prompt to create_rag_chain to to support integration of mult…
heliamoh Feb 24, 2025
669a555
added qa_prompt to create_rag_chain to to support integration of mult…
heliamoh Feb 24, 2025
74ac163
reorganized Reactome and pre/post-processing prompts. Added UniProt p…
heliamoh Feb 24, 2025
2668e46
updated variable name 'question' to 'input' for consistency
heliamoh Feb 24, 2025
a34e8fb
integrate chainlit with the new 'cross-database' system
heliamoh Feb 24, 2025
15ba423
the new graph system for uniprot integration
heliamoh Feb 24, 2025
0230b99
Merge branch 'refactor-codebase' into integrate-uniprot
GFJHogue Feb 27, 2025
28dee4e
consolidate new uniprot code following existing patterns
GFJHogue Feb 27, 2025
bf23413
Merge branch 'refactor-codebase' into integrate-uniprot
GFJHogue Mar 3, 2025
d08ef7a
improved typing & integrate cross-db code [WIP]
GFJHogue Mar 11, 2025
bcc94a8
ensure unchanged React-to-Me behaviour; fix state/checkpointer setup
GFJHogue Mar 12, 2025
8c28256
Merge branch 'main' into integrate-uniprot
GFJHogue Mar 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ properties:
type: array
items:
type: string
enum: ["React-to-Me"]
enum: ["React-to-Me", "Cross-Database Prototype"]
usage_limits:
type: object
properties:
Expand Down
4 changes: 2 additions & 2 deletions bin/chat-chainlit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from typing import Any

import chainlit as cl
from chainlit.data.base import BaseDataLayer
Expand All @@ -10,6 +9,7 @@

from agent.graph import AgentGraph
from agent.profiles import ProfileName, get_chat_profiles
from agent.profiles.base import OutputState
from util.chainlit_helpers import (is_feature_enabled, message_rate_limited,
save_openai_metrics, static_messages,
update_search_results)
Expand Down Expand Up @@ -93,7 +93,7 @@ async def main(message: cl.Message) -> None:
openai_cb = OpenAICallbackHandler()

enable_postprocess: bool = is_feature_enabled(config, "postprocessing")
result: dict[str, Any] = await llm_graph.ainvoke(
result: OutputState = await llm_graph.ainvoke(
message.content,
chat_profile.lower(),
callbacks=[chainlit_cb, openai_cb],
Expand Down
3 changes: 3 additions & 0 deletions bin/embeddings_manager
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ from botocore.client import Config

from data_generation.alliance import generate_alliance_embeddings
from data_generation.reactome import generate_reactome_embeddings
from data_generation.uniprot import generate_uniprot_embeddings
from util.embedding_environment import EM_ARCHIVE, EmbeddingEnvironment

S3_BUCKET = "download.reactome.org"
Expand Down Expand Up @@ -86,6 +87,8 @@ def make(
os.environ["HUGGINGFACEHUB_API_TOKEN"] = hf_key
if embedding.db == "reactome":
generate_reactome_embeddings(str(embedding_path), hf_model=embedding.model, **kwargs)
elif embedding.db == "uniprot":
generate_uniprot_embeddings(embedding_path, hf_model=embedding.model, **kwargs)
elif embedding.db == "alliance":
generate_alliance_embeddings(str(embedding_path), hf_model=embedding.model, **kwargs)
else:
Expand Down
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ ignore_missing_imports = True
allow_untyped_calls = True
allow_untyped_defs = True
allow_untyped_globals = True
explicit_package_bases = True
exclude = data/
files = bin/,src/

[mypy.plugins.pandas.*]
init_forbid_dynamic = False
27 changes: 26 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ psycopg = {extras = ["binary"], version = "^3.2.3"}
pydantic = "^2.10.5"
pyyaml = "^6.0.2"
tavily-python = "^0.5.0"
openpyxl = "^3.1.5"

[tool.poetry.group.dev.dependencies]
ruff = "^0.7.1"
Expand Down
9 changes: 5 additions & 4 deletions src/agent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from agent.models import get_embedding, get_llm
from agent.profiles import ProfileName, create_profile_graphs
from agent.profiles.base import InputState, OutputState
from util.logging import logging

LANGGRAPH_DB_URI = f"postgresql://{os.getenv('POSTGRES_USER')}:{os.getenv('POSTGRES_PASSWORD')}@postgres:5432/{os.getenv('POSTGRES_LANGGRAPH_DB')}?sslmode=disable"
Expand Down Expand Up @@ -81,13 +82,13 @@ async def ainvoke(
callbacks: Callbacks,
thread_id: str,
enable_postprocess: bool = True,
) -> dict[str, Any]:
) -> OutputState:
if self.graph is None:
self.graph = await self.initialize()
if profile not in self.graph:
return {}
result: dict[str, Any] = await self.graph[profile].ainvoke(
{"user_input": user_input},
return OutputState()
result: OutputState = await self.graph[profile].ainvoke(
InputState(user_input=user_input),
config=RunnableConfig(
callbacks=callbacks,
configurable={
Expand Down
11 changes: 9 additions & 2 deletions src/agent/profiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from langchain_core.language_models.chat_models import BaseChatModel
from langgraph.graph.state import StateGraph

from agent.profiles.react_to_me import create_reacttome_graph
from agent.profiles.cross_database import create_cross_database_graph
from agent.profiles.react_to_me import create_reactome_graph


class ProfileName(StrEnum):
# These should exactly match names in .config.schema.yaml
React_to_Me = "React-to-Me"
Cross_Database_Prototype = "Cross-Database Prototype"


class Profile(NamedTuple):
Expand All @@ -23,7 +25,12 @@ class Profile(NamedTuple):
ProfileName.React_to_Me.lower(): Profile(
name=ProfileName.React_to_Me,
description="An AI assistant specialized in exploring **Reactome** biological pathways and processes.",
graph_builder=create_reacttome_graph,
graph_builder=create_reactome_graph,
),
ProfileName.Cross_Database_Prototype.lower(): Profile(
name=ProfileName.Cross_Database_Prototype,
description="Early version of an AI assistant with knowledge from multiple bio-databases (**Reactome** + **Uniprot**).",
graph_builder=create_cross_database_graph,
),
}

Expand Down
40 changes: 32 additions & 8 deletions src/agent/profiles/base.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
from typing import Annotated, TypedDict

from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import BaseMessage
from langchain_core.runnables import Runnable, RunnableConfig
from langgraph.graph.message import add_messages

from agent.tasks.rephrase import create_rephrase_chain
from tools.external_search.state import WebSearchResult


class AdditionalContent(TypedDict):
class AdditionalContent(TypedDict, total=False):
search_results: list[WebSearchResult]


class BaseState(TypedDict):
# (Everything the Chainlit layer uses should be included here)

class InputState(TypedDict, total=False):
user_input: str # User input text
chat_history: Annotated[list[BaseMessage], add_messages]
context: list[Document]


class OutputState(TypedDict, total=False):
answer: str # primary LLM response that is streamed to the user
additional_content: AdditionalContent # sends on graph completion


class BaseState(InputState, OutputState, total=False):
rephrased_input: str # LLM-generated query from user input
chat_history: Annotated[list[BaseMessage], add_messages]


class BaseGraphBuilder:
pass # NOTE: Anything that is common to all graph builders goes here
# NOTE: Anything that is common to all graph builders goes here

def __init__(
self,
llm: BaseChatModel,
embedding: Embeddings,
) -> None:
self.rephrase_chain: Runnable = create_rephrase_chain(llm)

async def preprocess(self, state: BaseState, config: RunnableConfig) -> BaseState:
rephrased_input: str = await self.rephrase_chain.ainvoke(
{
"user_input": state["user_input"],
"chat_history": state["chat_history"],
},
config,
)
return BaseState(rephrased_input=rephrased_input)
Loading