Skip to content

Commit 69f46cc

Browse files
committed
Add Path.mkdir to make the databases directory;
Add a GET /ready endpoint for testing Add some command examples to readme.md
1 parent 8e60198 commit 69f46cc

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

llm/llm_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def set_my_llm_cache(cache_file: Path=LLM_CACHE) -> SQLiteCache:
278278
Set an LLM cache, which allows for previously executed completions to be
279279
loaded from disk instead of repeatedly queried.
280280
"""
281+
cache_file.parent.mkdir(exist_ok=True)
281282
set_llm_cache(SQLiteCache(database_path = cache_file))
282283

283284
@dataclass()

llm/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from llm_functions import get_summary_api_function, get_tags_api_function
33
import json
44
from firebase_admin import initialize_app
5-
from firebase_functions import https_fn
5+
from firebase_functions import https_fn, options
66

77
initialize_app()
88
app = Flask(__name__)
@@ -28,7 +28,6 @@ def summary():
2828

2929
return jsonify(summary["summary"])
3030

31-
3231
@app.route("/tags", methods=["POST"])
3332
def tags():
3433
body = json.loads(request.data)
@@ -44,8 +43,11 @@ def tags():
4443

4544
return jsonify(tags["tags"])
4645

46+
@app.route("/ready", methods=["GET"])
47+
def ready():
48+
return ""
4749

48-
@https_fn.on_request(secrets=["OPENAI_DEV"])
50+
@https_fn.on_request(secrets=["OPENAI_DEV"], timeout_sec=300, memory=options.MemoryOption.GB_1)
4951
def httpsflaskexample(req: https_fn.Request) -> https_fn.Response:
5052
with app.request_context(req.environ):
5153
return app.full_dispatch_request()

llm/readme.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,20 @@ TODO:
138138
139139
- [x] Get an OpenAPI key `firebase functions:secrets:access OPENAI_DEV`
140140
- [ ] Need to get docker running locally `yarn compose up --build`
141-
- [ ] Try to deploy the function `firebase deploy --only functions:maple-llm`
142-
- [ ] Alphabetize the requirements.txt file
141+
- [x] Try to deploy the function `firebase deploy --only functions:maple-llm`
142+
- [x] Alphabetize the requirements.txt file
143+
- [ ] Add some deploying/testing from the command line notes
144+
```bash
145+
# not sure if the GOOGLE_APPLICATION_CREDENTIALS is strictly necessary, but I
146+
# had a number of problems with authorization
147+
GOOGLE_APPLICATION_CREDENTIALS=/path/to/application_default_credentials.json \
148+
firebase deploy --only functions:maple-llm --debug
149+
150+
# This is an example curl command for hitting the production function
151+
curl \
152+
-X POST \
153+
-H "Content-Type: application/json" \
154+
-H "Authorization: Bearer $(gcloud auth print-identity-token)" \
155+
-d '{"bill_id": "1234","bill_title": "A title","bill_text": "Some bill text"}' \
156+
https://httpsflaskexample-ke6znoupgq-uc.a.run.app/summary
157+
```

0 commit comments

Comments
 (0)