Skip to content

Commit

Permalink
fix: CWYD-Contract Assistant - Landing page should mention Contract A…
Browse files Browse the repository at this point in the history
…ssistant (similar to our Research Assistant accelerator) (Azure-Samples#1199)

Co-authored-by: Himanshi Agrawal <[email protected]>
Co-authored-by: Roopan P M <[email protected]>
Co-authored-by: Roopan-Microsoft <[email protected]>
Co-authored-by: Harmanpreet Kaur <[email protected]>
Co-authored-by: Pavan Kumar <v-kupavan.microsoft.com>
  • Loading branch information
5 people authored Aug 5, 2024
1 parent 6ba499f commit 1448c01
Show file tree
Hide file tree
Showing 36 changed files with 251 additions and 50 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ In this scenario, a financial advisor is preparing for a meeting with a potentia

Now that the financial advisor is more informed about Woodgrove’s Emerging Markets Funds, they're better equipped to respond to questions about this fund from their client.

#### Contract Review and Summarization Assistant scenario
Additionally, we have implemented a Contract Review and Summarization Assistant scenario to demonstrate how this accelerator can be utilized in any industry. The Contract Review and Summarization Assistant helps professionals manage and interact with a large collection of documents efficiently. For more details, refer to the [Contract Review and Summarization Assistant README](docs/contract_assistance.md).
#### Legal Review and Summarization Assistant scenario
Additionally, we have implemented a Legal Review and Summarization Assistant scenario to demonstrate how this accelerator can be utilized in any industry. The Legal Review and Summarization Assistant helps professionals manage and interact with a large collection of documents efficiently. For more details, refer to the [Legal Review and Summarization Assistant README](docs/contract_assistance.md).

Note: Some of the sample data included with this accelerator was generated using AI and is for illustrative purposes only.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class AssistantStrategy(Enum):
DEFAULT = "default"
LEGAL_ASSISTANT = "legal assistant"
CONTRACT_ASSISTANT = "contract assistant"
12 changes: 6 additions & 6 deletions code/backend/batch/utilities/helpers/config/config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ def get_default_config():

@staticmethod
@functools.cache
def get_default_legal_assistant():
legal_file_path = os.path.join(os.path.dirname(__file__), "default_legal_assistant_prompt.txt")
legal_assistant = ""
with open(legal_file_path, encoding="utf-8") as f:
legal_assistant = f.readlines()
def get_default_contract_assistant():
contract_file_path = os.path.join(os.path.dirname(__file__), "default_contract_assistant_prompt.txt")
contract_assistant = ""
with open(contract_file_path, encoding="utf-8") as f:
contract_assistant = f.readlines()

return ''.join([str(elem) for elem in legal_assistant])
return ''.join([str(elem) for elem in contract_assistant])

@staticmethod
def clear_config():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
- If the information is not available in the context, reply that the information is not in the knowledge base.

## Very Important Instruction
- YOU ARE AN AI LEGAL ASSISTANT.
- YOU ARE AN AI CONTRACT ASSISTANT.
- If you can't answer a question using available documents, reply politely that the information is not in the knowledge base.
- Questions with a date range, use documents within the same range.
Question: {question}
Expand Down
14 changes: 6 additions & 8 deletions code/backend/pages/04_Configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@ def validate_answering_user_prompt():
st.warning("Your answering prompt doesn't contain the variable `{question}`")


def config_legal_assistant_prompt():
if st.session_state["ai_assistant_type"] == AssistantStrategy.LEGAL_ASSISTANT.value:
st.success("Legal Assistant Prompt")
st.session_state["answering_user_prompt"] = (
ConfigHelper.get_default_legal_assistant()
)
def config_contract_assistant_prompt():
if st.session_state["ai_assistant_type"] == AssistantStrategy.CONTRACT_ASSISTANT.value:
st.success("Contract Assistant Prompt")
st.session_state["answering_user_prompt"] = ConfigHelper.get_default_contract_assistant()
else:
st.success("Default Assistant Prompt")
st.session_state["answering_user_prompt"] = (
Expand Down Expand Up @@ -190,7 +188,7 @@ def validate_documents():
post_answering_prompt_help = "You can configure a post prompt that allows to fact-check or process the answer, given the sources, question and answer. This prompt needs to return `True` or `False`."
use_on_your_data_format_help = "Whether to use a similar prompt format to Azure OpenAI On Your Data, including separate system and user messages, and a few-shot example."
post_answering_filter_help = "The message that is returned to the user, when the post-answering prompt returns."
ai_assistant_type_help = "Whether to use the default user prompt or the Legal Assistance user prompt. Refer to the Legal Assistance README for more details."
ai_assistant_type_help = "Whether to use the default user prompt or the Contract Assistance user prompt. Refer to the Contract Assistance README for more details."
example_documents_help = (
"JSON object containing documents retrieved from the knowledge base, in the following format: \n"
"""```json
Expand Down Expand Up @@ -219,7 +217,7 @@ def validate_documents():
st.selectbox(
"Assistant Type",
key="ai_assistant_type",
on_change=config_legal_assistant_prompt,
on_change=config_contract_assistant_prompt,
options=config.get_available_ai_assistant_types(),
help=ai_assistant_type_help,
)
Expand Down
6 changes: 6 additions & 0 deletions code/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,10 @@ def speech_config():

return {"error": "Failed to get speech config"}, 500

@app.route("/api/assistanttype", methods=["GET"])
def assistanttype():
ConfigHelper.get_active_config_or_default.cache_clear()
result = ConfigHelper.get_active_config_or_default()
return jsonify({"ai_assistant_type": result.prompts.ai_assistant_type})

return app
21 changes: 21 additions & 0 deletions code/frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,24 @@ export async function callConversationApi(options: ConversationRequest, abortSig

return response;
}

export async function getAssistantTypeApi() {
try {
const response = await fetch("/api/assistanttype", {
method: "GET",
headers: {
"Content-Type": "application/json"
},
});

if (!response.ok) {
throw new Error('Network response was not ok');
}

const config = await response.json(); // Parse JSON response
return config;
} catch (error) {
console.error('Failed to fetch configuration:', error);
return null; // Return null or some default value in case of error
}
}
3 changes: 3 additions & 0 deletions code/frontend/src/assets/Interact with data.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions code/frontend/src/assets/Quick source reference.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions code/frontend/src/assets/Summarize contracts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions code/frontend/src/pages/chat/Cards_contract/Cards.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

/* Homepage.module.css */
.container {
display: flex;
flex-direction: column;
align-items: center;
padding: 16px;
/* background-color: #FAF9F8; */
}

.mainContent {
width: 100%;
display: flex;
justify-content: center;
}

.cards {
display: flex;
flex-wrap: wrap;
gap: 16px; /* Adjust gap between cards as needed */
justify-content: center; /* Center align cards in the row */
}

.featureCard {
width: 260px; /* Set a fixed width for the cards or adjust as needed */
display: inline;
flex-direction: column;
justify-content: space-between;
text-align: start;
background-color: #FAF9F8;
border-radius: 8px; /* Rounded corners */
border: 1px solid #EDEBE9; /* Border around the card */
box-shadow: 0px 4px 8px 0px #00000024;
padding: 18px; /* Add padding inside the card */
}


.cardTitle {
font-size: 16px; /* Adjust font size as needed */
margin-top: -30px;
margin-left: 30px;
font-weight: 600;
color: #3d3d3d;

}
.iconTitleContainer{
display: flex;
align-items: center;
}
.cardDescription {
font-size: 14px; /* Adjust font size as needed */
color: #3d3d3d;
margin-bottom: -2px;
}
.icon{
margin-top: 10px;
}
54 changes: 54 additions & 0 deletions code/frontend/src/pages/chat/Cards_contract/Cards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// src/pages/FeaturePage.tsx
import React from 'react';
import { Stack } from '@fluentui/react';
import IntractData from '../../../assets/Interact with data.svg'
import SourceReference from '../../../assets/Quick source reference.svg'
import SummarizeContracts from '../../../assets/Summarize contracts.svg'
import styles from './Cards.module.css'; // Create this CSS module for custom styles

const Cards: React.FC = () => {
return (
<div className={styles.container}>
<main className={styles.mainContent}>
<section className={styles.cards}>
<FeatureCard

title="Interact with Data"
description="Intuitive and conversational search experience that simplifies complex queries, ultimately improves productivity, job efficiency and satisfaction.​"
icon={<img src = {IntractData} aria-hidden="true" alt="Intract with Data" role="none" aria-label='IntractwithData' aria-labelledby='Cards' style={{ minWidth: 20, minHeight: 22 }} />}
/>
<FeatureCard

title="Summarize Contracts"
description="Quickly review and summarize lengthy documents, extracting essential details to streamline document review and preparation."
icon={<img src = {SummarizeContracts} aria-hidden="true" alt="Summarize Contracts" role="none" aria-label='SummarizeContracts' aria-labelledby='Cards'style={{ minWidth: 20, minHeight: 22 }} />}
/>
<FeatureCard

title="Quick Source Reference"
description="Effortlessly retrieve and reference original documents, ensuring accuracy and comprehensiveness."
icon={<img src = {SourceReference} aria-hidden="true" alt="Source Reference" role="none" aria-label='SourceReference' aria-labelledby='Cards' style={{ minWidth: 20, minHeight: 22 }} />}
/>
</section>
</main>
</div>
);
};

interface FeatureCardProps {
title: string;
description: string;
icon: React.ReactNode;
}

const FeatureCard: React.FC<FeatureCardProps> = ({ title, description, icon }) => {
return (
<div className={styles.featureCard}>
<div className={styles.icon}>{icon}</div>
<h2 className={styles.cardTitle}>{title}</h2>
<p className={styles.cardDescription}>{description}</p>
</div>
);
};

export default Cards;
21 changes: 21 additions & 0 deletions code/frontend/src/pages/chat/Chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
overflow-y: auto;
max-height: calc(100vh - 100px);
}
.loadingContainer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh; /* Full viewport height */
}

.loadingIcon {
border: 8px solid #f3f3f3; /* Light grey */
border-top: 8px solid #3498db; /* Blue */
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

.chatEmptyState {
flex-grow: 1;
Expand Down
Loading

0 comments on commit 1448c01

Please sign in to comment.