GitHubRepoViewerTool

GitHubRepoViewerTool

Agent가 GitHub 저장소를 탐색하고 콘텐츠를 가져올 수 있게 해 주는 Tool이에요.

출처: 문서

본문

GitHubRepoViewerTool은 GitHubRepoViewer 구성 요소를 감싸서, 에이전트 워크플로와 tool 기반 파이프라인에서 쓸 수 있는 tool 인터페이스를 제공해요. 경로 유형에 따라 다른 동작을 제공해요:

  • 디렉토리: 각 항목(파일과 하위 디렉토리)에 대해 하나씩 문서 리스트 반환
  • 파일: 파일 콘텐츠를 담은 단일 문서 반환

각 문서에는 경로, 유형, 크기, URL 등의 풍부한 메타데이터가 포함돼요.

Parameters ​

  • name — 선택. 기본값 "repo_viewer". tool의 이름.
  • description — 선택. tool이 무엇을 하는지 LLM에 알려주는 설명.
  • github_token — _선택_이지만 비공개 저장소나 rate limiting을 피하려면 권장.
  • repo — 선택. owner/repo 형식의 기본 저장소 설정.
  • branch — 선택. 기본값 "main". 작업할 기본 브랜치.
  • raise_on_failure — 선택. 기본값 True. False면 예외를 던지는 대신 에러를 문서로 반환.
  • max_file_size — 선택. 기본값 1,000,000 바이트(1MB). 가져올 최대 파일 크기.

Usage ​

pip install github-haystack

저장소 플레이스홀더: 아래 코드 스니펫을 실행하려면 owner/repo를 자신의 GitHub 저장소 이름으로 바꿔야 해요.

On its own ​

저장소 콘텐츠를 보는 기본 사용법:

from haystack_integrations.tools.github import GitHubRepoViewerTool

tool = GitHubRepoViewerTool()
result = tool.invoke(
    repo="deepset-ai/haystack",
    path="haystack/components",
    branch="main",
)
print(result)
{'documents': [Document(id=..., content: 'agents', meta: {'path': 'haystack/components/agents', 'type': 'dir', 'size': 0, 'url': 'https://github.com/deepset-ai/haystack/tree/main/haystack/components/agents'}), Document(id=..., content: 'builders', meta: {'path': 'haystack/components/builders', 'type': 'dir', 'size': 0, 'url': 'https://github.com/deepset-ai/haystack/tree/main/haystack/components/builders'}),...]}

With an Agent ​

GitHubRepoViewerTool을 Agent 구성 요소와 함께 사용할 수 있어요. Agent는 저장소 구조를 탐색하고 파일을 읽을 필요가 있을 때 자동으로 tool을 호출해요. 이 코드 예시에서는 GitHubRepoViewerTool이 문서를 상태에 쓸 수 있도록 Agent의 state_schema 파라미터를 설정했어요.

from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage, Document
from haystack.components.agents import Agent
from haystack_integrations.tools.github import GitHubRepoViewerTool

repo_tool = GitHubRepoViewerTool(name="github_repo_viewer")
agent = Agent(
    chat_generator=OpenAIChatGenerator(),
    tools=[repo_tool],
    exit_conditions=["text"],
    state_schema={"documents": {"type": list[Document]}},
)
response = agent.run(
    messages=[
        ChatMessage.from_user(
            "Can you analyze the structure of the deepset-ai/haystack repository and tell me about the main components?",
        ),
    ],
)
print(response["last_message"].text)
The `deepset-ai/haystack` repository has a structured layout that includes several important components. Here's an overview of its main parts:1. **Directories**:   - **`.github`**: Contains GitHub-specific configuration files and workflows.   - **`docker`**: Likely includes Docker-related files for containerization of the Haystack application.   - **`docs`**: Contains documentation for the Haystack project. This could include guides, API documentation, and other related resources.   - **`e2e`**: This likely stands for "end-to-end", possibly containing tests or examples related to end-to-end functionality of the Haystack framework.   - **`examples`**: Includes example scripts or notebooks demonstrating how to use Haystack.   - **`haystack`**: This is likely the core source code of the Haystack framework itself, containing the main functionality and classes.   - **`proposals`**: A directory that may contain proposals for new features or changes to the Haystack project.   - **`releasenotes`**: Contains notes about various releases, including changes and improvements.   - **`test`**: This directory likely contains unit tests and other testing utilities to ensure code quality and functionality.2. **Files**:   - **`.gitignore`**: Specifies files and directories that should be ignored by Git.   - **`.pre-commit-config.yaml`**: Configuration file for pre-commit hooks to automate code quality checks.   - **`CITATION.cff`**: Might include information on how to cite the repository in academic work.   - **`code_of_conduct.txt`**: Contains the code of conduct for contributors and users of the repository.   - **`CONTRIBUTING.md`**: Guidelines for contributing to the repository.   - **`LICENSE`**: The license under which the project is distributed.   - **`VERSION.txt`**: Contains versioning information for the project.   - **`README.md`**: A markdown file that usually provides an overview of the project, installation instructions, and usage examples.   - **`SECURITY.md`**: Contain...