GitHub
GitHub仓库协作者读取器 #
基类:EventBaseReader
GitHub 仓库协作者读取器。
获取 GitHub 仓库的协作者列表并返回文档列表。
示例:
>>> reader = GitHubRepositoryCollaboratorsReader("owner", "repo")
>>> colabs = reader.load_data()
>>> print(colabs)
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/base.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
过滤器类型 #
基类:EventEnum
筛选类型。
用于确定过滤器是包含性还是排除性的。
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/base.py
55 56 57 58 59 60 61 62 63 | |
load_data #
load_data() -> List[文档]
GitHub 仓库协作者读取器。
获取 GitHub 仓库中的协作者列表并将其转换为文档。
每个协作者通过以下步骤被转换为文档:
- The text of the document is the login.
- The title of the document is also the login.
- The extra_info of the document is a dictionary with the following keys:
- login: str, the login of the user
- type: str, the type of user e.g. "User"
- site_admin: bool, whether the user has admin permissions
- role_name: str, e.g. "admin"
- name: str, the name of the user, if available
- email: str, the email of the user, if available
- permissions: str, the permissions of the user, if available
:return: 文档列表
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/base.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
GitHub协作客户端 #
一个用于与GitHub协作者API交互的异步客户端。
客户端支持两种认证方式: 1. 个人访问令牌 (PAT) - 通过 github_token 参数或 GITHUB_TOKEN 环境变量传递 2. GitHub 应用 - 通过 github_app_auth 参数传递
示例:
>>> # Using Personal Access Token
>>> client = GitHubCollaboratorsClient("my_github_token")
>>> collaborators = client.get_collaborators("owner", "repo")
>>>
>>> # Using GitHub App
>>> from llama_index.readers.github.github_app_auth import GitHubAppAuth
>>> app_auth = GitHubAppAuth(app_id="123", private_key=key, installation_id="456")
>>> client = GitHubCollaboratorsClient(github_app_auth=app_auth)
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/github_client.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
get_all_endpoints #
get_all_endpoints() -> Dict[str, str]
获取所有可用的端点。
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/github_client.py
132 133 134 | |
请求
async
#
request(endpoint: str, method: str, headers: Dict[str, Any] = {}, params: Dict[str, Any] = {}, **kwargs: Any) -> Any
向 GitHub API 发起 API 请求。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `endpoint (str)`
|
要发送请求的端点名称。 |
required | |
- `method (str)`
|
用于请求的HTTP方法。 |
required | |
- `headers (dict)`
|
请求中包含的HTTP头部信息。 |
required | |
- `**kwargs`
|
传递给端点 URL 的关键字参数。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Any
|
|
引发:
| 类型 | 描述 |
|---|---|
-ImportError
|
如果未安装 |
-HTTPError
|
如果API请求失败。 |
示例:
>>> response = client.request("getCollaborators", "GET",
owner="owner", repo="repo", state="all")
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/github_client.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
get_collaborators
async
#
get_collaborators(owner: str, repo: str, page: int = 1) -> Dict
列出仓库中的协作者。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `owner (str)`
|
仓库所有者。 |
required | |
- `repo (str)`
|
仓库名称。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Dict
|
|
示例:
>>> repo_collaborators = client.get_collaborators("owner", "repo")
workflows/handler.py 中的源代码llama_index/readers/github/collaborators/github_client.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
GitHub问题客户端 #
一个用于与GitHub问题API交互的异步客户端。
客户端支持两种认证方式: 1. 个人访问令牌 (PAT) - 通过 github_token 参数或 GITHUB_TOKEN 环境变量传递 2. GitHub 应用 - 通过 github_app_auth 参数传递
示例:
>>> # Using Personal Access Token
>>> client = GitHubIssuesClient("my_github_token")
>>> issues = client.get_issues("owner", "repo")
>>>
>>> # Using GitHub App
>>> from llama_index.readers.github.github_app_auth import GitHubAppAuth
>>> app_auth = GitHubAppAuth(app_id="123", private_key=key, installation_id="456")
>>> client = GitHubIssuesClient(github_app_auth=app_auth)
workflows/handler.py 中的源代码llama_index/readers/github/issues/github_client.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
get_all_endpoints #
get_all_endpoints() -> Dict[str, str]
获取所有可用的端点。
workflows/handler.py 中的源代码llama_index/readers/github/issues/github_client.py
133 134 135 | |
请求
async
#
request(endpoint: str, method: str, headers: Dict[str, Any] = {}, params: Dict[str, Any] = {}, **kwargs: Any) -> Any
向 GitHub API 发起 API 请求。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `endpoint (str)`
|
要向其发出请求的端点名称。 |
required | |
- `method (str)`
|
用于请求的HTTP方法。 |
required | |
- `headers (dict)`
|
请求中包含的HTTP头部信息。 |
required | |
- `**kwargs`
|
传递给端点 URL 的关键字参数。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Any
|
|
引发:
| 类型 | 描述 |
|---|---|
-ImportError
|
如果未安装 |
-HTTPError
|
如果API请求失败。 |
示例:
>>> response = client.request("getIssues", "GET",
owner="owner", repo="repo", state="all")
workflows/handler.py 中的源代码llama_index/readers/github/issues/github_client.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
get_issues
async
#
get_issues(owner: str, repo: str, state: str = 'open', page: int = 1) -> Dict
列出仓库中的问题。
注意:GitHub的REST API将每个拉取请求都视为一个问题,但并非每个问题都是拉取请求。 因此,“问题”接口可能在响应中同时返回问题和拉取请求。 您可以通过pull_request键来识别拉取请求。 请注意,从“问题”接口返回的拉取请求ID将是一个问题ID。 要查找拉取请求ID,请使用“列出拉取请求”接口。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `owner (str)`
|
仓库所有者。 |
required | |
- `repo (str)`
|
仓库名称。 |
required | |
- `state (str)`
|
表示要返回的问题状态。 默认值:open 可选值:open, closed, all。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Dict
|
|
示例:
>>> repo_issues = client.get_issues("owner", "repo")
workflows/handler.py 中的源代码llama_index/readers/github/issues/github_client.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
GitHub仓库问题读取器 #
基类:EventBaseReader
GitHub 仓库问题读取器。
获取 GitHub 仓库的问题列表并返回文档列表。
示例:
>>> reader = GitHubRepositoryIssuesReader("owner", "repo")
>>> issues = reader.load_data()
>>> print(issues)
workflows/handler.py 中的源代码llama_index/readers/github/issues/base.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
问题状态 #
基类:EventEnum
问题类型。
用于决定检索哪些问题。
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
- |
OPEN
|
只需开启问题。这是默认设置。 |
- |
CLOSED
|
刚刚关闭了问题。 |
- |
ALL
|
所有问题,包括已打开和已关闭的。 |
workflows/handler.py 中的源代码llama_index/readers/github/issues/base.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
过滤器类型 #
基类:EventEnum
筛选类型。
用于确定过滤器是包含性还是排除性的。
workflows/handler.py 中的源代码llama_index/readers/github/issues/base.py
73 74 75 76 77 78 79 80 81 | |
load_data #
load_data(state: Optional[IssueState] = OPEN, labelFilters: Optional[List[Tuple[str, FilterType]]] = None) -> List[文档]
从代码仓库加载问题并将其转换为文档。
每个问题通过以下步骤转换为文档:
- 文档文本由问题标题和正文内容拼接而成。
- 文档标题即为议题标题。
- 文档的 doc_id 即为问题编号。
- 文档的 extra_info 是一个包含以下键的字典:
- state: 议题的状态。
- created_at: 议题创建的日期。
- closed_at: 议题关闭的日期。仅当议题已关闭时存在。
- url: 议题的URL地址。
- assignee: 被分配处理该议题的用户的登录名。仅当议题已分配时存在。
- 文档的嵌入为 None。
- 文档的 doc_hash 为 None。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- state
|
IssueState
|
要检索的问题状态。默认为 IssueState.OPEN。 |
required |
- labelFilters
|
一个可选的筛选器列表,用于根据标签对问题列表进行筛选。 |
required |
:return: 文档列表
workflows/handler.py 中的源代码llama_index/readers/github/issues/base.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
Github客户端 #
一个用于与Github API交互的异步客户端。
此客户端用于向Github发起API请求。 它提供了访问Github API端点的方法。 该客户端支持两种认证方式: 1. 个人访问令牌(PAT)- 通过github_token参数或GITHUB_TOKEN环境变量传递 2. GitHub应用 - 通过github_app_auth参数传递
示例:
>>> # Using Personal Access Token
>>> client = GithubClient("my_github_token")
>>> branch_info = client.get_branch("owner", "repo", "branch")
>>>
>>> # Using GitHub App
>>> from llama_index.readers.github.github_app_auth import GitHubAppAuth
>>> with open("private-key.pem", "r") as f:
... private_key = f.read()
>>> app_auth = GitHubAppAuth(
... app_id="123456",
... private_key=private_key,
... installation_id="789012"
... )
>>> client = GithubClient(github_app_auth=app_auth)
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
get_all_endpoints #
get_all_endpoints() -> Dict[str, str]
获取所有可用的端点。
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
321 322 323 | |
请求
async
#
request(endpoint: str, method: str, headers: Dict[str, Any] = {}, timeout: Optional[int] = 5, retries: int = 0, **kwargs: Any) -> Any
向 Github API 发起 API 请求。
此方法用于向 Github API 发起 API 请求。 它在客户端内部被其他方法调用。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `endpoint (str)`
|
要向其发出请求的端点名称。 |
required | |
- `method (str)`
|
用于请求的HTTP方法。 |
required | |
- `headers (dict)`
|
请求中包含的HTTP头部信息。 |
required | |
- `timeout (int or None)`
|
请求超时时间,单位为秒。默认值为5。 |
required | |
- `retries (int)`
|
请求的重试次数。默认值为0。 |
required | |
- `**kwargs`
|
传递给端点 URL 的关键字参数。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Any
|
|
引发:
| 类型 | 描述 |
|---|---|
-ImportError
|
如果未安装 |
-HTTPError
|
如果API请求失败且 fail_on_http_error 为 True。 |
示例:
>>> response = client.request("getTree", "GET",
owner="owner", repo="repo",
tree_sha="tree_sha", timeout=5, retries=0)
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
get_branch
async
#
get_branch(owner: str, repo: str, branch: Optional[str] = None, branch_name: Optional[str] = None, timeout: Optional[int] = 5, retries: int = 0) -> GitBranchResponseModel
获取分支信息。(Github API 接口:getBranch)。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `owner (str)`
|
仓库所有者。 |
required | |
- `repo (str)`
|
仓库名称。 |
required | |
- `branch (str)`
|
分支名称。 |
required | |
- `branch_name (str)`
|
分支名称(替代 |
required | |
- `timeout (int or None)`
|
请求超时时间,单位为秒。默认值为5。 |
required | |
- `retries (int)`
|
请求的重试次数。默认值为0。 |
required |
返回:
| 类型 | 描述 |
|---|---|
GitBranchResponseModel
|
|
示例:
>>> branch_info = client.get_branch("owner", "repo", "branch")
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
get_tree
async
#
get_tree(owner: str, repo: str, tree_sha: str, timeout: Optional[int] = 5, retries: int = 0) -> GitTreeResponseModel
获取关于树的信息。(GitHub API 端点:getTree)。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `owner (str)`
|
仓库所有者。 |
required | |
- `repo (str)`
|
仓库名称。 |
required | |
- `tree_sha (str)`
|
树的 SHA 值。 |
required | |
- `timeout (int or None)`
|
请求超时时间,单位为秒。默认值为5。 |
required | |
- `retries (int)`
|
请求的重试次数。默认值为0。 |
required |
返回:
| 类型 | 描述 |
|---|---|
GitTreeResponseModel
|
|
示例:
>>> tree_info = client.get_tree("owner", "repo", "tree_sha")
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
get_blob
async
#
get_blob(owner: str, repo: str, file_sha: str, timeout: Optional[int] = 5, retries: int = 0) -> Optional[GitBlobResponseModel]
获取关于blob的信息。(Github API接口:getBlob)。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `owner (str)`
|
仓库所有者。 |
required | |
- `repo (str)`
|
仓库名称。 |
required | |
- `file_sha (str)`
|
文件的SHA值。 |
required | |
- `timeout (int or None)`
|
请求超时时间,单位为秒。默认值为5。 |
required | |
- `retries (int)`
|
请求的重试次数。默认值为0。 |
required |
返回:
| 类型 | 描述 |
|---|---|
Optional[GitBlobResponseModel]
|
|
示例:
>>> blob_info = client.get_blob("owner", "repo", "file_sha")
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | |
get_commit
async
#
get_commit(owner: str, repo: str, commit_sha: str, timeout: Optional[int] = 5, retries: int = 0) -> GitCommitResponseModel
获取关于某次提交的信息。(Github API 接口:getCommit)。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
- `owner (str)`
|
仓库所有者。 |
required | |
- `repo (str)`
|
仓库名称。 |
required | |
- `commit_sha (str)`
|
提交的SHA值。 |
required | |
- `timeout (int or None)`
|
请求超时时间,单位为秒。默认值为5。 |
required | |
- `retries (int)`
|
请求的重试次数。默认值为0。 |
required |
返回:
| 类型 | 描述 |
|---|---|
GitCommitResponseModel
|
|
示例:
>>> commit_info = client.get_commit("owner", "repo", "commit_sha")
workflows/handler.py 中的源代码llama_index/readers/github/repository/github_client.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
GitHub仓库读取器 #
基类:EventBaseReader
GitHub 仓库读取器。
获取Github仓库的内容并返回文档列表。 这些文档要么是仓库中文件的内容,要么是 使用解析器从文件中提取的文本。
示例:
>>> from llama_index.core.instrumentation import get_dispatcher
>>> from llama_index.core.instrumentation.event_handlers import BaseEventHandler
>>>
>>> # Set up event handler
>>> class GitHubEventHandler(BaseEventHandler):
... def handle(self, event):
... if isinstance(event, GitHubFileProcessedEvent):
... print(f"Processed file: {event.file_path}")
...
>>> dispatcher = get_dispatcher()
>>> handler = GitHubEventHandler()
>>> dispatcher.add_event_handler(handler)
>>>
>>> client = github_client = GithubClient(
... github_token=os.environ["GITHUB_TOKEN"],
... verbose=True
... )
>>> reader = GithubRepositoryReader(
... github_client=github_client,
... owner="run-llama",
... repo="llama_index",
... )
>>> # Load all files from a branch
>>> branch_documents = reader.load_data(branch="main")
>>> # Load all files from a commit
>>> commit_documents = reader.load_data(commit_sha="commit_sha")
workflows/handler.py 中的源代码llama_index/readers/github/repository/base.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | |
过滤器类型 #
基类:EventEnum
筛选类型。
用于确定过滤器是包含性还是排除性的。
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
- |
EXCLUDE
|
排除指定目录中或具有指定扩展名的文件。 |
- |
INCLUDE
|
仅包含指定目录中或具有指定扩展名的文件。 |
workflows/handler.py 中的源代码llama_index/readers/github/repository/base.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
load_data #
load_data(commit_sha: Optional[str] = None, branch: Optional[str] = None, file_path: Optional[str] = None) -> List[文档]
从提交或分支加载数据。
从特定的提交 SHA 或分支加载 GitHub 仓库数据。
:param commit_sha: 提交哈希值
:param branch: 分支名称
:param file_path: 仓库中特定文件的完整路径
:return: 文档列表
workflows/handler.py 中的源代码llama_index/readers/github/repository/base.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
GitHub应用认证 #
GitHub 应用认证处理器。
该类通过生成JWT并获取/缓存安装访问令牌来管理GitHub应用程序的身份验证。令牌在过期时会自动刷新。
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
app_id |
str
|
GitHub 应用 ID。 |
private_key |
str
|
GitHub 应用的私钥(PEM 格式)。 |
installation_id |
str
|
GitHub 应用的安装ID。 |
示例:
>>> # Read private key from file
>>> with open("private-key.pem", "r") as f:
... private_key = f.read()
>>>
>>> # Create auth handler
>>> auth = GitHubAppAuth(
... app_id="123456",
... private_key=private_key,
... installation_id="789012"
... )
>>>
>>> # Get installation token (cached and auto-refreshed)
>>> import asyncio
>>> token = asyncio.run(auth.get_installation_token())
workflows/handler.py 中的源代码llama_index/readers/github/github_app_auth.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
get_installation_token
async
#
get_installation_token(force_refresh: bool = False) -> str
获取或刷新安装访问令牌。
如果缓存的令牌仍然有效,此方法将返回缓存的令牌;如果缓存的令牌已过期或即将过期,则向GitHub请求新令牌。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
force_refresh
|
bool
|
如果为True,即使缓存的令牌仍然有效,也会强制刷新令牌。 |
False
|
返回:
| 类型 | 描述 |
|---|---|
str
|
一个有效的安装访问令牌。 |
引发:
| 类型 | 描述 |
|---|---|
GitHubAppAuthenticationError
|
如果令牌检索失败。 |
ImportError
|
如果未安装httpx。 |
workflows/handler.py 中的源代码llama_index/readers/github/github_app_auth.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
invalidate_token #
invalidate_token() -> None
使缓存的令牌失效。
这会强制下一次调用 get_installation_token() 时获取新的令牌。 如果您知道令牌已被撤销或不再有效,这将非常有用。
workflows/handler.py 中的源代码llama_index/readers/github/github_app_auth.py
208 209 210 211 212 213 214 215 216 217 | |
GitHub应用认证错误 #
基类:EventException
当 GitHub 应用认证失败时触发。
workflows/handler.py 中的源代码llama_index/readers/github/github_app_auth.py
18 19 | |
选项: 成员:- GitHubRepositoryCollaboratorsReader - GitHubRepositoryIssuesReader - GithubRepositoryReader