open-notebook/open_notebook/graphs/prompt.py
Luis Novo b7e656a319
Version 1 (#160)
New front-end
Launch Chat API
Manage Sources
Enable re-embedding of all contents
Sources can be added without a notebook now
Improved settings
Enable model selector on all chats
Background processing for better experience
Dark mode
Improved Notes

Improved Docs: 
- Remove all Streamlit references from documentation
- Update deployment guides with React frontend setup
- Fix Docker environment variables format (SURREAL_URL, SURREAL_PASSWORD)
- Update docker image tag from :latest to :v1-latest
- Change navigation references (Settings → Models to just Models)
- Update development setup to include frontend npm commands
- Add MIGRATION.md guide for users upgrading from Streamlit
- Update quick-start guide with correct environment variables
- Add port 5055 documentation for API access
- Update project structure to reflect frontend/ directory
- Remove outdated source-chat documentation files
2025-10-18 12:46:22 -03:00

42 lines
1.2 KiB
Python

from typing import Any, Optional
from ai_prompter import Prompter
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.runnables import RunnableConfig
from langgraph.graph import END, START, StateGraph
from typing_extensions import TypedDict
from open_notebook.graphs.utils import provision_langchain_model
class PatternChainState(TypedDict):
prompt: str
parser: Optional[Any]
input_text: str
output: str
async def call_model(state: dict, config: RunnableConfig) -> dict:
content = state["input_text"]
system_prompt = Prompter(
template_text=state["prompt"], parser=state.get("parser")
).render(data=state)
payload = [SystemMessage(content=system_prompt)] + [HumanMessage(content=content)]
chain = await provision_langchain_model(
str(payload),
config.get("configurable", {}).get("model_id"),
"transformation",
max_tokens=5000,
)
response = await chain.ainvoke(payload)
return {"output": response.content}
agent_state = StateGraph(PatternChainState)
agent_state.add_node("agent", call_model) # type: ignore[type-var]
agent_state.add_edge(START, "agent")
agent_state.add_edge("agent", END)
graph = agent_state.compile()