llama-github 0.1.5__tar.gz → 0.1.6__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.
Files changed (40) hide show
  1. {llama_github-0.1.5 → llama_github-0.1.6}/CHANGELOG.md +12 -0
  2. {llama_github-0.1.5/llama_github.egg-info → llama_github-0.1.6}/PKG-INFO +16 -2
  3. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/data_retrieval/github_entities.py +90 -13
  4. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/llm_integration/initial_load.py +78 -13
  5. llama_github-0.1.6/llama_github/version.py +1 -0
  6. {llama_github-0.1.5 → llama_github-0.1.6/llama_github.egg-info}/PKG-INFO +16 -2
  7. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github.egg-info/requires.txt +3 -1
  8. {llama_github-0.1.5 → llama_github-0.1.6}/setup.cfg +1 -1
  9. llama_github-0.1.5/llama_github/version.py +0 -1
  10. {llama_github-0.1.5 → llama_github-0.1.6}/LICENSE +0 -0
  11. {llama_github-0.1.5 → llama_github-0.1.6}/MANIFEST.in +0 -0
  12. {llama_github-0.1.5 → llama_github-0.1.6}/README.md +0 -0
  13. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/__init__.py +0 -0
  14. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/config/__init__.py +0 -0
  15. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/config/config.json +0 -0
  16. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/config/config.py +0 -0
  17. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/data_retrieval/__init__.py +0 -0
  18. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/data_retrieval/github_api.py +0 -0
  19. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/features/__init__.py +0 -0
  20. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/features/feature_flags.py +0 -0
  21. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/features/insider_features.py +0 -0
  22. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/github_integration/__init__.py +0 -0
  23. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/github_integration/github_auth_manager.py +0 -0
  24. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/github_rag.py +0 -0
  25. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/llm_integration/__init__.py +0 -0
  26. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/llm_integration/llm_handler.py +0 -0
  27. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/logger.py +0 -0
  28. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/rag_processing/__init__.py +0 -0
  29. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/rag_processing/rag_processor.py +0 -0
  30. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github/utils.py +0 -0
  31. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github.egg-info/SOURCES.txt +0 -0
  32. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github.egg-info/dependency_links.txt +0 -0
  33. {llama_github-0.1.5 → llama_github-0.1.6}/llama_github.egg-info/top_level.txt +0 -0
  34. {llama_github-0.1.5 → llama_github-0.1.6}/setup.py +0 -0
  35. {llama_github-0.1.5 → llama_github-0.1.6}/tests/test_data_retrieval.py +0 -0
  36. {llama_github-0.1.5 → llama_github-0.1.6}/tests/test_github_auth_manager.py +0 -0
  37. {llama_github-0.1.5 → llama_github-0.1.6}/tests/test_initial_load.py +0 -0
  38. {llama_github-0.1.5 → llama_github-0.1.6}/tests/test_llm_handler.py +0 -0
  39. {llama_github-0.1.5 → llama_github-0.1.6}/tests/test_logger.py +0 -0
  40. {llama_github-0.1.5 → llama_github-0.1.6}/tests/test_rag_processor.py +0 -0
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.6] - 2024-10-30
9
+
10
+ ### New Features
11
+ - Enhanced PR content analysis with detailed commit information extraction
12
+ - Improved issue linking detection with support for multiple reference formats
13
+ - Full GitHub URLs, #references, and keyword-based references
14
+ - Added validation for issue numbers
15
+
16
+ ### Improvements
17
+ - Added detailed commit metadata extraction including stats and file changes
18
+ - Enhanced error handling for commit fetching
19
+
8
20
  ## [0.1.5] - 2024-10-14
9
21
 
10
22
  ### Optimized
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-github
3
- Version: 0.1.5
3
+ Version: 0.1.6
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
@@ -19,9 +19,11 @@ Requires-Dist: langchain
19
19
  Requires-Dist: numpy
20
20
  Requires-Dist: pydantic
21
21
  Requires-Dist: requests
22
- Requires-Dist: torch
23
22
  Requires-Dist: transformers
24
23
  Requires-Dist: urllib3
24
+ Requires-Dist: sys
25
+ Requires-Dist: platform
26
+ Requires-Dist: subprocess
25
27
  Requires-Dist: pydantic_core
26
28
  Requires-Dist: langchain_openai
27
29
  Requires-Dist: langchain_mistralai
@@ -138,6 +140,18 @@ All notable changes to this project will be documented in this file.
138
140
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
139
141
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
140
142
 
