-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtext_classification.py
More file actions
32 lines (23 loc) · 825 Bytes
/
text_classification.py
File metadata and controls
32 lines (23 loc) · 825 Bytes
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
import os
from langchain_core.prompts import PromptTemplate
from langchain_google_vertexai import ChatVertexAI
if __name__ == "__main__":
llm = ChatVertexAI(
project=os.environ["PROJECT_ID"],
location="us-central1",
model="gemini-2.0-flash"
)
prompt_template = PromptTemplate.from_template("""
Analyze the sentiment of the text below. Respond only with one word to describe the sentiment.
INPUT: This is fantastic news!
OUTPUT: POSITIVE
INPUT: Pi is roughly equal to 3.14
OUTPUT: NEUTRAL
INPUT: I really disliked the pizza. Who would use pineapples as a pizza topping?
OUTPUT: NEGATIVE
INPUT: {text}
OUTPUT:
""")
prompt = prompt_template.format(text="I love strawberries!")
response = llm.invoke(prompt)
print(response.content)