
    dh<                        S r SSKJrJr  SSKJr  SSKJr  SSKJ	r	J
r
  SSKJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"  SSK#J$r$  SSK%J&r&   " S	 S
\	5      r' " S S\	5      r( " S S\	5      r) " S S\	5      r* " S S\	5      r+ " S S\	5      r, " S S\	5      r- " S S\	5      r. " S S\	5      r/ " S S\	5      r0 " S S\	5      r1 " S S \	5      r2 " S! S"\	5      r3 " S# S$\	5      r4 " S% S&\	5      r5 " S' S(\5      r6g))*zGitHub Toolkit.    )DictList)BaseTool)BaseToolkit)	BaseModelField)COMMENT_ON_ISSUE_PROMPTCREATE_BRANCH_PROMPTCREATE_FILE_PROMPTCREATE_PULL_REQUEST_PROMPTCREATE_REVIEW_REQUEST_PROMPTDELETE_FILE_PROMPTGET_FILES_FROM_DIRECTORY_PROMPTGET_ISSUE_PROMPTGET_ISSUES_PROMPTGET_LATEST_RELEASE_PROMPTGET_PR_PROMPTGET_RELEASE_PROMPTGET_RELEASES_PROMPTLIST_BRANCHES_IN_REPO_PROMPTLIST_PRS_PROMPTLIST_PULL_REQUEST_FILES"OVERVIEW_EXISTING_FILES_BOT_BRANCHOVERVIEW_EXISTING_FILES_IN_MAINREAD_FILE_PROMPTSEARCH_CODE_PROMPTSEARCH_ISSUES_AND_PRS_PROMPTSET_ACTIVE_BRANCH_PROMPTUPDATE_FILE_PROMPT)GitHubAction)GitHubAPIWrapperc                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	NoInput&   z4Schema for operations that do not require any input. z*No input required, e.g. `` (empty string).descriptionno_input N)
__name__
__module____qualname____firstlineno____doc__r   r(   str__annotations____static_attributes__r)       i/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/agent_toolkits/github/toolkit.pyr#   r#   &   s    >"*VWHcWr2   r#   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	GetIssue,   z<Schema for operations that require an issue number as input.r   z%Issue number as an integer, e.g. `42`r&   issue_numberr)   N)
r*   r+   r,   r-   r.   r   r7   intr0   r1   r)   r2   r3   r5   r5   ,   s    Fa-TUL#Ur2   r5   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	CommentOnIssue2   z6Schema for operations that require a comment as input..Follow the required formatting.r&   inputr)   N
r*   r+   r,   r-   r.   r   r=   r/   r0   r1   r)   r2   r3   r:   r:   2   s    @s(IJE3Jr2   r:   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	GetPR8   z8Schema for operations that require a PR number as input.r   z&The PR number as an integer, e.g. `12`r&   	pr_numberr)   N)
r*   r+   r,   r-   r.   r   rB   r8   r0   r1   r)   r2   r3   r@   r@   8   s    B1*RSIsSr2   r@   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	CreatePR>   z@Schema for operations that require a PR title and body as input..r<   r&   formatted_prr)   N)
r*   r+   r,   r-   r.   r   rF   r/   r0   r1   r)   r2   r3   rD   rD   >   s    Jc/PQL#Qr2   rD   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	
CreateFileD   DSchema for operations that require a file path and content as input..r<   r&   formatted_filer)   N)
r*   r+   r,   r-   r.   r   rK   r/   r0   r1   r)   r2   r3   rH   rH   D   s    N1RSNCSr2   rH   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	ReadFileJ   8Schema for operations that require a file path as input..z}The full file path of the file you would like to read where the path must NOT start with a slash, e.g. `some_dir/my_file.py`.r&   formatted_filepathr)   N
r*   r+   r,   r-   r.   r   rP   r/   r0   r1   r)   r2   r3   rM   rM   J   s     B#L r2   rM   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	
UpdateFileV   rJ   .z#Strictly follow the provided rules.r&   formatted_file_updater)   N)
r*   r+   r,   r-   r.   r   rU   r/   r0   r1   r)   r2   r3   rS   rS   V   s    N!&>"3 r2   rS   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	
DeleteFile^   rO   .zThe full file path of the file you would like to delete where the path must NOT start with a slash, e.g. `some_dir/my_file.py`. Only input a string, not the param name.r&   rP   r)   NrQ   r)   r2   r3   rW   rW   ^   s    B## r2   rW   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	DirectoryPathl   z=Schema for operations that require a directory path as input.r%   zmThe path of the directory, e.g. `some_dir/inner_dir`. Only input a string, do not include the parameter name.r&   r=   r)   Nr>   r)   r2   r3   rZ   rZ   l   s    G
GE3 r2   rZ   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	
BranchNamex   z:Schema for operations that require a branch name as input..z)The name of the branch, e.g. `my_branch`.r&   branch_namer)   N)
r*   r+   r,   r-   r.   r   r_   r/   r0   r1   r)   r2   r3   r]   r]   x   s    DDK r2   r]   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	
SearchCode   ;Schema for operations that require a search query as input..zQA keyword-focused natural language searchquery for code, e.g. `MyFunctionName()`.r&   search_queryr)   N
r*   r+   r,   r-   r.   r   rd   r/   r0   r1   r)   r2   r3   ra   ra      s    E7L# r2   ra   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	CreateReviewRequest   z7Schema for operations that require a username as input..z@GitHub username of the user being requested, e.g. `my_username`.r&   usernamer)   N)
r*   r+   r,   r-   r.   r   ri   r/   r0   r1   r)   r2   r3   rg   rg      s    AVHc r2   rg   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	SearchIssuesAndPRs   rc   .z>Natural language search query, e.g. `My issue title or topic`.r&   rd   r)   Nre   r)   r2   r3   rk   rk      s    ETL# r2   rk   c                   2    \ rS rSr% Sr\" SSS9r\\S'   Sr	g)	TagName   z7Schema for operations that require a tag name as input..z+The tag name of the release, e.g. `v1.0.0`.r&   tag_namer)   N)
r*   r+   r,   r-   r.   r   rp   r/   r0   r1   r)   r2   r3   rn   rn      s    AAHc r2   rn   c                   h    \ rS rSr% Sr/ r\\   \S'   \	 SS\
S\SS 4S jj5       rS\\   4S jrS	rg
)GitHubToolkit   a  GitHub Toolkit.