143
+ ## [0.1.6] - 2024-10-30
144
+
145
+ ### New Features
146
+ - Enhanced PR content analysis with detailed commit information extraction
147
+ - Improved issue linking detection with support for multiple reference formats
148
+ - Full GitHub URLs, #references, and keyword-based references
149
+ - Added validation for issue numbers
150
+
151
+ ### Improvements
152
+ - Added detailed commit metadata extraction including stats and file changes
153
+ - Enhanced error handling for commit fetching
154
+
141
155
  ## [0.1.5] - 2024-10-14
142
156
 
143
157
  ### Optimized
@@ -241,25 +241,79 @@ class Repository:
241
241
 
242
242
  def extract_related_issues(self, pr_data: Dict[str, Any]) -> List[int]:
243
243
  """
244
- Extracts related issue numbers from the PR description and other fields.
245
-
246
- :param pr_data: The pull request data dictionary.
247
- :return: A list of related issue numbers.
244
+ Extracts related issue numbers from all PR data following GitHub's reference syntax.
245
+
246
+ This function implements GitHub's official autolink reference formats to find:
247
+ 1. Full GitHub issue/PR URLs
248
+ 2. Numeric references (#123)
249
+ 3. Keywords + issue references (fixes #123)
250
+ 4. Repository cross-references (owner/repo#123)
251
+
252
+ See: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls
253
+
254
+ Args:
255
+ pr_data: Dict[str, Any] - The complete pull request data dictionary
256
+
257
+ Returns:
258
+ List[int] - A sorted list of unique issue numbers found in the PR data
248
259
  """
260
+ # GitHub's official closing keywords
261
+ closing_keywords = (
262
+ 'close', 'closes', 'closed',
263
+ 'fix', 'fixes', 'fixed',
264
+ 'resolve', 'resolves', 'resolved'
265
+ )
266
+
267
+ # Regex patterns for GitHub issue references
249
268
  patterns = [
250
- rf'https://github\.com/{re.escape(self.full_name)}/issues/(\d+)',
251
- r'(?:^|\s)#(\d+)',
252
- r'(?:^|\s)(\d+)(?:\s|$)',
269
+ # Full GitHub issue/PR URL pattern
270
+ rf'(?:https?://)?github\.com/{re.escape(self.full_name)}/(?:issues|pull)/(\d+)',
271
+
272
+ # Standard #123 reference with proper boundaries
273
+ r'(?:^|[^\w/])#(\d+)(?=[^\w/]|$)',
274
+
275
+ # Closing keywords (fixes #123)
276
+ fr'(?:^|[^\w/])(?:{"|".join(closing_keywords)}):?\s+#(\d+)(?=[^\w/]|$)',
277
+
278
+ # Cross-repo reference (owner/repo#123)
279
+ rf'{re.escape(self.full_name)}#(\d+)',
280
+
281
+ # Issue keyword reference (issue #123 or issue: #123)
282
+ r'(?:^|[^\w/])(?:issue|bug|ticket|todo|task)s?:?\s+#?(\d+)(?=[^\w/]|$)'
253
283
  ]
284
+
254
285
  issues = set()
255
- # Convert PR data to JSON string for pattern matching
256
- pr_description = json.dumps(pr_data, default=str)
257
286
 
258
- for pattern in patterns:
259
- matches = re.findall(pattern, pr_description)
260
- issues.update(int(match) for match in matches)
287
+ def extract_from_text(text: str) -> None:
288
+ """Helper function to extract issue numbers from text"""
289
+ if not isinstance(text, str):
290
+ return
291
+
292
+ for pattern in patterns:
293
+ matches = re.findall(pattern, text, re.IGNORECASE | re.MULTILINE)
294
+ # Validate issue numbers (reasonable length and positive values)
295
+ valid_matches = [
296
+ int(match) for match in matches
297
+ if match.isdigit() and len(match) <= 7 and int(match) > 0
298
+ ]
299
+ issues.update(valid_matches)
300
+
301
+ def process_value(value: Any) -> None:
302
+ """Recursively process dictionary values and extract issue numbers"""
303
+ if isinstance(value, dict):
304
+ for v in value.values():
305
+ process_value(v)
306
+ elif isinstance(value, (list, tuple)):
307
+ for item in value:
308
+ process_value(item)
309
+ elif isinstance(value, str):
310
+ extract_from_text(value)
311
+
312
+ # Process all data in pr_data recursively
313
+ process_value(pr_data)
261
314
 
262
- return list(issues)
315
+ return sorted(list(issues))
316
+
263
317
 
264
318
  def get_issue_contents(self, issue_numbers: List[int], pr_number: int) -> List[Dict[str, Any]]:
