Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into main
  • Loading branch information
rosenauer committed Apr 18, 2021
2 parents 2055bd1 + 47afb75 commit 9a39b1f
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 69 deletions.
17 changes: 17 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:latest

RUN pip install --upgrade pip

COPY . /usr/src/app

RUN CFLAGS="-Wno-narrowing" pip install cld2-cffi
RUN pip install -r /usr/src/app/requirements.txt
RUN pip install slackers
RUN pip install pandas
RUN pip install docx
EXPOSE 5000
WORKDIR /usr/src/app
CMD ["uvicorn", "index:app", "--host", "0.0.0.0" ,"--port", "5000", "--log-level", "info"]



7 changes: 7 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ Start backend server (development):
```
uvicorn index:app --host 0.0.0.0 --port 5000 --log-level debug --reload
```

# Build and run dockerfile

```
docker build -t comprehendum .
docker run comprehendum (-d for detached mode)
```
27 changes: 24 additions & 3 deletions backend/gptapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
header_contenttype = "application/json"

search_model = "ada"
completion_model = "davinci"
completion_model = "curie"

examples_context = """6.6.1.3 Decent Working Time
Expand Down Expand Up @@ -65,8 +65,6 @@


def get_answer(question: str, paragraphs: List[str]):
# question = "Is a payment under duress deemed an act of corruption?"

response = requests.post(
answers_url,
headers={
Expand All @@ -86,3 +84,26 @@ def get_answer(question: str, paragraphs: List[str]):
}
)
return response.json()['answers'][0]


compl_model = "davinci"
completion_url = f"https://api.openai.com/v1/engines/{compl_model}/completions"


def get_completion(question: str):
response = requests.post(
completion_url,
headers={
"Authorization": header_auth,
"Content-Type": header_contenttype
},
json={
"prompt": """
What is the german legal warranty period?
""",
"max_tokens": 50,
"temperature": 0.1,
"n": 1,
}
)
return response.json()['choices'][0]['text']
4 changes: 2 additions & 2 deletions backend/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from gptapi import get_answer
from key_word_search import get_sentences

from hardcode import *
from intelligent_parse import *

# set permitted cors origins
origins = [
Expand Down Expand Up @@ -89,7 +89,7 @@ async def shutdown():

import signal

TIMEOUT = 2 # number of seconds your want for timeout
TIMEOUT = 1 # number of seconds your want for timeout


def interrupted():
Expand Down
File renamed without changes.
22 changes: 19 additions & 3 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
cld2-cffi==0.1.4
click==7.1.2
fastapi==0.63.0
h11==0.12.0
idna==2.10
joblib==1.0.1
multi-rake==0.0.1
nltk==3.6.1
numpy==1.20.2
openai==0.6.3
pycparser==2.20
pydantic==1.8.1
pyrsistent==0.17.3
python-dotenv==0.17.0
regex==2021.4.4
requests==2.25.1
six==1.15.0
starlette==0.13.6
tqdm==4.60.0
typing-extensions==3.7.4.3
uvicorn==0.13.4
python-dotenv==0.17.0
openai==0.6.3
urllib3==1.26.4
uvicorn==0.13.4
64 changes: 62 additions & 2 deletions backend/slack.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
from fastapi import Request
from index import app, ask_question
from pydantic import BaseModel
import random
import requests
from multi_rake import Rake
rake = Rake()

import logging
from slackers.hooks import commands

log = logging.getLogger(__name__)

users = [
{
"id": "U01T7Q8NE3U",
"name": "Silas Alberti",
"pronoun": "He"
},
{
"id": "U01T468DJ6R",
"name": "Marc Schneider",
"pronoun": "He"
},
{
"id": "U01T7AR57V0",
"name": "Simon Bohnen",
"pronoun": "He"
},
{
"id": "U01TZA1M800",
"name": "Ria Rosenauer",
"pronoun": "She"
},
{
"id": "U01T4ASN329",
"name": "Alexander von Recum",
"pronoun": "He"
}
]

@commands.on("comprehendum")
def handle_mention(payload):
# requests.post(payload["response_url"], json={
# "blocks": [
# {
# "type": "section",
# "text": {
# "type": "mrkdwn",
# "text": f"_Processing..._"
# }
# },
# ]
# })

print(payload["channel_id"])

channel_id = payload["channel_id"]
Expand All @@ -18,6 +61,12 @@ def handle_mention(payload):
question = payload["text"]
result = ask_question(question)

l = rake.apply(question)
keyword = max(l, key=lambda _:_[0])[0] if l is not None and len(l) > 0 else "legal & compliance"
random.seed(hash(keyword))
user = random.choice(users)
nl = "\n"

requests.post(payload["response_url"], json= {
"blocks": [
{
Expand All @@ -31,9 +80,20 @@ def handle_mention(payload):
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*Answer:* {result}"
"text": f"> *Answer:* Hey <@{payload['user_id']}>! "
f"{result.split(nl)[0]}{nl}{nl.join(['> ' + line for line in result.split(nl)[1:]])}"
}
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"_For specific support contact <@{user['id']}> from the "
f"legal & compliance "
f"department. {user['pronoun']} is the correct contact "
f"person for issues concerning *\"{keyword}\"*. 😀_"
}
},
]
})
else:
Expand Down
4 changes: 4 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react-scripts": "4.0.3",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^2.0.3",
"styled-components": "^5.2.3",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4",
"workbox-background-sync": "^5.1.3",
Expand Down Expand Up @@ -54,5 +55,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/styled-components": "^5.1.9"
}
}
10 changes: 9 additions & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700&display=swap"
rel="stylesheet"
/>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
38 changes: 0 additions & 38 deletions frontend/src/App.css

This file was deleted.

27 changes: 19 additions & 8 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import './App.css';

import 'semantic-ui-css/semantic.min.css';
import { Loader } from 'semantic-ui-react';
import { Loader, Container } from 'semantic-ui-react';
import InputComponent from './InputComponent';

function App() {
Expand Down Expand Up @@ -33,18 +33,28 @@ function App() {
<div
className="header"
style={{
height: '20%',
height: '15%',
backgroundColor: '#B0BEA9',
color: 'white',
display: 'flex',
alignItems: 'center',
alignItems: 'flex-end',
justifyContent: 'flex-start',
paddingLeft: '10%',
paddingBottom: '25px',
gap: '20px',
}}
>
<img
src="Siemens-logo.svg"
style={{
width: '200px',
}}
/>
<h1
style={{
fontSize: '30px',
marginLeft: '10%',
fontSize: '40px',
fontFamily: 'Lato',
fontWeight: 300,
}}
>
Legal &amp; Compliance Companion
Expand All @@ -68,13 +78,14 @@ function App() {
/>
{apiCallInProgress && <Loader style={{ marginTop: '10%' }} active />}
{!apiCallInProgress && requested && !error && (
<div
<Container
text
style={{
wordBreak: 'break-all',
}}
>
{result.data.answer}
</div>
</Container>
)}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/constants/apiEndpoints.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const BASE_URL = 'http://localhost:5000';
export const BASE_URL = 'http://192.168.0.218:5000';
export const QUESTION_ENDPOINT = '/api/question';
3 changes: 2 additions & 1 deletion frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import Asdf from './Asdf';
import * as serviceWorkerRegistration from './serviceWorkerRegistration';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
<Asdf />
</React.StrictMode>,
document.getElementById('root')
);
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/logo.svg

This file was deleted.

Loading

0 comments on commit 9a39b1f

Please sign in to comment.