mirror of
https://github.com/SirBlobby/Hoya26.git
synced 2026-02-04 03:34:34 -05:00
gemeni endpoints
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
from src.rag.embeddings import get_embedding
|
||||
from src.chroma.vector_store import search_documents
|
||||
from .client import generate_content
|
||||
|
||||
GREENWASHING_ANALYSIS_PROMPT = """
|
||||
You are an expert Environmental, Social, and Governance (ESG) Analyst specialized in detecting 'Greenwashing'.
|
||||
Your task is to analyze the provided context from a company's data reports and determine if they are engaging in greenwashing.
|
||||
|
||||
Greenwashing is defined as making misleading or unsubstantiated claims about the environmental benefits of a product, service, or company practice.
|
||||
|
||||
Please evaluate the following:
|
||||
1. Vague Claims: Are they using broad terms like 'eco-friendly' without specific details?
|
||||
2. Lack of Proof: Are claims backed by data, third-party certifications, or specific metrics?
|
||||
3. Hidden Trade-offs: Do they highlight one green act while ignoring a much larger environmental harm?
|
||||
4. Symbolic Actions: Are they focusing on minor changes while their core business remains highly polluting?
|
||||
|
||||
Based on the context provided, give a final verdict:
|
||||
- VERDICT: [Clear/Suspect/High Risk of Greenwashing]
|
||||
- REASONING: [Explain your findings clearly]
|
||||
- EVIDENCE: [Quote specific parts of the context if possible]
|
||||
- BETTER ALTERNATIVES: [Suggest 2-3 similar companies or products that have verified sustainability records or higher transparency in this specific area]
|
||||
"""
|
||||
|
||||
def analyze_greenwashing(query, category=None, num_results=10):
|
||||
try:
|
||||
query_embedding = get_embedding(query)
|
||||
|
||||
filter_metadata = None
|
||||
if category:
|
||||
filter_metadata = {"category": category}
|
||||
|
||||
search_results = search_documents(
|
||||
query_embedding,
|
||||
num_results=num_results,
|
||||
filter_metadata=filter_metadata
|
||||
)
|
||||
|
||||
context = ""
|
||||
if search_results:
|
||||
context = "--- START OF REPORT CONTEXT ---\n"
|
||||
for res in search_results:
|
||||
context += f"RELEVANT DATA CHUNK: {res['text']}\n\n"
|
||||
context += "--- END OF REPORT CONTEXT ---\n"
|
||||
|
||||
if context:
|
||||
full_prompt = f"{GREENWASHING_ANALYSIS_PROMPT}\n\n{context}\n\nUSER QUERY/COMPANY FOCUS: {query}"
|
||||
else:
|
||||
return "No data found in the report to analyze. Please upload a report first."
|
||||
|
||||
response = generate_content(full_prompt)
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
return f"Error in Analysis process: {str(e)}"
|
||||
|
||||
def ask_gemini_with_rag(query, category=None, num_results=5):
|
||||
return analyze_greenwashing(query, category, num_results)
|
||||
|
||||
Reference in New Issue
Block a user