Version-1 changes for Maple Chatbot pr_2198_bot - #2218
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code in llm/ not relevant to this PR, so I recommend not modifying the requirements here
nesanders
left a comment
There was a problem hiding this comment.
This is initial high level feedback.
| @@ -0,0 +1,104 @@ | |||
| import { useState, useRef, useEffect } from "react" | |||
There was a problem hiding this comment.
A big open question is if we should be authoring our own chat widget or adopting a framework like copilotkit instead.
|
|
||
| // Logged-in users: persistent monthly token budget, tracked in the | ||
| // top-level `llmUsage` collection (see usage.ts). | ||
| loggedInMonthlyTokenBudget: 50_000 |
There was a problem hiding this comment.
These default budgets might be too small to be useful for either logged in or anonymous users, but we can modify later
There was a problem hiding this comment.
We discussed that we can decide on changing this later
| --- | ||
|
|
||
| ## Backfilling Existing Documents | ||
|
|
There was a problem hiding this comment.
Is there anything we actually need to backfill? I think we already have the relevant embeddings for bills, questions, and testimony in the index.
There was a problem hiding this comment.
From our discussion, sounds liek this is extraneous and can be deleted
| "rimraf": "^3.0.2", | ||
| "ts-jest": "^29.2.5", | ||
| "typescript": "4.5.5" | ||
| "typescript": "^5.5.4" |
There was a problem hiding this comment.
I don't think we will update typescript version as part of this PR, though w may do so later for other reasons
There was a problem hiding this comment.
You updated this - thanks! However, you are adding the carrot in ("^") - I don't think we need to do that, either.
| import { httpsCallable } from "firebase/functions" | ||
| import { functions } from "components/firebase" | ||
| import { useAuth } from "components/auth" | ||
| import styles from "./ChatWidget.module.css" |
There was a problem hiding this comment.
i think we need to add a mock frontend pag that just exposes this widget on a placeholder page for initial testing purposes.
|
|
||
| // Merge by interleaving: pick the lower-rank item from each list at each | ||
| // step, which preserves the relative relevance ordering from Firestore. | ||
| const merged: string[] = [] |
There was a problem hiding this comment.
We should document the design decision of why we are returnign interleaved resuls for bills and BQs. If this is the same logic as the MCP server, we should import from there or modularize the function into a different module. If it is different logic, we should explain why.
|
Just noting - this PR does not yet introduce a data model for storing user chat histories. We should either introduce a basic framework for this here or capture an issue to do so later. We should be able to use https://reference.langchain.com/python/langchain-community/chat_message_histories/firestore/FirestoreChatMessageHistory for this. We will need to decide whether to add this as a separate firestore db or as a new collection or something else. it is a top priority to enforce user-level access so each user can only access their own conversation history. |
|
To keep the context size limited and avoid spending a lot of tokens, the bill retrieval search tool should by default retrieve only the |
| allow read: if true; | ||
| allow write: if false; | ||
| } | ||
| <<<<<<< HEAD |
There was a problem hiding this comment.
This is a dangling merge error that needs to be cleaned up.
| @@ -0,0 +1,25 @@ | |||
| export const LLM_CONFIG = { | |||
There was a problem hiding this comment.
Just a note: We also need a top level circuit breaker. Regardless of the individual usage limits below, we need to configure a limit on the total monthly spend of the feature so it doesn't go out of control. We could potentially configure that at the google cloud project level, not necessarily in the code here.
| */ | ||
| export const askQuestion = functions | ||
| .runWith({ timeoutSeconds: 120, memory: "512MB" }) | ||
| .https.onCall(async (data, context) => { |
There was a problem hiding this comment.
We will need some limit to scaling here to prevent overuse. A maxinstances limit here might help.
| } | ||
|
|
||
| return merged.slice(0, topK * 2).join("\n\n") | ||
| // Merge all results and sort by relevance score descending — same approach |
There was a problem hiding this comment.
Even if we don't modularize the relevance score logic between the MCP server and chat agent tools, can we at least cite the alignment betwen them by linking here?
Line 617 in 7a1fad3
There was a problem hiding this comment.
It would be ideal to modularize and import this logic from a single function def, but it is ok if we do not do that in this PR.
Summary
Maple Chatbot where a User can ask Questions about Bill/Policy issue question answering chat
ReAct AI agent with tool calling and reasoning loop capability
Access to firebase vector index search
Add a short summary of the changes, and a reference to the original issue using
#and the issue number, like #1Checklist
firestore.indexes.json(Please do not only create indexes through the Firebase Web UI, even though the error messages may reccommend it - indexes created this way may be obliterated by subsequent deploys)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.: