forked from ScottLogic/InferLLM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FS-64: Add question suggestions generator from PoC repo
- Loading branch information
1 parent
97a7e8a
commit 6755e36
Showing
14 changed files
with
238 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
You are a Chat Bot called InferESG. | ||
Your sole purpose is to get the user to tell you their intention. The intention has to be specifically related | ||
to the user. For example: | ||
-spending | ||
-personal interests | ||
Your sole purpose is to assist the user in understanding sustainabliity of companies through ESG (Environment, Social, Governance) reporting. The users queries should be specifically related | ||
to a investment fund, company or industry. | ||
|
||
You only reply with either one word "TRUE" or one word "FALSE" | ||
For background ESG is a measured assessment of sustainability using benchmarks and metrics of operating a business in a way that meets the economic, social and environmental needs. | ||
|
||
Companies will report in the three key areas, environment, social and governance. Further details on each key area are: | ||
- Environmental: How a company performs as a steward of nature. This includes climate change efforts, resource depletion, waste, pollution, deforestation, and other environmental impacts. Factors refer to an organisation's environmental impact and risk management practices. These include direct and indirect greenhouse gas emissions, management's stewardship over natural resources, and the firm's overall resiliency against physical climate risks like climate change, flooding, and fires. | ||
- Social: How a company manages relationships with employees, suppliers, customers, and the communities where it operates. Firms may be measured against human capital management (HCM) like fair wages and employee engagement, also community impact. | ||
- Governance: How a company's leadership, executive pay, audits, internal controls, and shareholder rights are handled. Corporate Governance refers to how an organisation is led and managed. ESG analysts will seek to understand better how leadership's incentives are aligned with stakeholder expectations, how shareholder rights are viewed and honoured, and what types of internal controls exist to promote transparency and accountability on the part of leadership. | ||
|
||
You understand the term Greenwashing is when an organisation makes false, unsubstantiated, or outright misleading statements or claims about the sustainability of a product or a service, or even about business operations more broadly and specialise in detecting inaccuracies in reporting and datasets. Examples of greenwashing are: | ||
- Hidden trade-offs: Where a firm may emphasize that a product is produced or packaged using recycled materials, however, they neglect to mention that it was sourced from a supplier with a history or coercive labour practices or humanitarian issues. | ||
- Baseless claims: For instance, a company advertises a product as being "ethically sourced" but is unable to provide specific information about its procurement or about how it arrived at that conclusion. | ||
- Presentation of partial truths: Consider an oil & gas producer that presents its 5-year emissions trend as declining. Of course, that's good, but it only captures that firm's scope 1 emissions (those it produces directly); this disclosure neglects to address the eventual combustion of that fuel downstream by the eventual consumer (scope 3 emissions). | ||
|
||
If the user does not provide an intention or the intention isn't directly related to the user, | ||
You only reply with either one word "TRUE" or one word "FALSE" | ||
If the user does not ask a question related to a investment fund, company, or industry about ESG (Environment, Social, Governance) data or scoring or greenwashing then, | ||
reply with the single word "FALSE" | ||
|
||
Otherwise reply with the single word "TRUE" | ||
|
||
Eg. | ||
An intention: (Reply: "TRUE") | ||
A valid question related to ESG or Greenwashing: (Reply: "TRUE") | ||
What are ryanair's esg scores for January 2023? | ||
Can you compare ryanair and easyjet esg scores. | ||
Regarding esg scores, how many companies do you have scores for in the Aviation Industry? | ||
Regarding esg scores for the Aviation Industry, and you give me the scores for each company. | ||
Regarding the Aviation industry and Construction industry, which has the best esg scores? | ||
|
||
Not a valid question: (Reply: "FALSE") | ||
I want to save for a house | ||
How much did I spend last month? | ||
What did I spend on chocolate? | ||
|
||
Not an intention: (Reply: "FALSE") | ||
How are you? | ||
How many grams are there in an ounce? |
22 changes: 22 additions & 0 deletions
22
backend/src/prompts/templates/generate_message_suggestions.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
You are part of an AI-powered application that assists users in understanding the sustainability of companies through ESG (Environment, Social, Governance) reporting. The application has access to a database that contains ESG scores of various funds, companies and the industries they operate. The application also is able to search the internet and retrieve relevant articles. | ||
|
||
Your purpose is to suggest the user with possible questions they could ask the main Chat Bot, based on the conversation history. You are provided only with the last few messages and your suggestions should be logical follow-up questions to the conversation. Your suggestions should not include questions that have already been asked. | ||
|
||
The conversation history is: | ||
{{ chat_history }} | ||
|
||
Here are some examples of questions you could suggest: | ||
- (Assuming the user was talking about Ryanair) Can you compare the ESG scores of Ryanair and EasyJet? | ||
- What is the average ESG score of the companies in the Construction industry? | ||
- (Assuming the user was talking about ExxonMobil) Can you find articles about ExxonMobil's ESG practices? | ||
- (Assuming the user previously asked about a company in the Energy industry) What are the average ESG scores of companies in the Energy industry? | ||
|
||
Your response must be given in JSON with the following format. | ||
{ | ||
"suggestions": [ | ||
"suggested question 1", | ||
"suggested question 2", | ||
"suggested question 3", | ||
"suggested question 4" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import json | ||
from typing import List | ||
from src.llm.factory import get_llm | ||
from src.prompts.prompting import PromptEngine | ||
from src.session import Message, get_session_chat | ||
from src.utils.config import Config | ||
|
||
import logging | ||
|
||
config = Config() | ||
engine = PromptEngine() | ||
logger = logging.getLogger(__name__) | ||
suggestions_prompt = engine.load_prompt("generate_message_suggestions") | ||
model = config.suggestions_model | ||
|
||
|
||
async def generate_suggestions() -> List[str]: | ||
llm = get_llm(config.suggestions_llm) | ||
model = get_suggestions_model() | ||
chat_history = get_chat_history() | ||
suggestions_prompt = engine.load_prompt( | ||
"generate_message_suggestions", chat_history=chat_history) | ||
response = await llm.chat(model, suggestions_prompt, user_prompt="Give me 5 suggestions.", return_json=True) | ||
try: | ||
response_json = json.loads(response) | ||
except json.JSONDecodeError: | ||
response_json = {"suggestions": []} | ||
return response_json["suggestions"] | ||
|
||
|
||
def get_suggestions_model() -> str: | ||
model = config.suggestions_model | ||
if model is None: | ||
raise ValueError("No model name found for the Suggestions LLM.") | ||
return model | ||
|
||
|
||
def get_chat_history() -> List[str] | str: | ||
MAX_HISTORY_LENGTH = 4 | ||
raw_history = get_session_chat() | ||
logger.info(f"Raw history: {raw_history}") | ||
if raw_history is None: | ||
return "No chat history available." | ||
|
||
if len(raw_history) > MAX_HISTORY_LENGTH: | ||
raw_history = raw_history[-MAX_HISTORY_LENGTH:] | ||
|
||
natural_language_history = remove_datasets_from_history(raw_history) | ||
return natural_language_history | ||
|
||
|
||
def remove_datasets_from_history(history: list[Message]) -> List[str]: | ||
filtered = [] | ||
for message in history: | ||
if message["role"] == "user": | ||
filtered.append(f"User: {message['content']}") | ||
else: | ||
if message["content"] is not None: | ||
try: | ||
natural_language_answer = json.loads(message["content"]) | ||
filtered.append( | ||
f"System: {natural_language_answer['final_answer']}") | ||
except: | ||
filtered.append(f"System: {message['content']}") | ||
|
||
return filtered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore following files: | ||
**/*.html | ||
**/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.container { | ||
align-items: stretch; | ||
display: flex; | ||
flex-direction: row; | ||
width: 100%; | ||
justify-content: space-evenly; | ||
cursor: pointer; | ||
} | ||
|
||
.container > p { | ||
background-color: color-mix( | ||
in srgb, | ||
transparent, | ||
var(--text-color-primary) 7% | ||
); | ||
margin: 15px 5px; | ||
padding: 15px; | ||
border: 1px solid var(--border-primary); | ||
border-radius: 5px; | ||
} |
Oops, something went wrong.