Skip to content

Commit

Permalink
fixed how the chatbot presents answers, tickets #331 and #342
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Aug 26, 2023
1 parent 98f8743 commit 57905c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
38 changes: 29 additions & 9 deletions application/frontend/src/pages/chatbot/chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const Chatbot = () => {
'yaml',
'zephir',
];
type chatMessage = { timestamp: string; role: string; message: string; data: Document[] | null };
type chatMessage = { timestamp: string; role: string; message: string; data: Document[] | null; };
interface ChatState {
term: string;
error: string;
Expand Down Expand Up @@ -287,7 +287,7 @@ export const Chatbot = () => {
timestamp: new Date().toLocaleTimeString(),
role: 'assistant',
message: data.response,
data: data.table,
data: data.table
},
]);
})
Expand All @@ -299,11 +299,23 @@ export const Chatbot = () => {
}

function displayDocument(d: Document) {
return (
<a href={d.hyperlink} target="_blank">
*Reference: The above answer was based on the {d.name} section of{' '}
{d.section ? d.section : d.sectionID};
</a>

var link = "/node/" + d.doctype.toLowerCase() + "/" + d.name
if (d.section) {
link = link + "/section/" + d.section
} else {
link = link + "/sectionid/" + d.sectionID
}
return (<p>
<p>*Reference: The above answer was based on:
<a href={d.hyperlink} target="_blank"> {d.name} section: {' '}
{d.section ? d.section : d.sectionID};
</a>
</p>
<p>
You can find more information about {d.name} <a href={link}> on its OpenCRE page</a>
</p>
</p>
);
}

Expand Down Expand Up @@ -337,8 +349,8 @@ export const Chatbot = () => {
<Comment.Text>{processResponse(m.message)}</Comment.Text>
{m.data
? m.data?.map((m2) => {
return displayDocument(m2);
})
return displayDocument(m2);
})
: ''}
</Comment.Content>
</Comment>
Expand Down Expand Up @@ -372,6 +384,14 @@ export const Chatbot = () => {
<div className="table-container mt-5 ms-5 d-none">
<div className="table-content bg-light shadow p-3" id="table-content"></div>
</div>
<div className='chatbot'>
<i>
ChatCRE uses Google's PALM2 LLM, you can find the code for OpenCRE in https://github.com/owaps/OpenCRE.
Your question travels to Heroku (OpenCRE hosting provider) and then to GCP over a protected connection.
Your data is never stored in the OpenCRE servers, you can start a new session by refreshing your page.
The OpenCRE team has taken all reasonable precautions we could think off to protect your privacy and security.
</i>
</div>
</Grid>
</Container>
</Grid.Column>
Expand Down
9 changes: 4 additions & 5 deletions application/prompt_client/prompt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ def generate_text(self, prompt: str) -> Dict[str, str]:
timestamp = datetime.now().strftime("%I:%M:%S %p")
if not prompt:
return {"response": "", "table": "", "timestamp": timestamp}
logger.info(f"getting embeddings for {prompt}")
logger.debug(f"getting embeddings for {prompt}")
question_embedding = self.ai_client.get_text_embeddings(prompt)
logger.info(f"retrieved embeddings for {prompt}")
logger.debug(f"retrieved embeddings for {prompt}")

# Find the closest area in the existing embeddings
closest_id, similarity = self.get_id_of_most_similar_node_paginated(
Expand All @@ -426,8 +426,7 @@ def generate_text(self, prompt: str) -> Dict[str, str]:
)
closest_object = self.database.get_node_by_db_id(closest_id)
answer = ""

logger.info(
logger.debug(
f"The prompt {prompt}, was most similar to object \n{closest_object}\n, with similarity:{similarity}"
)
closest_content = ""
Expand All @@ -449,7 +448,7 @@ def generate_text(self, prompt: str) -> Dict[str, str]:
else:
return {"response": "An adequate answer could not be found", "table": [""]}

logger.info(f"retrieved completion for {prompt}")
logger.debug(f"retrieved completion for {prompt}")
table = [closest_object]
result = f"Answer: {answer}"
return {"response": result, "table": table}

0 comments on commit 57905c9

Please sign in to comment.