feat: add knowledge_ids field to ApplicationVersion and populate from ResourceMapping - #6533
Merged
Merged
Conversation
Contributor
Author
|
Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information |
There was a problem hiding this comment.
Pull request overview
This PR adds a persisted knowledge_ids list onto ApplicationVersion so simple-app chats can read the knowledge-base bindings from the latest published version instead of querying ResourceMapping at runtime (except in debug mode).
Changes:
- Added
knowledge_idsJSONField toApplicationVersionplus a data migration to backfill it fromResourceMappingfor existing SIMPLE applications. - Updated application publishing to populate
knowledge_idson newly createdApplicationVersionrecords. - Updated chat open/reopen and
ChatInfo.get_application()to preferApplicationVersion.knowledge_idswhen not debugging.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/chat/serializers/chat.py | Uses latest ApplicationVersion.knowledge_ids for SIMPLE chat open/reopen when not in debug. |
| apps/application/serializers/common.py | Updates SIMPLE ChatInfo loading to source knowledge IDs from ApplicationVersion when not debugging. |
| apps/application/serializers/application.py | Populates ApplicationVersion.knowledge_ids on publish for SIMPLE applications. |
| apps/application/models/application.py | Adds knowledge_ids field to ApplicationVersion model. |
| apps/application/migrations/0014_applicationversion_knowledge_ids.py | Adds schema + backfills knowledge_ids from ResourceMapping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+505
to
+507
| application_version = QuerySet(ApplicationVersion).filter(application_id=application.id).order_by( | ||
| '-create_time')[0:1].first() | ||
| knowledge_id_list = application_version.knowledge_ids |
Comment on lines
+32
to
+44
| updates = [] | ||
| for obj in ApplicationVersion.objects.using(db_alias).iterator(): | ||
| app_id = str(obj.application_id) | ||
| if app_id not in simple_application_ids: | ||
| continue | ||
| knowledge_ids = mapping.get(app_id) | ||
| if knowledge_ids: | ||
| obj.knowledge_ids = knowledge_ids | ||
| updates.append(obj) | ||
| if updates: | ||
| ApplicationVersion.objects.using(db_alias).bulk_update( | ||
| updates, ["knowledge_ids"], batch_size=500 | ||
| ) |
Comment on lines
+1275
to
+1280
| work_flow_version.knowledge_ids = [ | ||
| str(row.target_id) | ||
| for row in QuerySet(ResourceMapping).filter( | ||
| source_id=str(application.id), source_type="APPLICATION", target_type="KNOWLEDGE" | ||
| ) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add knowledge_ids field to ApplicationVersion and populate from ResourceMapping