llama-github 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llama_github-0.1.1/CHANGELOG.md +34 -0
- llama_github-0.1.1/MANIFEST.in +2 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/PKG-INFO +65 -3
- llama_github-0.1.0/llama_github.egg-info/PKG-INFO → llama_github-0.1.1/README.md +29 -31
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/config/config.json +3 -3
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/github_rag.py +69 -11
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/llm_integration/initial_load.py +8 -1
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/llm_integration/llm_handler.py +2 -4
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/rag_processing/rag_processor.py +76 -66
- llama_github-0.1.1/llama_github/version.py +1 -0
- llama_github-0.1.0/README.md → llama_github-0.1.1/llama_github.egg-info/PKG-INFO +94 -3
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github.egg-info/SOURCES.txt +1 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/setup.cfg +2 -2
- {llama_github-0.1.0 → llama_github-0.1.1}/setup.py +7 -0
- llama_github-0.1.0/MANIFEST.in +0 -1
- llama_github-0.1.0/llama_github/version.py +0 -1
- {llama_github-0.1.0 → llama_github-0.1.1}/LICENSE +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/config/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/config/config.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/data_retrieval/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/data_retrieval/github_api.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/data_retrieval/github_entities.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/features/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/features/feature_flags.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/features/insider_features.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/github_integration/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/github_integration/github_auth_manager.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/llm_integration/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/logger.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/rag_processing/__init__.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github/utils.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github.egg-info/dependency_links.txt +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github.egg-info/requires.txt +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/llama_github.egg-info/top_level.txt +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/tests/test_data_retrieval.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/tests/test_github_auth_manager.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/tests/test_initial_load.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/tests/test_llm_handler.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/tests/test_logger.py +0 -0
- {llama_github-0.1.0 → llama_github-0.1.1}/tests/test_rag_processor.py +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.1] - 2024-08-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Implemented `answer_with_context` method for direct answer generation (closes #6)
|
|
12
|
+
- Added support for Mistral AI LLM provider
|
|
13
|
+
- Enhanced `retrieve_context` function to include metadata (e.g., URLs) with each context string (closes #2)
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Improved reranking with jina-reranker-v2 for better context retrieval
|
|
17
|
+
- Updated return type of `retrieve_context` to accommodate metadata
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Resolved warning during context retrieval (closes #3)
|
|
21
|
+
|
|
22
|
+
### Improved
|
|
23
|
+
- Enhanced overall context retrieval process
|
|
24
|
+
- Expanded LLM support for more versatile use cases
|
|
25
|
+
|
|
26
|
+
## [0.1.0] - 2024-08-15
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- Initial release of llama-github
|
|
30
|
+
- Basic functionality for retrieving context from GitHub repositories
|
|
31
|
+
- Integration with LLM for processing and generating responses
|
|
32
|
+
|
|
33
|
+
[0.1.1]: https://github.com/JetXu-LLM/llama-github/compare/v0.1.0...v0.1.1
|
|
34
|
+
[0.1.0]: https://github.com/JetXu-LLM/llama-github/releases/tag/v0.1.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: llama-github
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Llama-github is an open-source Python library that empowers LLM Chatbots, AI Agents, and Auto-dev Agents to conduct Retrieval from actively selected GitHub public projects. It Augments through LLMs and Generates context for any coding question, in order to streamline the development of sophisticated AI-driven applications.
|
|
5
5
|
Home-page: https://github.com/JetXu-LLM/llama-github
|
|
6
6
|
Author: Jet Xu
|
|
@@ -29,9 +29,16 @@ Requires-Dist: flake8; extra == "dev"
|
|
|
29
29
|
|
|
30
30
|
# llama-github
|
|
31
31
|
|
|
32
|
+
[](https://badge.fury.io/py/llama-github)
|
|
33
|
+
[](https://pepy.tech/project/Llama-github)
|
|
32
34
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
33
35
|
|
|
34
|
-
Llama-github is
|
|
36
|
+
Llama-github is a powerful tool that helps you retrieve the most relevant code snippets, issues, and repository information from GitHub based on your queries, transforming them into valuable knowledge context. It empowers LLM Chatbots, AI Agents, and Auto-dev Agents to solve complex coding tasks. Whether you're a developer looking for quick solutions or an engineer implementing advanced Auto Dev AI Agents, llama-github makes it easy and efficient.
|
|
37
|
+
|
|
38
|
+
If you like this project or believe it has potential, please give it a ⭐️. Your support is our greatest motivation!
|
|
39
|
+
|
|
40
|
+
## Architecture
|
|
41
|
+

|
|
35
42
|
|
|
36
43
|
## Installation
|
|
37
44
|
```
|
|
@@ -82,6 +89,26 @@ For more advanced usage and examples, please refer to the [documentation](docs/u
|
|
|
82
89
|
|
|
83
90
|
- **🛠️ Logging and Error Handling**: We understand the importance of smooth operations and easy troubleshooting. That's why llama-github comes equipped with comprehensive logging and error handling mechanisms. Gain deep insights into the library's behavior, quickly diagnose issues, and maintain a stable and reliable development workflow.
|
|
84
91
|
|
|
92
|
+
## Vision and Roadmap
|
|
93
|
+
|
|
94
|
+
### Vision
|
|
95
|
+
|
|
96
|
+
Our vision is to become a pivotal module in the future of AI-driven development solutions, seamlessly integrating with GitHub to empower LLMs in automatically resolving complex coding tasks.
|
|
97
|
+
|
|
98
|
+

|
|
99
|
+
|
|
100
|
+
### Roadmap
|
|
101
|
+
|
|
102
|
+
For a detailed view of our project roadmap, please visit our [Project Roadmap](https://github.com/users/JetXu-LLM/projects/2).
|
|
103
|
+
|
|
104
|
+
## Acknowledgments
|
|
105
|
+
|
|
106
|
+
We would like to express our gratitude to the following open-source projects for their support and contributions:
|
|
107
|
+
|
|
108
|
+
- **[LangChain](https://github.com/langchain-ai/langchain)**: For providing the foundational framework that empowers the LLM prompting and processing capabilities in llama-github.
|
|
109
|
+
- **[Jina.ai](https://github.com/jina-ai/reader)**: For offering s.jina.ai API and open source reranker and embedding models that enhance the accuracy and relevance of the generated contexts in llama-github.
|
|
110
|
+
|
|
111
|
+
Their contributions have been instrumental in the development of llama-github, and we highly recommend checking out their projects for more innovative solutions.
|
|
85
112
|
|
|
86
113
|
## Contributing
|
|
87
114
|
|
|
@@ -93,8 +120,43 @@ This project is licensed under the terms of the Apache 2.0 license. See the [LIC
|
|
|
93
120
|
|
|
94
121
|
## Contact
|
|
95
122
|
|
|
96
|
-
If you have any questions, suggestions, or feedback, please feel free to reach out to us at [
|
|
123
|
+
If you have any questions, suggestions, or feedback, please feel free to reach out to us at [Jet Xu's email](mailto:Voldemort.xu@foxmail.com).
|
|
97
124
|
|
|
98
125
|
---
|
|
99
126
|
|
|
100
127
|
Thank you for choosing llama-github! We hope this library enhances your AI development experience and helps you build powerful applications with ease.
|
|
128
|
+
|
|
129
|
+
# Changelog
|
|
130
|
+
|
|
131
|
+
All notable changes to this project will be documented in this file.
|
|
132
|
+
|
|
133
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
134
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
135
|
+
|
|
136
|
+
## [0.1.1] - 2024-08-23
|
|
137
|
+
|
|
138
|
+
### Added
|
|
139
|
+
- Implemented `answer_with_context` method for direct answer generation (closes #6)
|
|
140
|
+
- Added support for Mistral AI LLM provider
|
|
141
|
+
- Enhanced `retrieve_context` function to include metadata (e.g., URLs) with each context string (closes #2)
|
|
142
|
+
|
|
143
|
+
### Changed
|
|
144
|
+
- Improved reranking with jina-reranker-v2 for better context retrieval
|
|
145
|
+
- Updated return type of `retrieve_context` to accommodate metadata
|
|
146
|
+
|
|
147
|
+
### Fixed
|
|
148
|
+
- Resolved warning during context retrieval (closes #3)
|
|
149
|
+
|
|
150
|
+
### Improved
|
|
151
|
+
- Enhanced overall context retrieval process
|
|
152
|
+
- Expanded LLM support for more versatile use cases
|
|
153
|
+
|
|
154
|
+
## [0.1.0] - 2024-08-15
|
|
155
|
+
|
|
156
|
+
### Added
|
|
157
|
+
- Initial release of llama-github
|
|
158
|
+
- Basic functionality for retrieving context from GitHub repositories
|
|
159
|
+
- Integration with LLM for processing and generating responses
|
|
160
|
+
|
|
161
|
+
[0.1.1]: https://github.com/JetXu-LLM/llama-github/compare/v0.1.0...v0.1.1
|
|
162
|
+
[0.1.0]: https://github.com/JetXu-LLM/llama-github/releases/tag/v0.1.0
|
|
@@ -1,37 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: llama-github
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Llama-github is an open-source Python library that empowers LLM Chatbots, AI Agents, and Auto-dev Agents to conduct Retrieval from actively selected GitHub public projects. It Augments through LLMs and Generates context for any coding question, in order to streamline the development of sophisticated AI-driven applications.
|
|
5
|
-
Home-page: https://github.com/JetXu-LLM/llama-github
|
|
6
|
-
Author: Jet Xu
|
|
7
|
-
Author-email: Voldemort.xu@foxmail.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.6
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Requires-Dist: aiohttp
|
|
15
|
-
Requires-Dist: asyncio
|
|
16
|
-
Requires-Dist: dataclasses
|
|
17
|
-
Requires-Dist: PyGithub
|
|
18
|
-
Requires-Dist: langchain
|
|
19
|
-
Requires-Dist: numpy
|
|
20
|
-
Requires-Dist: pydantic
|
|
21
|
-
Requires-Dist: requests
|
|
22
|
-
Requires-Dist: torch
|
|
23
|
-
Requires-Dist: transformers
|
|
24
|
-
Requires-Dist: urllib3
|
|
25
|
-
Provides-Extra: dev
|
|
26
|
-
Requires-Dist: pytest; extra == "dev"
|
|
27
|
-
Requires-Dist: black; extra == "dev"
|
|
28
|
-
Requires-Dist: flake8; extra == "dev"
|
|
29
|
-
|
|
30
1
|
# llama-github
|
|
31
2
|
|
|
3
|
+
[](https://badge.fury.io/py/llama-github)
|
|
4
|
+
[](https://pepy.tech/project/Llama-github)
|
|
32
5
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
33
6
|
|
|
34
|
-
Llama-github is
|
|
7
|
+
Llama-github is a powerful tool that helps you retrieve the most relevant code snippets, issues, and repository information from GitHub based on your queries, transforming them into valuable knowledge context. It empowers LLM Chatbots, AI Agents, and Auto-dev Agents to solve complex coding tasks. Whether you're a developer looking for quick solutions or an engineer implementing advanced Auto Dev AI Agents, llama-github makes it easy and efficient.
|
|
8
|
+
|
|
9
|
+
If you like this project or believe it has potential, please give it a ⭐️. Your support is our greatest motivation!
|
|
10
|
+
|
|
11
|
+
## Architecture
|
|
12
|
+

|
|
35
13
|
|
|
36
14
|
## Installation
|
|
37
15
|
```
|
|
@@ -82,6 +60,26 @@ For more advanced usage and examples, please refer to the [documentation](docs/u
|
|
|
82
60
|
|
|
83
61
|
- **🛠️ Logging and Error Handling**: We understand the importance of smooth operations and easy troubleshooting. That's why llama-github comes equipped with comprehensive logging and error handling mechanisms. Gain deep insights into the library's behavior, quickly diagnose issues, and maintain a stable and reliable development workflow.
|
|
84
62
|
|
|
63
|
+
## Vision and Roadmap
|
|
64
|
+
|
|
65
|
+
### Vision
|
|
66
|
+
|
|
67
|
+
Our vision is to become a pivotal module in the future of AI-driven development solutions, seamlessly integrating with GitHub to empower LLMs in automatically resolving complex coding tasks.
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
### Roadmap
|
|
72
|
+
|
|
73
|
+
For a detailed view of our project roadmap, please visit our [Project Roadmap](https://github.com/users/JetXu-LLM/projects/2).
|
|
74
|
+
|
|
75
|
+
## Acknowledgments
|
|
76
|
+
|
|
77
|
+
We would like to express our gratitude to the following open-source projects for their support and contributions:
|
|
78
|
+
|
|
79
|
+
- **[LangChain](https://github.com/langchain-ai/langchain)**: For providing the foundational framework that empowers the LLM prompting and processing capabilities in llama-github.
|
|
80
|
+
- **[Jina.ai](https://github.com/jina-ai/reader)**: For offering s.jina.ai API and open source reranker and embedding models that enhance the accuracy and relevance of the generated contexts in llama-github.
|
|
81
|
+
|
|
82
|
+
Their contributions have been instrumental in the development of llama-github, and we highly recommend checking out their projects for more innovative solutions.
|
|
85
83
|
|
|
86
84
|
## Contributing
|
|
87
85
|
|
|
@@ -93,7 +91,7 @@ This project is licensed under the terms of the Apache 2.0 license. See the [LIC
|
|
|
93
91
|
|
|
94
92
|
## Contact
|
|
95
93
|
|
|
96
|
-
If you have any questions, suggestions, or feedback, please feel free to reach out to us at [
|
|
94
|
+
If you have any questions, suggestions, or feedback, please feel free to reach out to us at [Jet Xu's email](mailto:Voldemort.xu@foxmail.com).
|
|
97
95
|
|
|
98
96
|
---
|
|
99
97
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"general_prompt": "You are a highly intelligent assistant with expertise in GitHub repositories and coding practices. Your task is to
|
|
2
|
+
"general_prompt": "You are a highly intelligent assistant with expertise in GitHub repositories and coding practices. Your primary task is to provide comprehensive and accurate answers to questions related to GitHub projects, coding issues, or programming concepts. When analyzing queries, focus on delivering a complete response that directly addresses the original question. While you may be provided with additional context, use this information judiciously to enhance your answer without deviating from the main point. Your extensive knowledge base, combined with your ability to understand complex coding queries and retrieve pertinent information, should be the foundation of your responses. When referencing provided context, integrate it seamlessly into your answer without explicitly evaluating or critiquing it. Your goal is to guide developers towards solutions, explain concepts clearly, or provide the information they seek about GitHub projects and software development, always ensuring that your final response is a cohesive and complete answer to the original question.",
|
|
3
3
|
"always_answer_prompt": "**Instructions:**\nAs an advanced AI assistant with deep expertise in GitHub repositories, coding practices, and programming concepts, your primary goal is to provide concise, accurate, and contextually relevant answers to complex coding queries. When presented with a question, your first step is to analyze the query and generate a succinct abstraction that captures its core essence by using only one sentence, especially if the original question is lengthy or convoluted.\n\nNext, leverage your extensive knowledge base and reasoning capabilities to craft a coherent and informative response. If possible, enhance your answer with sample code snippets that demonstrate the practical application of the concepts discussed. Remember, your responses should guide developers towards solving their problems, understanding new concepts, or finding the information they seek related to GitHub projects and software development. Please keep your responses concise and to the point, focusing on the most essential information needed to address the query. Avoid generating long articles or overly detailed explanations.\n\nIn addition to the answer itself, provide a brief analysis of how you would approach searching for relevant code and issues within GitHub repositories. This analysis should outline your thought process and the key factors you would consider when conducting these searches. However, keep this analysis concise and focused on the high-level logic rather than delving into specific search criteria or keywords.\n\nThroughout your responses, prioritize clarity and brevity. Focus on delivering the most essential information needed to address the query effectively. Even if certain details are unknown, ensure that your answers are plausible, useful, and serve as a foundation for further exploration and context generation.\n\nRemember, your ultimate aim is to empower developers with the knowledge and guidance they need to overcome challenges, expand their understanding, and navigate the vast landscape of GitHub repositories and software development practices.",
|
|
4
4
|
"code_search_criteria_prompt": "**Instructions:**\n- **Expertise-Driven Github Code Search Criteria Generation:** Generate GitHub code search criteria strings based on the provided question and its draft answer. Analyze both the question and answer to identify key concepts, technologies, and coding practices that can help locate relevant code snippets on GitHub. Always include the `language:` qualifier to focus your search on language-related content.\n\n**Output Format:** Present each search criteria string on a new line, formatted for immediate use in GitHub's code search, without additional explanations or commentary.\n\n**Optimization Considerations:**\n- **Keyword Relevance:** Extract keywords and phrases tightly related to the question from the question and answer that are likely to appear in relevant code and code comments. Prioritize terms that reflect specific coding concepts, libraries, or techniques. Avoid generic terms like \"example\" or \"integration\" that may not be present in actual code.\n- **Contextual Understanding:** Use the provided answer as additional context to inform your keyword selection. Identify key insights, technologies, or approaches mentioned in the answer tightly related to the question that can help refine the search criteria.\n- **Language and Platform Specificity:** If the question is specific to a certain programming language or platform, ensure to include relevant language or platform-specific keywords, libraries, or frameworks in the search criteria. This helps filter out irrelevant results from other languages or platforms.\n- **Simplicity and Effectiveness:** Craft search criteria with simple and limited keywords which could lead to precise search results to relevant code snippets tightly related to original question. Strike a balance between specificity and breadth to ensure the criteria capture the essential aspects of the question and answer. The search criteria should be neither too narrow that no results are returned, nor too broad that many irrelevant results are included.\n- **Multiple Perspectives:** Generate multiple search criteria strings that approach the question from different angles or emphasize different aspects mentioned in the question and answer. This increases the chances of finding relevant code snippets.",
|
|
5
5
|
"issue_search_criteria_prompt": "**Instructions:**\n- **Question-Driven GitHub Issue Search Criteria Generation:** Generate GitHub issue search criteria strings based on the provided question. Analyze the question to identify key concepts, technologies, and problem-solving approaches that can help locate relevant issues on GitHub. Consider using relevant `label:` or `is:` qualifiers when applicable.\n\n**Output Format:** Present each search criteria string on a new line, formatted for immediate use in GitHub's issue search, without additional explanations or commentary.\n\n**Optimization Considerations:**\n- **Keyword Relevance:** Extract keywords and phrases tightly related to the question that are likely to appear in issue titles, descriptions, and discussions. Prioritize terms that reflect specific problems, error messages, or technologies. Avoid generic terms like \"help\" or \"problem\" that may not effectively narrow down the search results.\n- **Contextual Understanding:** Use the question's draft answer to inform your keyword selection. Identify key aspects, technologies, or potential troubleshooting areas tightly related to the question but not only specific aspects of answers that can help refine the search criteria.\n- **Simplicity and Effectiveness:** Craft search criteria with simple and limited keywords which could lead to precise search results relevant to the original question. Strike a balance between specificity and breadth to ensure the criteria capture the essential aspects of the question without being overly restrictive.\n- **Multiple Perspectives:** Generate multiple search criteria strings that approach the question from different angles or emphasize different aspects mentioned in the question. This increases the chances of finding relevant issues that discuss similar problems or solutions.\n- **Leveraging Labels:** When appropriate, include relevant `label:` qualifiers in the search criteria to narrow down the results to issues with specific labels, such as \"bug,\" \"enhancement,\" or \"documentation.\" This can help focus the search on issues that align with the nature of the question.\n- **Considering Issue Discussions:** Keep in mind that issue discussions often contain valuable information, experiences, and workarounds shared by other developers. Craft search criteria that not only match the issue title and description but also consider the likelihood of the keywords appearing in the issue's comments and discussions.",
|
|
6
6
|
"repo_search_criteria_prompt": "**Instructions:**\n- **Expertise-Driven Github Repository Search Criteria Generation:** Generate GitHub repo search criteria strings based on the provided question. Analyze the question leverage your expertise for related key concepts, technologies, and problem-solving approaches that can help locate relevant repositories on GitHub. Focus on practical keywords and phrases likely to be present in repository names, descriptions, and topics. Use the `language:` qualifier to direct your search toward repositories written in a specific language, keeping the criteria simple and effective.\n- **Necessity Score Determination:** Evaluate the necessity of conducting a GitHub repository search based on the difficulty of question. Determine if repository-level information is essential to comprehensively address the question. Assign a necessity score indicating the importance of performing a repository search.\n\n**Output Format:**\n- **Necessity Score:** Begin your output with a necessity score (0-100) indicating the importance of performing a separate GitHub repository search. Use the following scale:\n - 0-59: Low necessity - Only code and issue search results is sufficient.\n - 60-79: Medium necessity - One repository search may offer additional insights and context.\n - 80-100: High necessity - Two repository searches are crucial to gather comprehensive information, such as project structure, documentation, or community engagement, to thoroughly address the question.\n\n- **Search Criteria:** Present each search criteria string on a new line, formatted for immediate use in GitHub's repository search, without additional explanations or commentary.\n**Optimization Considerations:**\n- **Keyword Relevance:** Generate search criteria keywords and phrases from the question that are uniquely relevant to repository names, descriptions, and topics. Prioritize terms that reflect the broader context, expertise, and strategic thinking required to address the question effectively. Avoid generic terms that may lead to irrelevant search results.\n- **Simplicity and Effectiveness:** Craft search criteria that are simple yet effective in narrowing down the repository search results to the most relevant and informative ones. Strike a balance between specificity and breadth, ensuring that the criteria capture the essential aspects of the question without being overly restrictive. Aim for criteria that yield a manageable number of high-quality repository results.\n- **Language and Platform Specificity:** If the question pertains to a specific programming language or platform, incorporate relevant language or platform-specific keywords in the search criteria. Use the `language:` qualifier to filter repositories based on the language of interest. This helps focus the search on repositories that are more likely to contain relevant code, documentation, and community expertise.\n- **Multiple Criteria Flexibility:** Generate multiple search criteria strings that approach the question from different angles or emphasize different aspects mentioned in the question. This flexibility allows for a more comprehensive repository search, increasing the chances of discovering relevant repositories that may offer valuable insights, code samples, or best practices related to the question at hand.",
|
|
7
7
|
"scoring_context_prompt": "You are an expert in evaluating the relevance of coding-related contexts to given questions. Your primary function is to analyze the provided context and question, and output a single integer score between 0 and 100, indicating how well the context supports answering the question.\n\nScoring criteria:\n0-20: The context is completely irrelevant to the question and provides no useful information to answer it.\n21-40: The context is slightly relevant to the question but lacks crucial information to provide a complete answer.\n41-60: The context is somewhat relevant to the question and provides some useful information, but it may not be sufficient to fully answer the question.\n61-80: The context is highly relevant to the question and provides most of the necessary information to answer it, but some minor details may be missing.\n81-100: The context is extremely relevant to the question and provides all the necessary information to comprehensively answer it.\n\nRemember, your output should consist of only a single integer score without any additional text or explanation. Analyze the context and question carefully, and provide a score that accurately reflects the relevance of the context in answering the question.",
|
|
8
8
|
"default_embedding": "jinaai/jina-embeddings-v2-base-code",
|
|
9
|
-
"default_reranker": "jinaai/jina-reranker-
|
|
9
|
+
"default_reranker": "jinaai/jina-reranker-v2-base-multilingual",
|
|
10
10
|
"min_stars_to_keep_result": 20,
|
|
11
11
|
"max_workers": 8,
|
|
12
12
|
"code_search_max_hits": 30,
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"issue_chunk_size": 7000,
|
|
17
17
|
"repo_chunk_size": 7000,
|
|
18
18
|
"google_chunk_size": 7000,
|
|
19
|
-
"top_n_contexts":
|
|
19
|
+
"top_n_contexts": 4
|
|
20
20
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
from llama_github.logger import logger
|
|
2
2
|
from llama_github.config.config import config
|
|
3
|
-
from typing import List, Optional, Any
|
|
3
|
+
from typing import List, Optional, Any, Dict
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from pprint import pformat
|
|
6
6
|
|
|
7
7
|
from llama_github.llm_integration.initial_load import LLMManager
|
|
8
|
-
from llama_github.llm_integration.llm_handler import LLMHandler
|
|
9
8
|
from llama_github.rag_processing.rag_processor import RAGProcessor
|
|
10
9
|
|
|
11
10
|
from llama_github.github_integration.github_auth_manager import GitHubAuthManager
|
|
@@ -32,6 +31,7 @@ class GithubRAG:
|
|
|
32
31
|
def __init__(self, github_access_token: Optional[str] = None,
|
|
33
32
|
github_app_credentials: Optional[GitHubAppCredentials] = None,
|
|
34
33
|
openai_api_key: Optional[str] = None,
|
|
34
|
+
mistral_api_key: Optional[str] = None,
|
|
35
35
|
huggingface_token: Optional[str] = None,
|
|
36
36
|
jina_api_key: Optional[str] = None,
|
|
37
37
|
open_source_models_hg_dir: Optional[str] = None,
|
|
@@ -92,7 +92,7 @@ class GithubRAG:
|
|
|
92
92
|
logger.debug(
|
|
93
93
|
"Initializing llm manager, embedding model & reranker model...")
|
|
94
94
|
self.llm_manager = LLMManager(
|
|
95
|
-
openai_api_key, huggingface_token, open_source_models_hg_dir, embedding_model, rerank_model, llm)
|
|
95
|
+
openai_api_key, mistral_api_key, huggingface_token, open_source_models_hg_dir, embedding_model, rerank_model, llm)
|
|
96
96
|
logger.debug(
|
|
97
97
|
"LLM Manager, Embedding model & Reranker model Initialized.")
|
|
98
98
|
|
|
@@ -112,8 +112,8 @@ class GithubRAG:
|
|
|
112
112
|
try:
|
|
113
113
|
logger.info("Retrieving context...")
|
|
114
114
|
if simple_mode:
|
|
115
|
-
#In simple mode, only a Google search will be conducted based on the user's question.
|
|
116
|
-
#This model is not suitable for long questions (e.g., questions with more than 20 words).
|
|
115
|
+
# In simple mode, only a Google search will be conducted based on the user's question.
|
|
116
|
+
# This model is not suitable for long questions (e.g., questions with more than 20 words).
|
|
117
117
|
task_google_search = asyncio.create_task(
|
|
118
118
|
self.google_search_retrieval(query=query))
|
|
119
119
|
await asyncio.gather(task_google_search)
|
|
@@ -121,7 +121,7 @@ class GithubRAG:
|
|
|
121
121
|
f"Google search: {str(len(task_google_search.result()))}")
|
|
122
122
|
context_list = self.rag_processor.arrange_context(
|
|
123
123
|
google_search_result=task_google_search.result())
|
|
124
|
-
if len(context_list)>0:
|
|
124
|
+
if len(context_list) > 0:
|
|
125
125
|
topn_contexts = await self.rag_processor.retrieve_topn_contexts(
|
|
126
126
|
context_list=context_list, query=query, top_n=config.get("top_n_contexts"))
|
|
127
127
|
else:
|
|
@@ -166,7 +166,7 @@ class GithubRAG:
|
|
|
166
166
|
repo_search_result=task_repo_search.result(),
|
|
167
167
|
google_search_result=task_google_search.result())
|
|
168
168
|
|
|
169
|
-
if len(context_list)>0:
|
|
169
|
+
if len(context_list) > 0:
|
|
170
170
|
topn_contexts = await self.rag_processor.retrieve_topn_contexts(
|
|
171
171
|
context_list=context_list, query=query, answer=analyzed_strategy[1], top_n=config.get("top_n_contexts"))
|
|
172
172
|
|
|
@@ -237,9 +237,13 @@ class GithubRAG:
|
|
|
237
237
|
seen = set()
|
|
238
238
|
unique_list = []
|
|
239
239
|
for d in result:
|
|
240
|
-
|
|
241
|
-
if
|
|
242
|
-
seen.add(
|
|
240
|
+
api_url = d["url"]
|
|
241
|
+
if api_url not in seen:
|
|
242
|
+
seen.add(api_url)
|
|
243
|
+
# Transform the API URL to the official GitHub issue webpage URL
|
|
244
|
+
html_url = api_url.replace(
|
|
245
|
+
'api.github.com/repos', 'github.com').replace('issues/', 'issues/')
|
|
246
|
+
d["url"] = html_url
|
|
243
247
|
unique_list.append(d)
|
|
244
248
|
result = unique_list
|
|
245
249
|
|
|
@@ -330,6 +334,7 @@ class GithubRAG:
|
|
|
330
334
|
results_with_index.append({
|
|
331
335
|
'index': index,
|
|
332
336
|
'full_name': repository.full_name,
|
|
337
|
+
'url': repository.html_url,
|
|
333
338
|
'content': repo_readme,
|
|
334
339
|
})
|
|
335
340
|
# if repo_simple_structure:
|
|
@@ -345,4 +350,57 @@ class GithubRAG:
|
|
|
345
350
|
logger.info("Repo search retrieved successfully.")
|
|
346
351
|
except Exception as e:
|
|
347
352
|
logger.error(f"Error retrieving repos search: {e}")
|
|
348
|
-
return results_with_index
|
|
353
|
+
return results_with_index
|
|
354
|
+
|
|
355
|
+
def answer_with_context(self, query: str, contexts: Optional[List[Dict[str, Any]]] = None, simple_mode=False) -> str:
|
|
356
|
+
"""
|
|
357
|
+
Generate an answer based on the given query and optional contexts.
|
|
358
|
+
|
|
359
|
+
This method can be called in different environments (Jupyter notebook,
|
|
360
|
+
synchronous Python program, asynchronous Python program) and will
|
|
361
|
+
handle the async call appropriately.
|
|
362
|
+
|
|
363
|
+
Args:
|
|
364
|
+
query (str): The user's query.
|
|
365
|
+
contexts (Optional[List[Dict[str, Any]]]): Optional list of context dictionaries.
|
|
366
|
+
Each dictionary should contain 'content' and 'url' keys.
|
|
367
|
+
|
|
368
|
+
Returns:
|
|
369
|
+
str: The generated answer.
|
|
370
|
+
"""
|
|
371
|
+
self.loop = asyncio.get_event_loop()
|
|
372
|
+
ipython = get_ipython()
|
|
373
|
+
if ipython and ipython.has_trait('kernel'):
|
|
374
|
+
logger.debug("Running in Jupyter notebook, nest_asyncio applied.")
|
|
375
|
+
import nest_asyncio
|
|
376
|
+
nest_asyncio.apply()
|
|
377
|
+
return asyncio.run(self.async_answer_with_context(query, contexts, simple_mode))
|
|
378
|
+
if self.loop.is_running():
|
|
379
|
+
return asyncio.ensure_future(self.async_answer_with_context(query, contexts, simple_mode))
|
|
380
|
+
return self.loop.run_until_complete(self.async_answer_with_context(query, contexts, simple_mode))
|
|
381
|
+
|
|
382
|
+
async def async_answer_with_context(self, query: str, contexts: Optional[List[Dict[str, Any]]] = None, simple_mode=False) -> str:
|
|
383
|
+
"""
|
|
384
|
+
Asynchronously generate an answer based on the given query and optional contexts.
|
|
385
|
+
|
|
386
|
+
Args:
|
|
387
|
+
query (str): The user's query.
|
|
388
|
+
contexts (Optional[List[Dict[str, Any]]]): Optional list of context dictionaries.
|
|
389
|
+
Each dictionary should contain 'content' and 'url' keys.
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
str: The generated answer.
|
|
393
|
+
"""
|
|
394
|
+
if contexts is None:
|
|
395
|
+
contexts = await self.async_retrieve_context(query, simple_mode)
|
|
396
|
+
logger.debug(f"Retrieved contexts: {contexts}")
|
|
397
|
+
context_contents = [context['context'] for context in contexts]
|
|
398
|
+
context_urls = [context['url'] for context in contexts]
|
|
399
|
+
|
|
400
|
+
answer = await self.rag_processor.llm_handler.ainvoke(
|
|
401
|
+
human_question=query,
|
|
402
|
+
context=context_contents,
|
|
403
|
+
# context_urls=context_urls
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
return answer
|
|
@@ -5,6 +5,7 @@ from threading import Lock
|
|
|
5
5
|
from langchain_openai import ChatOpenAI
|
|
6
6
|
from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
7
7
|
from langchain_community.cross_encoders import HuggingFaceCrossEncoder
|
|
8
|
+
from langchain_mistralai.chat_models import ChatMistralAI
|
|
8
9
|
|
|
9
10
|
from llama_github.config.config import config
|
|
10
11
|
from llama_github.logger import logger
|
|
@@ -33,6 +34,7 @@ class LLMManager:
|
|
|
33
34
|
|
|
34
35
|
def __init__(self,
|
|
35
36
|
openai_api_key: Optional[str] = None,
|
|
37
|
+
mistral_api_key: Optional[str] = None,
|
|
36
38
|
huggingface_token: Optional[str] = None,
|
|
37
39
|
open_source_models_hg_dir: Optional[str] = None,
|
|
38
40
|
embedding_model: Optional[str] = config.get(
|
|
@@ -48,11 +50,16 @@ class LLMManager:
|
|
|
48
50
|
if llm is not None:
|
|
49
51
|
self.llm = llm
|
|
50
52
|
self.model_type = "Custom_langchain_llm"
|
|
53
|
+
elif mistral_api_key is not None and mistral_api_key != "" and self.llm is None:
|
|
54
|
+
logger.info("Initializing Mistral API...")
|
|
55
|
+
self.llm = ChatMistralAI(mistral_api_key=mistral_api_key, model="mistral-large-latest")
|
|
56
|
+
self.llm_simple = ChatMistralAI(mistral_api_key=mistral_api_key, model="open-mistral-nemo")
|
|
57
|
+
self.model_type = "OpenAI"
|
|
51
58
|
elif openai_api_key is not None and openai_api_key != "" and self.llm is None:
|
|
52
59
|
logger.info("Initializing OpenAI API...")
|
|
53
60
|
self.llm = ChatOpenAI(api_key=openai_api_key, model="gpt-4-turbo")
|
|
54
61
|
self.llm_simple = ChatOpenAI(
|
|
55
|
-
api_key=openai_api_key, model="gpt-
|
|
62
|
+
api_key=openai_api_key, model="gpt-4o-mini")
|
|
56
63
|
self.model_type = "OpenAI"
|
|
57
64
|
# Initialize for Open Source Models
|
|
58
65
|
elif open_source_models_hg_dir is not None and open_source_models_hg_dir != "" and self.llm is None:
|
|
@@ -8,11 +8,10 @@ from langchain_core.output_parsers import StrOutputParser
|
|
|
8
8
|
from llama_github.config.config import config
|
|
9
9
|
from llama_github.logger import logger
|
|
10
10
|
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
|
11
|
-
from
|
|
11
|
+
from pydantic import BaseModel
|
|
12
12
|
from typing import Optional
|
|
13
13
|
from langchain_openai import output_parsers
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
class LLMHandler:
|
|
17
16
|
def __init__(self, llm_manager: Optional[LLMManager] = None):
|
|
18
17
|
"""
|
|
@@ -80,7 +79,6 @@ class LLMHandler:
|
|
|
80
79
|
|
|
81
80
|
# Format the prompt with the provided parameters.
|
|
82
81
|
formatted_prompt = chat_prompt.format_prompt(**prompt_params)
|
|
83
|
-
logger.debug(f"Formatted prompt: {formatted_prompt}")
|
|
84
82
|
# Determine the processing chain based on the presence of an output structure.
|
|
85
83
|
if output_structure is not None:
|
|
86
84
|
chain = llm.with_structured_output(output_structure)
|
|
@@ -92,7 +90,7 @@ class LLMHandler:
|
|
|
92
90
|
response = await chain.ainvoke(formatted_prompt.to_messages())
|
|
93
91
|
except Exception as e:
|
|
94
92
|
logger.exception(
|
|
95
|
-
f"Call llm with #{human_question}# generated an exception:{e}")
|
|
93
|
+
f"Call {'simple ' if simple_llm else ''}llm with #{human_question}# generated an exception:{e}")
|
|
96
94
|
if output_structure is not None:
|
|
97
95
|
response = await chain.ainvoke(formatted_prompt.to_messages())
|
|
98
96
|
return response
|
|
@@ -209,20 +209,21 @@ class RAGProcessor:
|
|
|
209
209
|
logger.error(f"Error in get_issue_search_criteria: {e}")
|
|
210
210
|
return []
|
|
211
211
|
|
|
212
|
-
def _arrange_code_search_result(self, code_search_result: List[Dict]) -> List[Dict]:
|
|
212
|
+
def _arrange_code_search_result(self, code_search_result: List[Dict]) -> List[Dict[str, str]]:
|
|
213
213
|
"""
|
|
214
|
-
Arrange the result of
|
|
214
|
+
Arrange the result of Code search with metadata.
|
|
215
215
|
|
|
216
216
|
Args:
|
|
217
|
-
|
|
217
|
+
_arrange_code_search_result (dict): The result of Code search.
|
|
218
218
|
|
|
219
219
|
Returns:
|
|
220
|
-
|
|
220
|
+
List[Dict[str, str]]: The arranged result of Code search with metadata.
|
|
221
221
|
"""
|
|
222
222
|
arranged_results = []
|
|
223
223
|
|
|
224
224
|
for result in code_search_result:
|
|
225
225
|
content = result['content']
|
|
226
|
+
url = result.get('url', '')
|
|
226
227
|
|
|
227
228
|
# Split content into chunks
|
|
228
229
|
chunks = self._split_content_into_chunks(
|
|
@@ -249,7 +250,7 @@ class RAGProcessor:
|
|
|
249
250
|
f"programming language is: {language}\n\n"
|
|
250
251
|
f"{chunk}"
|
|
251
252
|
)
|
|
252
|
-
arranged_results.append(chunk_text)
|
|
253
|
+
arranged_results.append({'context': chunk_text, 'url': url})
|
|
253
254
|
|
|
254
255
|
return arranged_results
|
|
255
256
|
|
|
@@ -290,173 +291,182 @@ class RAGProcessor:
|
|
|
290
291
|
chunks = splitter.split_text(content)
|
|
291
292
|
return chunks
|
|
292
293
|
|
|
293
|
-
def _arrange_issue_search_result(self, issue_search_result: dict) ->
|
|
294
|
+
def _arrange_issue_search_result(self, issue_search_result: dict) -> List[Dict[str, str]]:
|
|
294
295
|
"""
|
|
295
|
-
|
|
296
|
+
Arrange the result of Issue search with metadata.
|
|
296
297
|
|
|
297
298
|
Args:
|
|
298
|
-
|
|
299
|
+
_arrange_issue_search_result (dict): The result of Issue search.
|
|
299
300
|
|
|
300
301
|
Returns:
|
|
301
|
-
|
|
302
|
+
List[Dict[str, str]]: The arranged result of Issue search with metadata.
|
|
302
303
|
"""
|
|
303
304
|
arranged_results = []
|
|
304
305
|
|
|
305
306
|
for result in issue_search_result:
|
|
306
307
|
content = result['issue_content']
|
|
308
|
+
url = result.get('url', '')
|
|
307
309
|
|
|
308
310
|
# Split content into chunks
|
|
309
311
|
chunks = self._split_content_into_chunks(
|
|
310
312
|
content, max_tokens=config.get('issue_chunk_size'))
|
|
311
313
|
|
|
312
314
|
for chunk in chunks:
|
|
313
|
-
arranged_results.append(chunk)
|
|
315
|
+
arranged_results.append({'context': chunk, 'url': url})
|
|
314
316
|
|
|
315
317
|
return arranged_results
|
|
316
318
|
|
|
317
|
-
def _arrange_repo_search_result(self, repo_search_result: dict) ->
|
|
319
|
+
def _arrange_repo_search_result(self, repo_search_result: dict) -> List[Dict[str, str]]:
|
|
318
320
|
"""
|
|
319
|
-
|
|
321
|
+
Arrange the result of Repo search with metadata.
|
|
320
322
|
|
|
321
323
|
Args:
|
|
322
|
-
|
|
324
|
+
_arrange_repo_search_result (dict): The result of Repo search.
|
|
323
325
|
|
|
324
326
|
Returns:
|
|
325
|
-
|
|
327
|
+
List[Dict[str, str]]: The arranged result of Repo search with metadata.
|
|
326
328
|
"""
|
|
327
329
|
arranged_results = []
|
|
328
330
|
|
|
329
331
|
for result in repo_search_result:
|
|
330
332
|
content = result['content']
|
|
333
|
+
url = result.get('url', '')
|
|
331
334
|
|
|
332
335
|
# Split content into chunks
|
|
333
336
|
chunks = self._split_content_into_chunks(
|
|
334
337
|
content, max_tokens=config.get('repo_chunk_size'))
|
|
335
338
|
|
|
336
339
|
for chunk in chunks:
|
|
337
|
-
arranged_results.append(chunk)
|
|
340
|
+
arranged_results.append({'context': chunk, 'url': url})
|
|
338
341
|
|
|
339
342
|
return arranged_results
|
|
340
343
|
|
|
341
|
-
def _arrange_google_search_result(self, google_search_result: dict) ->
|
|
344
|
+
def _arrange_google_search_result(self, google_search_result: dict) -> List[Dict[str, str]]:
|
|
342
345
|
"""
|
|
343
|
-
|
|
346
|
+
Arrange the result of Google search with metadata.
|
|
344
347
|
|
|
345
348
|
Args:
|
|
346
|
-
google_search_result (dict):
|
|
349
|
+
google_search_result (dict): The result of Google search.
|
|
347
350
|
|
|
348
351
|
Returns:
|
|
349
|
-
|
|
352
|
+
List[Dict[str, str]]: The arranged result of Google search with metadata.
|
|
350
353
|
"""
|
|
351
354
|
arranged_results = []
|
|
352
355
|
|
|
353
356
|
for result in google_search_result:
|
|
354
357
|
content = result['content']
|
|
358
|
+
url = result.get('url', '') # Extract the URL if available
|
|
355
359
|
|
|
356
360
|
# Split content into chunks
|
|
357
|
-
chunks = self._split_content_into_chunks(
|
|
358
|
-
content, max_tokens=config.get('google_chunk_size'))
|
|
361
|
+
chunks = self._split_content_into_chunks(content, max_tokens=config.get('google_chunk_size'))
|
|
359
362
|
|
|
360
363
|
for chunk in chunks:
|
|
361
|
-
arranged_results.append(chunk)
|
|
364
|
+
arranged_results.append({'context': chunk, 'url': url})
|
|
362
365
|
|
|
363
366
|
return arranged_results
|
|
364
367
|
|
|
365
|
-
def arrange_context(self, code_search_result: Optional[dict] = None, issue_search_result: Optional[dict] = None,
|
|
368
|
+
def arrange_context(self, code_search_result: Optional[dict] = None, issue_search_result: Optional[dict] = None,
|
|
369
|
+
repo_search_result: Optional[dict] = None, google_search_result: Optional[dict] = None) -> List[
|
|
370
|
+
Dict[str, str]]:
|
|
366
371
|
"""
|
|
367
|
-
|
|
372
|
+
Arrange the context before RAG with metadata.
|
|
368
373
|
|
|
369
374
|
Args:
|
|
370
|
-
code_search_result (dict, optional):
|
|
371
|
-
issue_search_result (dict, optional):
|
|
372
|
-
repo_search_result (dict, optional):
|
|
373
|
-
google_search_result (dict, optional):
|
|
375
|
+
code_search_result (dict, optional): The result of code search. Defaults to None.
|
|
376
|
+
issue_search_result (dict, optional): The result of issue search. Defaults to None.
|
|
377
|
+
repo_search_result (dict, optional): The result of repo search. Defaults to None.
|
|
378
|
+
google_search_result (dict, optional): The result of Google search. Defaults to None.
|
|
374
379
|
|
|
375
380
|
Returns:
|
|
376
|
-
|
|
381
|
+
List[Dict[str, str]]: The arranged context with metadata.
|
|
377
382
|
"""
|
|
378
383
|
context = []
|
|
379
384
|
if code_search_result:
|
|
380
|
-
context.extend(
|
|
381
|
-
self._arrange_code_search_result(code_search_result))
|
|
385
|
+
context.extend(self._arrange_code_search_result(code_search_result))
|
|
382
386
|
if issue_search_result:
|
|
383
|
-
context.extend(
|
|
384
|
-
self._arrange_issue_search_result(issue_search_result))
|
|
387
|
+
context.extend(self._arrange_issue_search_result(issue_search_result))
|
|
385
388
|
if repo_search_result:
|
|
386
|
-
context.extend(
|
|
387
|
-
self._arrange_repo_search_result(repo_search_result))
|
|
389
|
+
context.extend(self._arrange_repo_search_result(repo_search_result))
|
|
388
390
|
if google_search_result:
|
|
389
|
-
context.extend(
|
|
390
|
-
self._arrange_google_search_result(google_search_result))
|
|
391
|
+
context.extend(self._arrange_google_search_result(google_search_result))
|
|
391
392
|
return context
|
|
392
393
|
|
|
393
|
-
async def retrieve_topn_contexts(self, context_list: List[str], query: str, answer: Optional[str] = None,
|
|
394
|
+
async def retrieve_topn_contexts(self, context_list: List[Dict[str, str]], query: str, answer: Optional[str] = None,
|
|
395
|
+
top_n: Optional[int] = 5) -> List[Dict[str, str]]:
|
|
394
396
|
"""
|
|
395
|
-
Retrieve top n context
|
|
397
|
+
Retrieve top n context dictionaries from the context list.
|
|
396
398
|
|
|
397
399
|
Args:
|
|
398
|
-
context_list (List[str]): List of context
|
|
400
|
+
context_list (List[Dict[str, str]]): List of context dictionaries to retrieve top n from.
|
|
401
|
+
Each dictionary should have at least 'context' and 'url' keys.
|
|
399
402
|
query (str): The query string.
|
|
400
403
|
answer (Optional[str]): The answer string (optional).
|
|
401
404
|
top_n (Optional[int]): Number of top context strings to retrieve (default: 5).
|
|
402
405
|
|
|
403
406
|
Returns:
|
|
404
|
-
List[str]: A list of top n context
|
|
407
|
+
List[Dict[str, str]]: A list of top n context dictionaries.
|
|
405
408
|
"""
|
|
406
409
|
top_contexts = []
|
|
407
410
|
try:
|
|
408
411
|
reranker = self.llm_manager.get_rerank_model()
|
|
409
412
|
|
|
410
|
-
|
|
413
|
+
# Extract contexts from the dictionaries
|
|
414
|
+
contexts = [context_item['context'] for context_item in context_list]
|
|
415
|
+
|
|
416
|
+
# Create sentence pairs for reranking
|
|
417
|
+
sentence_pairs = [[query, doc] for doc in contexts]
|
|
411
418
|
rerank_scores = reranker.compute_score(sentence_pairs)
|
|
412
419
|
|
|
413
|
-
# Zip scores with
|
|
420
|
+
# Zip scores with context dictionaries
|
|
414
421
|
scored_contexts = list(zip(rerank_scores, context_list))
|
|
415
422
|
sorted_scored_contexts = sorted(
|
|
416
423
|
scored_contexts, key=lambda x: x[0], reverse=True)
|
|
417
424
|
|
|
418
|
-
# Extract top 3*top_n
|
|
419
|
-
|
|
420
|
-
|
|
425
|
+
# Extract top 3*top_n context dictionaries after rerank
|
|
426
|
+
selected_contexts = [context for score, context in
|
|
427
|
+
sorted_scored_contexts[:min(top_n * 3, len(sorted_scored_contexts))]]
|
|
421
428
|
|
|
422
429
|
# If there are too few contexts, skip embedding comparison step
|
|
423
|
-
if len(
|
|
424
|
-
return
|
|
430
|
+
if len(selected_contexts) < top_n * 2:
|
|
431
|
+
return selected_contexts[:min(top_n, len(selected_contexts))]
|
|
425
432
|
|
|
426
|
-
# Calculate
|
|
433
|
+
# Calculate embeddings to select top 2*top_n
|
|
427
434
|
logger.debug("Embedding start...")
|
|
428
435
|
embedding_model = self.llm_manager.get_embedding_model()
|
|
429
|
-
query_embedding = embedding_model.encode(
|
|
430
|
-
|
|
431
|
-
context_embeddings = [embedding_model.encode(
|
|
432
|
-
context) for context in selected_context]
|
|
436
|
+
query_embedding = embedding_model.encode(query + "\n" + answer if answer is not None else "")
|
|
437
|
+
context_embeddings = [embedding_model.encode(context_item['context']) for context_item in selected_contexts]
|
|
433
438
|
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
# Calculate cosine similarities
|
|
440
|
+
cos_similarities = [
|
|
441
|
+
(query_embedding @ context_embedding.T) / (norm(query_embedding) * norm(context_embedding))
|
|
442
|
+
for context_embedding in context_embeddings]
|
|
436
443
|
|
|
437
|
-
|
|
438
|
-
|
|
444
|
+
# Get top indices based on cosine similarities
|
|
445
|
+
top_indices = np.argsort(cos_similarities)[-(top_n * 2):][::-1]
|
|
446
|
+
top_contexts = [selected_contexts[i] for i in top_indices]
|
|
439
447
|
top_cos_similarities = [cos_similarities[i] for i in top_indices]
|
|
440
|
-
top_rerank_scores = [rerank_scores[
|
|
441
|
-
|
|
448
|
+
top_rerank_scores = [rerank_scores[contexts.index(context_item['context'])] for context_item in
|
|
449
|
+
top_contexts]
|
|
442
450
|
|
|
443
|
-
# Use simple LLM to calculate context
|
|
444
|
-
llm_scores = await asyncio.gather(
|
|
451
|
+
# Use simple LLM to calculate context relevance scores
|
|
452
|
+
llm_scores = await asyncio.gather(
|
|
453
|
+
*[self.get_context_relevance_score(query, context_item['context']) for context_item in top_contexts])
|
|
445
454
|
logger.debug(f"Simple LLM scores: {llm_scores}")
|
|
446
455
|
|
|
447
456
|
# Combine scores for final ranking
|
|
448
457
|
combined_scores = [llm_score * cos_sim * rerank_score
|
|
449
|
-
for llm_score, cos_sim, rerank_score in
|
|
458
|
+
for llm_score, cos_sim, rerank_score in
|
|
459
|
+
zip(llm_scores, top_cos_similarities, top_rerank_scores)]
|
|
450
460
|
|
|
451
461
|
combined_context_scores = list(zip(top_contexts, combined_scores))
|
|
452
462
|
sorted_combined_context_scores = sorted(
|
|
453
463
|
combined_context_scores, key=lambda x: x[1], reverse=True)
|
|
454
|
-
logger.debug(
|
|
455
|
-
f"Combined sorted context scores: {sorted_combined_context_scores}")
|
|
464
|
+
logger.debug(f"Combined sorted context scores: {sorted_combined_context_scores}")
|
|
456
465
|
|
|
457
|
-
|
|
458
|
-
|
|
466
|
+
# Extract top n context dictionaries
|
|
467
|
+
top_contexts = [context for context, _ in sorted_combined_context_scores[:top_n]]
|
|
459
468
|
logger.debug(f"Final top contexts: {top_contexts}")
|
|
469
|
+
|
|
460
470
|
except Exception as e:
|
|
461
471
|
logger.error(f"Error retrieving top n context: {e}")
|
|
462
472
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.1.1'
|
|
@@ -1,8 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: llama-github
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Llama-github is an open-source Python library that empowers LLM Chatbots, AI Agents, and Auto-dev Agents to conduct Retrieval from actively selected GitHub public projects. It Augments through LLMs and Generates context for any coding question, in order to streamline the development of sophisticated AI-driven applications.
|
|
5
|
+
Home-page: https://github.com/JetXu-LLM/llama-github
|
|
6
|
+
Author: Jet Xu
|
|
7
|
+
Author-email: Voldemort.xu@foxmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: aiohttp
|
|
15
|
+
Requires-Dist: asyncio
|
|
16
|
+
Requires-Dist: dataclasses
|
|
17
|
+
Requires-Dist: PyGithub
|
|
18
|
+
Requires-Dist: langchain
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Requires-Dist: pydantic
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: torch
|
|
23
|
+
Requires-Dist: transformers
|
|
24
|
+
Requires-Dist: urllib3
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest; extra == "dev"
|
|
27
|
+
Requires-Dist: black; extra == "dev"
|
|
28
|
+
Requires-Dist: flake8; extra == "dev"
|
|
29
|
+
|
|
1
30
|
# llama-github
|
|
2
31
|
|
|
32
|
+
[](https://badge.fury.io/py/llama-github)
|
|
33
|
+
[](https://pepy.tech/project/Llama-github)
|
|
3
34
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
4
35
|
|
|
5
|
-
Llama-github is
|
|
36
|
+
Llama-github is a powerful tool that helps you retrieve the most relevant code snippets, issues, and repository information from GitHub based on your queries, transforming them into valuable knowledge context. It empowers LLM Chatbots, AI Agents, and Auto-dev Agents to solve complex coding tasks. Whether you're a developer looking for quick solutions or an engineer implementing advanced Auto Dev AI Agents, llama-github makes it easy and efficient.
|
|
37
|
+
|
|
38
|
+
If you like this project or believe it has potential, please give it a ⭐️. Your support is our greatest motivation!
|
|
39
|
+
|
|
40
|
+
## Architecture
|
|
41
|
+

|
|
6
42
|
|
|
7
43
|
## Installation
|
|
8
44
|
```
|
|
@@ -53,6 +89,26 @@ For more advanced usage and examples, please refer to the [documentation](docs/u
|
|
|
53
89
|
|
|
54
90
|
- **🛠️ Logging and Error Handling**: We understand the importance of smooth operations and easy troubleshooting. That's why llama-github comes equipped with comprehensive logging and error handling mechanisms. Gain deep insights into the library's behavior, quickly diagnose issues, and maintain a stable and reliable development workflow.
|
|
55
91
|
|
|
92
|
+
## Vision and Roadmap
|
|
93
|
+
|
|
94
|
+
### Vision
|
|
95
|
+
|
|
96
|
+
Our vision is to become a pivotal module in the future of AI-driven development solutions, seamlessly integrating with GitHub to empower LLMs in automatically resolving complex coding tasks.
|
|
97
|
+
|
|
98
|
+

|
|
99
|
+
|
|
100
|
+
### Roadmap
|
|
101
|
+
|
|
102
|
+
For a detailed view of our project roadmap, please visit our [Project Roadmap](https://github.com/users/JetXu-LLM/projects/2).
|
|
103
|
+
|
|
104
|
+
## Acknowledgments
|
|
105
|
+
|
|
106
|
+
We would like to express our gratitude to the following open-source projects for their support and contributions:
|
|
107
|
+
|
|
108
|
+
- **[LangChain](https://github.com/langchain-ai/langchain)**: For providing the foundational framework that empowers the LLM prompting and processing capabilities in llama-github.
|
|
109
|
+
- **[Jina.ai](https://github.com/jina-ai/reader)**: For offering s.jina.ai API and open source reranker and embedding models that enhance the accuracy and relevance of the generated contexts in llama-github.
|
|
110
|
+
|
|
111
|
+
Their contributions have been instrumental in the development of llama-github, and we highly recommend checking out their projects for more innovative solutions.
|
|
56
112
|
|
|
57
113
|
## Contributing
|
|
58
114
|
|
|
@@ -64,8 +120,43 @@ This project is licensed under the terms of the Apache 2.0 license. See the [LIC
|
|
|
64
120
|
|
|
65
121
|
## Contact
|
|
66
122
|
|
|
67
|
-
If you have any questions, suggestions, or feedback, please feel free to reach out to us at [
|
|
123
|
+
If you have any questions, suggestions, or feedback, please feel free to reach out to us at [Jet Xu's email](mailto:Voldemort.xu@foxmail.com).
|
|
68
124
|
|
|
69
125
|
---
|
|
70
126
|
|
|
71
|
-
Thank you for choosing llama-github! We hope this library enhances your AI development experience and helps you build powerful applications with ease.
|
|
127
|
+
Thank you for choosing llama-github! We hope this library enhances your AI development experience and helps you build powerful applications with ease.
|
|
128
|
+
|
|
129
|
+
# Changelog
|
|
130
|
+
|
|
131
|
+
All notable changes to this project will be documented in this file.
|
|
132
|
+
|
|
133
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
134
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
135
|
+
|
|
136
|
+
## [0.1.1] - 2024-08-23
|
|
137
|
+
|
|
138
|
+
### Added
|
|
139
|
+
- Implemented `answer_with_context` method for direct answer generation (closes #6)
|
|
140
|
+
- Added support for Mistral AI LLM provider
|
|
141
|
+
- Enhanced `retrieve_context` function to include metadata (e.g., URLs) with each context string (closes #2)
|
|
142
|
+
|
|
143
|
+
### Changed
|
|
144
|
+
- Improved reranking with jina-reranker-v2 for better context retrieval
|
|
145
|
+
- Updated return type of `retrieve_context` to accommodate metadata
|
|
146
|
+
|
|
147
|
+
### Fixed
|
|
148
|
+
- Resolved warning during context retrieval (closes #3)
|
|
149
|
+
|
|
150
|
+
### Improved
|
|
151
|
+
- Enhanced overall context retrieval process
|
|
152
|
+
- Expanded LLM support for more versatile use cases
|
|
153
|
+
|
|
154
|
+
## [0.1.0] - 2024-08-15
|
|
155
|
+
|
|
156
|
+
### Added
|
|
157
|
+
- Initial release of llama-github
|
|
158
|
+
- Basic functionality for retrieving context from GitHub repositories
|
|
159
|
+
- Integration with LLM for processing and generating responses
|
|
160
|
+
|
|
161
|
+
[0.1.1]: https://github.com/JetXu-LLM/llama-github/compare/v0.1.0...v0.1.1
|
|
162
|
+
[0.1.0]: https://github.com/JetXu-LLM/llama-github/releases/tag/v0.1.0
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = llama-github
|
|
3
|
-
version = 0.1.
|
|
3
|
+
version = 0.1.1
|
|
4
4
|
author = Jet Xu
|
|
5
5
|
author_email = Voldemort.xu@foxmail.com
|
|
6
6
|
description = Llama-github is an open-source Python library that empowers LLM Chatbots, AI Agents, and Auto-dev Agents to conduct Retrieval from actively selected GitHub public projects. It Augments through LLMs and Generates context for any coding question, in order to streamline the development of sophisticated AI-driven applications.
|
|
7
|
-
long_description = file: README.md
|
|
7
|
+
long_description = file: README.md, CHANGELOG.md
|
|
8
8
|
long_description_content_type = text/markdown
|
|
9
9
|
url = https://github.com/JetXu-LLM/llama-github
|
|
10
10
|
classifiers =
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
from setuptools import setup, find_packages
|
|
2
|
+
from configparser import ConfigParser
|
|
2
3
|
|
|
3
4
|
# Read the requirements from requirements.txt
|
|
4
5
|
with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|
5
6
|
requirements = fh.readlines()
|
|
6
7
|
|
|
8
|
+
# Read version from setup.cfg
|
|
9
|
+
config = ConfigParser()
|
|
10
|
+
config.read('setup.cfg')
|
|
11
|
+
version = config['metadata']['version']
|
|
12
|
+
|
|
7
13
|
setup(
|
|
14
|
+
version=version,
|
|
8
15
|
install_requires=[req.strip() for req in requirements],
|
|
9
16
|
)
|
llama_github-0.1.0/MANIFEST.in
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
include llama_github/config/config.json
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.1.0'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{llama_github-0.1.0 → llama_github-0.1.1}/llama_github/github_integration/github_auth_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|