Spaces:
Sleeping
Sleeping
File size: 1,281 Bytes
b2e1431 eeefa20 b2e1431 eeefa20 b2e1431 eeefa20 b2e1431 | 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 | from dotenv import load_dotenv
load_dotenv()
import os
from langchain.prompts import PromptTemplate
from langchain_google_genai import ChatGoogleGenerativeAI
classification_modeL_cache = {}
llm_model_cache = {}
def get_llm(model_name="gemini-2.5-flash-lite"):
return ChatGoogleGenerativeAI(
model=model_name,
temperature=0.6,
top_p=0.8,
top_k=1,
max_tokens=None,
max_retries=3,
google_api_key=os.getenv("GOOGLE_API_KEY"),
)
prompt = PromptTemplate(
input_variables=["text", "positive_prob", "negative_prob"],
template="""
You are Sen, a sentiment analysis assistant.
TEXT:
{text}
PROBABILITY OF BEING POSITIVE:
{positive_prob}
PROBABILITY OF BEING NEGATIVE:
{negative_prob}
Given the above text and probabilities, please analyze the user's content.
""")
eval_prompt = PromptTemplate(
input_variables=["text"],
template="""
You are agent who analyze the sentiment in Twitter's tweets.
LIST OF TWEETS:
{text}
INSTRUCTIONS
For each tweet in LIST OF TWEETS, analyze the sentiment only without any explanation, in the format: "positive" or "negative"
EXAMPLE:
["positive", "negative", "positive", "negative", "positive"]
"""
) |