-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwith_Structured_output_typedict.py
38 lines (26 loc) · 2.1 KB
/
with_Structured_output_typedict.py
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
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
from typing import TypedDict, Annotated, Optional, Literal
load_dotenv()
model = ChatGoogleGenerativeAI(model='gemini-1.5-pro')
# schema
class Review(TypedDict):
key_themes: Annotated[list[str], "Write down all the key themes discussed in the review in a list"]
summary: Annotated[str, "A brief summary of the review"]
sentiment: Annotated[Literal["pos", "neg"], "Return sentiment of the review either negative, positive or neutral"]
pros: Annotated[Optional[list[str]], "Write down all the pros inside a list"]
cons: Annotated[Optional[list[str]], "Write down all the cons inside a list"]
name: Annotated[Optional[str], "Write the name of the reviewer"]
structured_model = model.with_structured_output(Review)
result = structured_model.invoke("""I recently upgraded to the Samsung Galaxy S24 Ultra, and I must say, it’s an absolute powerhouse! The Snapdragon 8 Gen 3 processor makes everything lightning fast—whether I’m gaming, multitasking, or editing photos. The 5000mAh battery easily lasts a full day even with heavy use, and the 45W fast charging is a lifesaver.
The S-Pen integration is a great touch for note-taking and quick sketches, though I don't use it often. What really blew me away is the 200MP camera—the night mode is stunning, capturing crisp, vibrant images even in low light. Zooming up to 100x actually works well for distant objects, but anything beyond 30x loses quality.
However, the weight and size make it a bit uncomfortable for one-handed use. Also, Samsung’s One UI still comes with bloatware—why do I need five different Samsung apps for things Google already provides? The $1,300 price tag is also a hard pill to swallow.
Pros:
Insanely powerful processor (great for gaming and productivity)
Stunning 200MP camera with incredible zoom capabilities
Long battery life with fast charging
S-Pen support is unique and useful
Review written by AI
""")
print(result["cons"])