Skip to content

(EAI-988): Refactor GenerateResponse for tool call support #687

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

Merged
merged 9 commits into from
May 27, 2025

Conversation

mongodben
Copy link
Collaborator

@mongodben mongodben commented Apr 28, 2025

Jira: https://jira.mongodb.org/browse/EAI-988

Changes

  • Simplify GenerateResponse so only takes the request-specific args
    • Can pass other stuff in a constructor function
  • Refactor legacy RAG system to fit into shape of new construct.
    • To be removed relatively soon
  • Include GenerateResponse in args to conversations server.
  • preserve includeChunksForMaxTokensPossible() utility func from now removed generate user message file

Notes

@mongodben mongodben changed the base branch from main to retrieval_tool_call April 28, 2025 16:18
Copy link
Collaborator

@nlarew nlarew left a comment

Choose a reason for hiding this comment

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

LGTM - some minor comments + a typo that you might wanna fix

@@ -20,6 +20,7 @@ import {
makeDefaultFindVerifiedAnswer,
defaultCreateConversationCustomData,
defaultAddMessageToConversationCustomData,
makeLegacyGeneratateResponse,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
makeLegacyGeneratateResponse,
makeLegacyGenerateResponse,

typo throughout

@@ -21,25 +15,7 @@ const userMessage = {
} satisfies Message;

describe("makeFilterNPreviousMessages", () => {
it("should throw an error when there are no messages", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just confirming - we don't want to throw anymore if the array is empty?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct. this is b/c we wont store the system message anymore.

this is for a few reasons:

  1. this is b.c some tool info is in the system msg. so if tool changes, then could be mismatch btwn behavvior and persisted system message
  2. logically, the system msg isn't really part of the converastion, so probably should have never been saved 🤷

Comment on lines 40 to 57
export interface GenerateResponseParams {
shouldStream: boolean;
latestMessageText: string;
clientContext?: ClientContext;
customData?: ConversationCustomData;
dataStreamer?: DataStreamer;
reqId: string;
conversation: Conversation;
request?: ExpressRequest;
}

export interface GenerateResponseReturnValue {
messages: SomeMessage[];
}

export type GenerateResponse = (
params: GenerateResponseParams
) => Promise<GenerateResponseReturnValue>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this all be in a separate generateResponse.ts file? Seems like a distinct (if not separate) concern from the route that calls it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah reasonable, will do

mongodben and others added 4 commits April 28, 2025 15:42
verified answer generate response

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>
@mongodben mongodben merged commit c87dc74 into retrieval_tool_call May 27, 2025
1 check failed
@mongodben mongodben deleted the EAI-988 branch May 27, 2025 16:50
mongodben added a commit that referenced this pull request Jun 11, 2025
* (EAI-988): Refactor `GenerateResponse` for tool call support  (#687)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* (EAI-989): Refactor verified answers to wrap `GenerateResponse` (#688)

verified answer generate response

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* handle streaming

* separate generateresponse

* typo fix

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-990): Refactor search as a tool  (#705)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* update default ref links

* fix broken tests

* Apply suggestions from code review

Co-authored-by: Nick Larew <nick.larew@mongodb.com>

* revert default reference links

* adding missing test

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>
Co-authored-by: Nick Larew <nick.larew@mongodb.com>

* (EAI-992): Remove `ChatLlm` (#751)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* remove ChatLlm

* lite fixes

* Remove stub

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-993): deprecate framework (#752)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* deprecation

* build out docs following last week convo

* clean up spec + contact

* fix merge funk

* docs updates

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-1071): Fix broken Atlas OpenAPI ingest (#765)

* update to fix broken test

* Update packages/ingest-mongodb-public/src/sources/snooty/snootyAstToOpenApiSpec.ts

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* (EAI-995): add guardrail (#755)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* update default ref links

* fix broken tests

* input guardrail refactor

* guardrail works well

* simpler validity metric

* add guardrail to server

* add next step todo

* llm refusal msg

* remove TODO comment

* merge fix

* fix unnec changes

* NL feedback

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* fix type in text

* (EAI-991 & EAI-1050): Evaluate and clean up retrieval as a tool (#757)

* refactor GenerateRespose

* Clean up imports

* consolidate generate user prompt to the legacy file

* update test config imports

* Fix broken tests

* get started

* nominally working generate res w/ search

* small refactors

* aint pretty but fully functional

* hacky if more functional

* more hack

* tools

* functional if not pretty

* Add processing

* working tool calling

* making progress

* keepin on

* Clean config

* working e2e

* update model version

* Remove no longer used stuff

* decouple search results for references and whats shown to model

* fix scripts build errs

* fix broken tests

* update default ref links

* fix broken tests

* input guardrail refactor

* guardrail works well

* simpler validity metric

* add guardrail to server

* add next step todo

* llm refusal msg

* remove TODO comment

* evals on new architecture

* Get urls in a way that supports verified answers

* dont eval on retrieved elems if no context

* Cleaner handling

* update trace handling

* update trace handling

* undo git funk

* handle undefined case

* Fix tracing test

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>

* remove console logs + redunancies

---------

Co-authored-by: Ben Perlmutter <mongodben@mongodb.com>
Co-authored-by: Nick Larew <nick.larew@mongodb.com>
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