mirror of
https://github.com/SirBlobby/Hoya26.git
synced 2026-02-04 03:34:34 -05:00
Gemeni Prompt
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from src.rag.embeddings import get_embedding
|
import os
|
||||||
|
from google import genai
|
||||||
from src.chroma.vector_store import search_documents
|
from src.chroma.vector_store import search_documents
|
||||||
from .client import generate_content
|
|
||||||
|
|
||||||
GREENWASHING_ANALYSIS_PROMPT = """
|
GREENWASHING_ANALYSIS_PROMPT = """
|
||||||
You are an expert Environmental, Social, and Governance (ESG) Analyst specialized in detecting 'Greenwashing'.
|
You are an expert Environmental, Social, and Governance (ESG) Analyst specialized in detecting 'Greenwashing'.
|
||||||
@@ -18,40 +18,31 @@ Based on the context provided, give a final verdict:
|
|||||||
- VERDICT: [Clear/Suspect/High Risk of Greenwashing]
|
- VERDICT: [Clear/Suspect/High Risk of Greenwashing]
|
||||||
- REASONING: [Explain your findings clearly]
|
- REASONING: [Explain your findings clearly]
|
||||||
- EVIDENCE: [Quote specific parts of the context if possible]
|
- 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):
|
def ask(prompt):
|
||||||
try:
|
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
|
||||||
query_embedding = get_embedding(query)
|
return client.models.generate_content(model="gemini-2.0-flash-exp", contents=prompt).text
|
||||||
|
|
||||||
filter_metadata = None
|
def analyze(query, query_embedding, num_results=5, num_alternatives=3):
|
||||||
if category:
|
results = search_documents(query_embedding, num_results=num_results + num_alternatives + 5)
|
||||||
filter_metadata = {"category": category}
|
|
||||||
|
|
||||||
search_results = search_documents(
|
context = "--- START OF REPORT CONTEXT ---\n"
|
||||||
query_embedding,
|
for res in results[:num_results]:
|
||||||
num_results=num_results,
|
context += f"RELEVANT DATA CHUNK: {res['text']}\n\n"
|
||||||
filter_metadata=filter_metadata
|
context += "--- END OF REPORT CONTEXT ---\n"
|
||||||
)
|
|
||||||
|
|
||||||
context = ""
|
full_prompt = f"{GREENWASHING_ANALYSIS_PROMPT}\n\n{context}\n\nUSER QUERY/COMPANY FOCUS: {query}"
|
||||||
if search_results:
|
analysis_text = ask(full_prompt)
|
||||||
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:
|
alternatives = []
|
||||||
full_prompt = f"{GREENWASHING_ANALYSIS_PROMPT}\n\n{context}\n\nUSER QUERY/COMPANY FOCUS: {query}"
|
seen_texts = set()
|
||||||
else:
|
for res in results[num_results:]:
|
||||||
return "No data found in the report to analyze. Please upload a report first."
|
text_preview = res['text'][:200]
|
||||||
|
if text_preview not in seen_texts:
|
||||||
|
seen_texts.add(text_preview)
|
||||||
|
alternatives.append({"text": res['text'], "score": res.get('score'), "summary": text_preview})
|
||||||
|
if len(alternatives) >= num_alternatives:
|
||||||
|
break
|
||||||
|
|
||||||
response = generate_content(full_prompt)
|
return {"analysis": analysis_text, "alternatives": alternatives}
|
||||||
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)
|
|
||||||
|
|||||||
@@ -3,15 +3,9 @@ import os
|
|||||||
|
|
||||||
def generate_content(prompt, model_name="gemini-2.0-flash-exp"):
|
def generate_content(prompt, model_name="gemini-2.0-flash-exp"):
|
||||||
api_key = os.environ.get("GOOGLE_API_KEY")
|
api_key = os.environ.get("GOOGLE_API_KEY")
|
||||||
if not api_key:
|
client = genai.Client(api_key=api_key)
|
||||||
return "Error: GOOGLE_API_KEY not found."
|
response = client.models.generate_content(
|
||||||
|
model=model_name,
|
||||||
try:
|
contents=prompt,
|
||||||
client = genai.Client(api_key=api_key)
|
)
|
||||||
response = client.models.generate_content(
|
return response.text
|
||||||
model=model_name,
|
|
||||||
contents=prompt,
|
|
||||||
)
|
|
||||||
return response.text
|
|
||||||
except Exception as e:
|
|
||||||
return f"Error interacting with Gemini API: {str(e)}"
|
|
||||||
|
|||||||
0
backend/src/gemini/reporting.py
Normal file
0
backend/src/gemini/reporting.py
Normal file
Reference in New Issue
Block a user