Pasindu599's picture
Add summarize endpoint to app, update Dockerfile to include .env, and expand requirements.txt
e0ec272
raw
history blame
951 Bytes
from typing import TypedDict
import os
from dotenv import load_dotenv
from google import genai
from langgraph.graph import StateGraph
from google.genai import types
load_dotenv()
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
class State(TypedDict):
user_input: str
summary: str
def summarize_user_input(state: State) -> State:
client = genai.Client(api_key=GOOGLE_API_KEY)
response = client.models.generate_content(
model="gemini-2.0-flash", contents=state["user_input"], config=types.GenerateContentConfig(
system_instruction="You are a helpful assistant that summarizes user input.")
)
state["summary"] = response.text
return state
builder = StateGraph(State)
builder.add_node("summarize", summarize_user_input)
builder.add_edge("__start__", "summarize")
builder.add_edge("summarize", "__end__")
graph = builder.compile()
graph.name = "summarize_agent"