*Security Note*: This toolkit contains tools that can read and modify
    the state of a service; e.g., by creating, deleting, or updating,
    reading underlying data.

    For example, this toolkit can be used to create issues, pull requests,
    and comments on GitHub.

    See [Security](https://python.langchain.com/docs/security) for more information.

Setup:
    See detailed installation instructions here:
    https://python.langchain.com/docs/integrations/tools/github/#installation

    You will need to install ``pygithub`` and set the following environment
    variables:

    .. code-block:: bash

        pip install -U pygithub
        export GITHUB_APP_ID="your-app-id"
        export GITHUB_APP_PRIVATE_KEY="path-to-private-key"
        export GITHUB_REPOSITORY="your-github-repository"

Instantiate:
    .. code-block:: python

        from langchain_community.agent_toolkits.github.toolkit import GitHubToolkit
        from langchain_community.utilities.github import GitHubAPIWrapper

        github = GitHubAPIWrapper()
        toolkit = GitHubToolkit.from_github_api_wrapper(github)

Tools:
    .. code-block:: python

        tools = toolkit.get_tools()
        for tool in tools:
            print(tool.name)

    .. code-block:: none

        Get Issues
        Get Issue
        Comment on Issue
        List open pull requests (PRs)
        Get Pull Request
        Overview of files included in PR
        Create Pull Request
        List Pull Requests' Files
        Create File
        Read File
        Update File
        Delete File
        Overview of existing files in Main branch
        Overview of files in current working branch
        List branches in this repository
        Set active branch
        Create a new branch
        Get files from a directory
        Search issues and pull requests
        Search code
        Create review request

Include release tools:
    By default, the toolkit does not include release-related tools.
    You can include them by setting ``include_release_tools=True`` when
    initializing the toolkit:

    .. code-block:: python

        toolkit = GitHubToolkit.from_github_api_wrapper(
            github, include_release_tools=True
        )

    Setting ``include_release_tools=True`` will include the following tools:

    .. code-block:: none

        Get latest release
        Get releases
        Get release

Use within an agent:
    .. code-block:: python

        from langchain_openai import ChatOpenAI
        from langgraph.prebuilt import create_react_agent

        # Select example tool
        tools = [tool for tool in toolkit.get_tools() if tool.name == "Get Issue"]
        assert len(tools) == 1
        tools[0].name = "get_issue"

        llm = ChatOpenAI(model="gpt-4o-mini")
        agent_executor = create_react_agent(llm, tools)

        example_query = "What is the title of issue 24888?"

        events = agent_executor.stream(
            {"messages": [("user", example_query)]},
            stream_mode="values",
        )
        for event in events:
            event["messages"][-1].pretty_print()

    .. code-block:: none

         ================================[1m Human Message [0m=================================

        What is the title of issue 24888?
        ==================================[1m Ai Message [0m==================================
        Tool Calls:
        get_issue (call_iSYJVaM7uchfNHOMJoVPQsOi)
        Call ID: call_iSYJVaM7uchfNHOMJoVPQsOi
        Args:
            issue_number: 24888
        =================================[1m Tool Message [0m=================================
        Name: get_issue

        {"number": 24888, "title": "Standardize KV-Store Docs", "body": "..."
        ==================================[1m Ai Message [0m==================================

        The title of issue 24888 is "Standardize KV-Store Docs".

Parameters:
    tools: List[BaseTool]. The tools in the toolkit. Default is an empty list.
toolsgithub_api_wrapperinclude_release_toolsreturnc                 D   SS[         [        S.SS[        [        S.SS[        [
        S.SS	[        [        S.S
S[        [        S.SS[        [        S.SS[        [        S.SS[        [        S.SS[        [        S.SS[        [        S.SS[         ["        S.SS[$        [&        S.SS[(        [        S.SS[*        [        S.SS[,        [        S.SS [.        [0        S.S!S"[2        [0        S.S#S$[4        [6        S.S%S&[8        [:        S.S'S([<        [>        S.S)S*[@        [B        S./nS+S,[D        [        S.S-S.[F        [        S.S/S0[H        [J        S./nX2(       a  UO/ -   nU Vs/ sH)  n[M        US1   US2   US3   UURO                  S4S55      S69PM+     nnU " US79$ s  snf )8a  Create a GitHubToolkit from a GitHubAPIWrapper.

Args:
    github_api_wrapper: GitHubAPIWrapper. The GitHub API wrapper.
    include_release_tools: bool. Whether to include release-related tools.
        Defaults to False.

Returns:
    GitHubToolkit. The GitHub toolkit.

get_issuesz
Get Issues)modenamer'   args_schema	get_issuez	Get Issuecomment_on_issuezComment on Issuelist_open_pull_requestszList open pull requests (PRs)get_pull_requestzGet Pull Requestlist_pull_request_filesz Overview of files included in PRcreate_pull_requestzCreate Pull RequestzList Pull Requests' Filescreate_filezCreate File	read_filez	Read Fileupdate_filezUpdate Filedelete_filezDelete Filelist_files_in_main_branchz)Overview of existing files in Main branchlist_files_in_bot_branchz+Overview of files in current working branchlist_branches_in_repoz List branches in this repositoryset_active_branchzSet active branchcreate_branchzCreate a new branchget_files_from_directoryzGet files from a directorysearch_issues_and_prszSearch issues and pull requestssearch_codezSearch codecreate_review_requestzCreate review requestget_latest_releasezGet latest releaseget_releaseszGet releasesget_releasezGet releaser{   r'   rz   r|   N)r{   r'   rz   api_wrapperr|   rt   )(r   r#   r   r5   r	   r:   r   r   r@   r   r   rD   r   rH   r   rM   r   rS   r   rW   r   r   r   r   r]   r
   r   rZ   r   rk   r   ra   r   rg   r   r   r   rn   r    get)clsru   rv   
operationsrelease_operationsactionrt   s          r3   from_github_api_wrapper%GitHubToolkit.from_github_api_wrapper,  sS     %$0&	 $#/'	 +*6-	 27.&	 +*,$	 2:6$	 .-9'	 236$	 &%1)	 $#/'	 &%1)	 &%1)	 4C>&	 3EA&	 0:;&	 ,+7)	 (-3)	 34>,	 09;1	 &%1)	 0/;2	s"

F -,8&	 '&2&	 &%1&	*
*  9N#5TVW
 %	
 % F^"=1F^."JJ}d; % 	 	
 	
s   &/Fc                     U R                   $ )zGet the tools in the toolkit.r   )selfs    r3   	get_toolsGitHubToolkit.get_tools  s    zzr2   r)   N)F)r*   r+   r,   r-   r.   rt   r   r   r0   classmethodr!   boolr   r   r1   r)   r2   r3   rr   rr      s\    @D E4>QVn !1n JNn 	n  n `4> r2   rr   N)7r.   typingr   r   langchain_core.toolsr   langchain_core.tools.baser   pydanticr   r   'langchain_community.tools.github.promptr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   %langchain_community.tools.github.toolr    $langchain_community.utilities.githubr!   r#   r5   r:   r@   rD   rH   rM   rS   rW   rZ   r]   ra   rg   rk   rn   rr   r)   r2   r3   <module>r      s     ) 1 %      2 ? AXi XVy VKY KTI TRy RT T	y 	  	I 	 	 	)  i xK xr2   