265
319
  """
@@ -324,11 +378,34 @@ class Repository:
324
378
  "head_branch": pr.head.ref,
325
379
  },
326
380
  "related_issues": [],
381
+ "commits": [],
327
382
  "file_changes": [],
328
383
  "ci_cd_results": [],
329
384
  "interactions": []
330
385
  }
331
386
 
387
+ # Fetch and process commits
388
+ try:
389
+ commits = pr.get_commits()
390
+ for commit in commits:
391
+ commit_data = {
392
+ "sha": commit.sha,
393
+ "message": commit.commit.message,
394
+ "author": commit.commit.author.name,
395
+ "date": self.to_isoformat(commit.commit.author.date),
396
+ "stats": {
397
+ "additions": commit.stats.additions,
398
+ "deletions": commit.stats.deletions,
399
+ "total": commit.stats.total
400
+ },
401
+ "files": [f.filename for f in commit.files] # Just keep changed file names
402
+ }
403
+ pr_data["commits"].append(commit_data)
404
+ except GithubException as e:
405
+ logger.exception(f"Error fetching commits for PR #{number}")
406
+ pr_data["commits"] = []
407
+ pr_data["commit_stats"] = {}
408
+
332
409
  # Fetch CI/CD results
333
410
  try:
334
411
  last_commit = pr.get_commits().reversed[0]
@@ -8,6 +8,11 @@ from llama_github.config.config import config
8
8
  from llama_github.logger import logger
9
9
 
10
10
  class LLMManager:
11
+ """
12
+ Singleton class for managing Language Models and related components.
13
+ This class handles initialization and access to various models including LLMs,
14
+ embedding models, and reranking models.
15
+ """
11
16
  _instance_lock = Lock()
12
17
  _instance = None
13
18
  llm = None
@@ -18,6 +23,9 @@ class LLMManager:
18
23
  embedding_model = None
19
24
 
20
25
  def __new__(cls, *args, **kwargs):
26
+ """
27
+ Ensure only one instance of LLMManager is created (Singleton pattern).
28
+ """
21
29
  if cls._instance is None: # First check (unlocked)
22
30
  with cls._instance_lock: # Acquire lock
23
31
  if cls._instance is None: # Second check (locked)
@@ -34,6 +42,19 @@ class LLMManager:
34
42
  rerank_model: Optional[str] = config.get("default_reranker"),
35
43
  llm: Any = None,
36
44
  simple_mode: bool = False):
45
+ """
46
+ Initialize the LLMManager with specified models and API keys.
47
+
48
+ Args:
49
+ openai_api_key (Optional[str]): API key for OpenAI.
50
+ mistral_api_key (Optional[str]): API key for Mistral AI.
51
+ huggingface_token (Optional[str]): Token for Hugging Face.
52
+ open_source_models_hg_dir (Optional[str]): Directory for open-source models.
53
+ embedding_model (Optional[str]): Name or path of the embedding model.
54
+ rerank_model (Optional[str]): Name or path of the reranking model.
55
+ llm (Any): Custom LLM instance if provided.
56
+ simple_mode (bool): If True, skip initialization of embedding and reranking models.
57
+ """
37
58
  with self._instance_lock: # Prevent re-initialization
38
59
  if self._initialized:
39
60
  return
@@ -41,7 +62,7 @@ class LLMManager:
41
62
 
42
63
  self.simple_mode = simple_mode
43
64
 
44
- # Initialize for OpenAI GPT-4
65
+ # Initialize LLM based on provided API keys or custom LLM
45
66
  if llm is not None:
46
67
  self.llm = llm
47
68
  self.model_type = "Custom_langchain_llm"
@@ -59,33 +80,47 @@ class LLMManager:
59
80
  # Initialize for Open Source Models
60
81
  elif open_source_models_hg_dir is not None and open_source_models_hg_dir != "" and self.llm is None:
61
82
  logger.info(f"Initializing {open_source_models_hg_dir}...")
62
- # load hugingface models
83
+ # load huggingface models
63
84
  self.model_type = "Hubgingface"
64
85
  elif self.llm is None:
65
86
  # default model is phi3_mini_128k
66
87
  self.model_type = "Hubgingface"
67
88
 
68
89
  if not self.simple_mode:
69
- import torch
90
+ import sys
91
+ import platform
92
+ import subprocess
93
+
94
+ def get_device():
95
+ if sys.platform.startswith('darwin'): # macOS
96
+ # Check for Apple Silicon (M1/M2)
97
+ if platform.machine() == 'arm64':
98
+ return 'mps'
99
+ elif sys.platform.startswith('linux') or sys.platform.startswith('win'):
100
+ # Check for NVIDIA GPU
101
+ try:
102
+ subprocess.run(['nvidia-smi'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
103
+ return 'cuda'
104
+ except (subprocess.CalledProcessError, FileNotFoundError):
105
+ pass
106
+
107
+ # Default to CPU
108
+ return 'cpu'
109
+
110
+ # Usage
111
+ self.device = get_device()
112
+
70
113
  from transformers import AutoModel
71
114
  from transformers import AutoModelForSequenceClassification
72
115
  from transformers import AutoTokenizer
73
- # initial model_kwargs
74
- if torch.cuda.is_available():
75
- self.device = torch.device('cuda')
76
- elif torch.backends.mps.is_available():
77
- self.device = torch.device('mps')
78
- else:
79
- self.device = torch.device('cpu')
80
-
81
- # initial embedding_model
116
+ # Initialize embedding model
82
117
  if self.tokenizer is None:
83
118
  logger.info(f"Initializing {embedding_model}...")
84
119
  self.tokenizer = AutoTokenizer.from_pretrained(embedding_model)
85
120
  self.embedding_model = AutoModel.from_pretrained(
86
121
  embedding_model, trust_remote_code=True).to(self.device)
87
122
 
88
- # initial rerank_model
123
+ # Initialize reranking model
89
124
  if self.rerank_model is None:
90
125
  logger.info(f"Initializing {rerank_model}...")
91
126
  self.rerank_model = AutoModelForSequenceClassification.from_pretrained(
@@ -95,16 +130,46 @@ class LLMManager:
95
130
  logger.info("Simple mode enabled. Skipping embedding and rerank model initialization.")
96
131
 
97
132
  def get_llm(self):
133
+ """
134
+ Get the main Language Model.
135
+
136
+ Returns:
137
+ The initialized Language Model.
138
+ """
98
139
  return self.llm
99
140
 
100
141
  def get_llm_simple(self):
142
+ """
143
+ Get the simplified Language Model.
144
+
145
+ Returns:
146
+ The initialized simplified Language Model.
147
+ """
101
148
  return self.llm_simple
102
149
 
103
150
  def get_tokenizer(self):
151
+ """
152
+ Get the tokenizer for the embedding model.
153
+
154
+ Returns:
155
+ The initialized tokenizer.
156
+ """
104
157
  return self.tokenizer
105
158
 
106
159
  def get_rerank_model(self):
160
+ """
161
+ Get the reranking model.
162
+
163
+ Returns:
164
+ The initialized reranking model.
165
+ """
107
166
  return self.rerank_model
108
167
 
109
168
  def get_embedding_model(self):
169
+ """
170
+ Get the embedding model.
171
+
172
+ Returns:
173
+ The initialized embedding model.
174
+ """
110
175
  return self.embedding_model
@@ -0,0 +1 @@
1
+ __version__ = '0.1.6'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-github
3
- Version: 0.1.5
3
+ Version: 0.1.6
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
@@ -19,9 +19,11 @@ Requires-Dist: langchain
19
19
  Requires-Dist: numpy
20
20
  Requires-Dist: pydantic
21
21
  Requires-Dist: requests
22
- Requires-Dist: torch
23
22
  Requires-Dist: transformers
24
23
  Requires-Dist: urllib3
24
+ Requires-Dist: sys
25
+ Requires-Dist: platform
26
+ Requires-Dist: subprocess
25
27
  Requires-Dist: pydantic_core
26
28
  Requires-Dist: langchain_openai
27
29
  Requires-Dist: langchain_mistralai
@@ -138,6 +140,18 @@ All notable changes to this project will be documented in this file.
138
140
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
139
141
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
140
142
 
143
+ ## [0.1.6] - 2024-10-30
144
+
145
+ ### New Features
146
+ - Enhanced PR content analysis with detailed commit information extraction
147
+ - Improved issue linking detection with support for multiple reference formats
148
+ - Full GitHub URLs, #references, and keyword-based references
149
+ - Added validation for issue numbers
150
+
151
+ ### Improvements
152
+ - Added detailed commit metadata extraction including stats and file changes
153
+ - Enhanced error handling for commit fetching
154
+
141
155
  ## [0.1.5] - 2024-10-14
142
156
 
143
157
  ### Optimized
@@ -6,9 +6,11 @@ langchain
6
6
  numpy
7
7
  pydantic
8
8
  requests
9
- torch
10
9
  transformers
11
10
  urllib3
11
+ sys
12
+ platform
13
+ subprocess
12
14
  pydantic_core
13
15
  langchain_openai
14
16
  langchain_mistralai
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = llama-github
3
- version = 0.1.5
3
+ version = 0.1.6
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.
@@ -1 +0,0 @@
1
- __version__ = '0.1.5'
File without changes
File without changes
File without changes
File without changes