Skip to content

Commit 5dd2c19

Browse files
committed
Initial commit
1 parent 89c4237 commit 5dd2c19

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

llm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
llm-api/
2+
__pycache__/

llm/api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import Flask, jsonify, abort
2+
from llm_functions import get_summaries_and_tags_api_function
3+
4+
app = Flask(__name__)
5+
6+
@app.route('/summary', methods=['POST'])
7+
def summary():
8+
body = json.loads(request.data)
9+
# We require bill_id, bill_title, bill_text to exist as keys in the POST
10+
# Note: & is essentially set intersection
11+
if not (body.keys() & {"bill_id", "bill_title", "bill_text"}):
12+
abort(404, description="requires bill_id, bill_title, and bill_text")
13+
14+
summary = get_summaries_and_tags_api_function(
15+
body["bill_id"],
16+
body["bill_title"],
17+
body["bill_text"]
18+
)
19+
20+
if summary["status"] in [-1, -2]:
21+
abort(404, description="unable to generate summary or tags")
22+
23+
return jsonify(summary)

llm/cloudbuild.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
steps:
2+
- name: 'gcr.io/cloud-builders/gcloud'
3+
args: ['functions', 'deploy', 'api', '--runtime', 'python39', '--trigger-http', '--allow-unauthenticated', '--entry-point', 'hello_world', '--source', '.']
4+
timeout: '1600s'

llm/readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,23 @@ This project uses OpenAI's API for various language processing tasks. To use the
122122
```python
123123
import os
124124
print(os.environ.get('OPENAI_API_KEY'))
125+
126+
# Running the API
127+
128+
Set up a virtual environment and run the Flask app
129+
130+
```
131+
python3 -m venv llm-api
132+
source llm-api/bin/activate # .fish if using fish
133+
pip3 install -r requirements.txt
134+
python3 -m flask --app api run
135+
```
136+
137+
TODO:
138+
139+
- [ ] Get an OpenAPI key
140+
- [ ] Attempt to run the summary function locally using the flask API
141+
- [ ] Try to add deploy this using cloud functions and `cloudbuild.yaml`
142+
Found some cloud functions documentation here,
143+
https://medium.com/@rez.archer/mastering-serverless-flask-apis-on-google-cloud-a-ci-cd-pipeline-setup-253b6de1c1ad
144+
- [ ] Alphabetize the requirements.txt file

llm/requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ asttokens==2.4.1
99
attrs==23.2.0
1010
backoff==2.2.1
1111
bcrypt==4.1.3
12-
blinker==1.8.2
12+
blinker==1.9.0
1313
blis==0.7.11
1414
build==1.2.1
1515
cachetools==5.3.3
@@ -181,3 +181,6 @@ websockets==12.0
181181
wrapt==1.16.0
182182
yarl==1.9.4
183183
zipp==3.19.1
184+
Flask==3.1.0
185+
itsdangerous==2.2.0
186+
Werkzeug==3.1.3

0 commit comments

Comments
 (0)