Skip to content

Llm flask api #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Conversation

chiroptical
Copy link
Collaborator

@chiroptical chiroptical commented Apr 9, 2025

DO NOT MERGE

firebase/firebase-tools#5873

functions: Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run 'source /app/llm/venv/bin/activate && python3.10 -m pip install -r requirements.txt'?

Summary

Add a short summary of the changes, and a reference to the original issue using # and the issue number, like #1

Checklist

  • On the frontend, I've made my strings translate-able.
  • If I've added shared components, I've added a storybook story.
  • I've made pages responsive and look good on mobile.

Screenshots

Add some screenshots highlighting your changes.

Known issues

If you've run against limitations or caveats, include them here. Include follow-up issues as well.

Steps to test/reproduce

For each feature or bug fix, create a step by step list for how a reviewer can test it out. E.g.:

  1. Go to the home page
  2. Click on a testimony
  3. See that it's loaded with a loading spinner

Copy link

vercel bot commented Apr 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
maple-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2025 0:29am
maple-prod 🔄 Building (Inspect) Visit Preview 💬 Add feedback Apr 30, 2025 0:29am

@Mephistic
Copy link
Collaborator

Nathan's comments from the Zoom on cutting down dependency:

I expect the imports here are sufficient to run the python llm functions:

import json

There are some fairly hefty ones there that are needed... langchain, sklearn, chromadb

We can probably cut sklearn if we find easy replacement for the small number of functions we are importing from it.
Also, I noticed streamlit is imported there, and that is actually totally unecessary! It is vestigial IUUC. I don't see it actually referenced anywhere in the script.
Removing streamlit could be a quick win.

.dockerignore Outdated
Comment on lines 6 to 7
.git No newline at end of file
.git
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to figure out how to configure my editor to not make changes like this automatically

Comment on lines 7 to 8
USER node No newline at end of file
USER node
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray

Comment on lines +48 to +51
@https_fn.on_request(secrets=["OPENAI_DEV"])
def httpsflaskexample(req: https_fn.Request) -> https_fn.Response:
with app.request_context(req.environ):
return app.full_dispatch_request()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the magic sauce to expose these routes to firebase

source venv/bin/activate # .fish if using fish
pip3 install -r requirements.txt
python3 -m flask --app main run
```
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add more details here and remove everything below it

"runtime": "nodejs18"
},
{
"predeploy": [". llm/venv/bin/activate && python3.10 -m pip install -r llm/requirements.txt"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this file is mainly used when you type firebase deploy ... so this pre-deploy will not happen inside a Docker environment

"runtime": "nodejs18"
},
{
"predeploy": ["source /app/llm/venv/bin/activate && python3.10 -m pip install -r /app/llm/requirements.txt"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this one should be used by docker compose and should run inside the docker enviroment (note this doesn't exactly work for reasons I don't understand)

Comment on lines +15 to +20
@app.route("/summary", methods=["POST"])
def summary():
body = json.loads(request.data)
# We require bill_id, bill_title, bill_text to exist as keys in the POST
if not is_intersection(body.keys(), {"bill_id", "bill_title", "bill_text"}):
abort(404, description="requires bill_id, bill_title, and bill_text")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: currently this API takes a json payload like

{
  "bill_id": "...",
  "bill_title": "...",
  "bill_text": "..." 
}

In the future, since this has access to firebase, you could also offer an API which takes the bill_id and returns the summary after looking up the title/text.

Comment on lines +26 to +27
if summary["status"] in [-1, -2]:
abort(500, description="Unable to generate summary")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status field returns either -1 or -2 if it fails... This is probably somewhat unfortunate here because if this API ever changes I will not be able to know about it.

I'll add a note to get_summary_api_function but we don't really have types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, maybe I should just check that this value is negative? technically the return type is int

Comment on lines +42 to +43
if tags["status"] in [-1, -2]:
abort(500, description="Unable to generate tags")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably check for negative return type? See above https://github.com/codeforboston/maple/pull/1789/files#r2055086855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants