github.mdx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ---
  2. title: 📝 Github
  3. ---
  4. 1. Setup the Github loader by configuring the Github account with username and personal access token (PAT). Check out [this](https://docs.github.com/en/enterprise-server@3.6/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token) link to learn how to create a PAT.
  5. ```Python
  6. from embedchain.loaders.github import GithubLoader
  7. loader = GithubLoader(
  8. config={
  9. "token":"ghp_xxxx"
  10. }
  11. )
  12. ```
  13. 2. Once you setup the loader, you can create an app and load data using the above Github loader
  14. ```Python
  15. import os
  16. from embedchain.pipeline import Pipeline as App
  17. os.environ["OPENAI_API_KEY"] = "sk-xxxx"
  18. app = App()
  19. app.add("repo:embedchain/embedchain type:repo", data_type="github", loader=loader)
  20. response = app.query("What is Embedchain?")
  21. # Answer: Embedchain is a Data Platform for Large Language Models (LLMs). It allows users to seamlessly load, index, retrieve, and sync unstructured data in order to build dynamic, LLM-powered applications. There is also a JavaScript implementation called embedchain-js available on GitHub.
  22. ```
  23. The `add` function of the app will accept any valid github query with qualifiers. It only supports loading github code, repository, issues and pull-requests.
  24. <Note>
  25. You must provide qualifiers `type:` and `repo:` in the query. The `type:` qualifier can be a combination of `code`, `repo`, `pr`, `issue`. The `repo:` qualifier must be a valid github repository name.
  26. </Note>
  27. <Card title="Valid queries" icon="lightbulb" iconType="duotone" color="#ca8b04">
  28. - `repo:embedchain/embedchain type:repo` - to load the repository
  29. - `repo:embedchain/embedchain type:issue,pr` - to load the issues and pull-requests of the repository
  30. - `repo:embedchain/embedchain type:issue state:closed` - to load the closed issues of the repository
  31. </Card>
  32. 3. We automatically create a chunker to chunk your GitHub data, however if you wish to provide your own chunker class. Here is how you can do that:
  33. ```Python
  34. from embedchain.chunkers.common_chunker import CommonChunker
  35. from embedchain.config.add_config import ChunkerConfig
  36. github_chunker_config = ChunkerConfig(chunk_size=2000, chunk_overlap=0, length_function=len)
  37. github_chunker = CommonChunker(config=github_chunker_config)
  38. app.add(load_query, data_type="github", loader=loader, chunker=github_chunker)
  39. ```