Spaces:
Sleeping
Sleeping
File size: 951 Bytes
e0ec272 |
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 |
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"
|