mirror of
https://github.com/SirBlobby/Hoya26.git
synced 2026-02-03 19:24: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 .client import generate_content
|
||||
|
||||
GREENWASHING_ANALYSIS_PROMPT = """
|
||||
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]
|
||||
- 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)
|
||||
def ask(prompt):
|
||||
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
|
||||
return client.models.generate_content(model="gemini-2.0-flash-exp", contents=prompt).text
|
||||
|
||||
filter_metadata = None
|
||||
if category:
|
||||
filter_metadata = {"category": category}
|
||||
def analyze(query, query_embedding, num_results=5, num_alternatives=3):
|
||||
results = search_documents(query_embedding, num_results=num_results + num_alternatives + 5)
|
||||
|
||||
search_results = search_documents(
|
||||
query_embedding,
|
||||
num_results=num_results,
|
||||
filter_metadata=filter_metadata
|
||||
)
|
||||
context = "--- START OF REPORT CONTEXT ---\n"
|
||||
for res in results[:num_results]:
|
||||
context += f"RELEVANT DATA CHUNK: {res['text']}\n\n"
|
||||
context += "--- END OF REPORT CONTEXT ---\n"
|
||||
|
||||
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"
|
||||
full_prompt = f"{GREENWASHING_ANALYSIS_PROMPT}\n\n{context}\n\nUSER QUERY/COMPANY FOCUS: {query}"
|
||||
analysis_text = ask(full_prompt)
|
||||
|
||||
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."
|
||||
alternatives = []
|
||||
seen_texts = set()
|
||||
for res in results[num_results:]:
|
||||
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 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)
|
||||
return {"analysis": analysis_text, "alternatives": alternatives}
|
||||
|
||||
@@ -3,15 +3,9 @@ import os
|
||||
|
||||
def generate_content(prompt, model_name="gemini-2.0-flash-exp"):
|
||||
api_key = os.environ.get("GOOGLE_API_KEY")
|
||||
if not api_key:
|
||||
return "Error: GOOGLE_API_KEY not found."
|
||||
|
||||
try:
|
||||
client = genai.Client(api_key=api_key)
|
||||
response = client.models.generate_content(
|
||||
model=model_name,
|
||||
contents=prompt,
|
||||
)
|
||||
return response.text
|
||||
except Exception as e:
|
||||
return f"Error interacting with Gemini API: {str(e)}"
|
||||
client = genai.Client(api_key=api_key)
|
||||
response = client.models.generate_content(
|
||||
model=model_name,
|
||||
contents=prompt,
|
||||
)
|
||||
return response.text
|
||||
|
||||
0
backend/src/gemini/reporting.py
Normal file
0
backend/src/gemini/reporting.py
Normal file
Reference in New Issue
Block a user