Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 91
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
54b1533
fix: use the latest user messages block instead of single message - WIP
yrobla c1981f8
fix problems with snippet language detection and search
yrobla cd526a1
fix linting
yrobla e87e5f9
fix vector search package extraction
yrobla 2397720
fix lint
yrobla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
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
41 changes: 25 additions & 16 deletions
41 src/codegate/pipeline/codegate_context_retriever/codegate.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -59,44 +59,53 @@ async def process( | ||
| """ | ||
| Use RAG DB to add context to the user request | ||
| """ | ||
| # Get the latest user messages | ||
| user_messages = self.get_latest_user_messages(request) | ||
| # Nothing to do if the user_messages string is empty | ||
| if len(user_messages) == 0: | ||
| # Get the latest user message | ||
| user_message = self.get_last_user_message_block(request) | ||
| if not user_message: | ||
| return PipelineResult(request=request) | ||
| # Create storage engine object | ||
| storage_engine = StorageEngine() | ||
| # Extract any code snippets | ||
| snippets = extract_snippets(user_messages) | ||
| snippets = extract_snippets(user_message) | ||
yrobla marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| bad_snippet_packages = [] | ||
| if len(snippets) > 0: | ||
| snippet_language = snippets[0].language | ||
| # Collect all packages referenced in the snippets | ||
| snippet_packages = [] | ||
| for snippet in snippets: | ||
| snippet_packages.extend( | ||
| PackageExtractor.extract_packages(snippet.code, snippet.language) | ||
| PackageExtractor.extract_packages(snippet.code, snippet.language) # type: ignore | ||
| ) | ||
| logger.info(f"Found {len(snippet_packages)} packages in code snippets.") | ||
| logger.info( | ||
| f"Found {len(snippet_packages)} packages " | ||
| f"for language {snippet_language} in code snippets." | ||
| ) | ||
| # Find bad packages in the snippets | ||
| bad_snippet_packages = await storage_engine.search( | ||
| language=snippets[0].language, packages=snippet_packages | ||
| ) | ||
| language=snippet_language, packages=snippet_packages | ||
| ) # type: ignore | ||
| logger.info(f"Found {len(bad_snippet_packages)} bad packages in code snippets.") | ||
| # Remove code snippets from the user messages and search for bad packages | ||
| # in the rest of the user query/messsages | ||
| user_messages = re.sub(r"```.*?```", "", user_messages, flags=re.DOTALL) | ||
| # Vector search to find bad packages | ||
| bad_packages = await storage_engine.search(query=user_messages, distance=0.5, limit=100) | ||
| user_messages = re.sub(r"```.*?```", "", user_message, flags=re.DOTALL) | ||
| user_messages = re.sub(r"⋮...*?⋮...\n\n", "", user_messages, flags=re.DOTALL) | ||
| # split messages into double newlines, to avoid passing so many content in the search | ||
| split_messages = user_messages.split("\n\n") | ||
| collected_bad_packages = [] | ||
| for item_message in split_messages: | ||
| # Vector search to find bad packages | ||
| bad_packages = await storage_engine.search(query=item_message, distance=0.5, limit=100) | ||
| if bad_packages and len(bad_packages) > 0: | ||
| collected_bad_packages.extend(bad_packages) | ||
| # All bad packages | ||
| all_bad_packages = bad_snippet_packages + bad_packages | ||
| all_bad_packages = bad_snippet_packages + collected_bad_packages | ||
| logger.info(f"Adding {len(all_bad_packages)} bad packages to the context.") | ||
| @@ -119,7 +128,7 @@ async def process( | ||
| # Add the context to the last user message | ||
| # Format: "Context: {context_str} \n Query: {last user message content}" | ||
| message = new_request["messages"][last_user_idx] | ||
| context_msg = f'Context: {context_str} \n\n Query: {message["content"]}' | ||
| context_msg = f'Context: {context_str} \n\n Query: {message["content"]}' # type: ignore | ||
| message["content"] = context_msg | ||
| logger.debug("Final context message", context_message=context_msg) | ||
17 changes: 14 additions & 3 deletions
17 src/codegate/pipeline/extract_snippets/extract_snippets.py
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.