docs: 📝 additional cleanup for context providers docs
This commit is contained in:
parent
84fc394076
commit
db3277bdc2
14 changed files with 51 additions and 30 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import subprocess
|
||||
from typing import List
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from ...core.context import ContextProvider
|
||||
from ...core.main import ContextItem, ContextItemDescription, ContextItemId
|
||||
|
||||
|
|
@ -15,9 +17,11 @@ class DiffContextProvider(ContextProvider):
|
|||
description = "Output of 'git diff' in current repo"
|
||||
dynamic = True
|
||||
|
||||
DIFF_CONTEXT_ITEM_ID = "diff"
|
||||
_DIFF_CONTEXT_ITEM_ID = "diff"
|
||||
|
||||
workspace_dir: str = None
|
||||
workspace_dir: str = Field(
|
||||
None, description="The workspace directory in which to run `git diff`"
|
||||
)
|
||||
|
||||
@property
|
||||
def BASE_CONTEXT_ITEM(self):
|
||||
|
|
@ -27,7 +31,7 @@ class DiffContextProvider(ContextProvider):
|
|||
name="Diff",
|
||||
description="Reference the output of 'git diff' for the current workspace",
|
||||
id=ContextItemId(
|
||||
provider_title=self.title, item_id=self.DIFF_CONTEXT_ITEM_ID
|
||||
provider_title=self.title, item_id=self._DIFF_CONTEXT_ITEM_ID
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ...core.context import ContextProvider
|
||||
from ...core.main import ContextItem, ContextItemDescription, ContextItemId
|
||||
|
|
@ -41,7 +41,7 @@ class FileTreeContextProvider(ContextProvider):
|
|||
description = "Add a formatted file tree of this directory to the context"
|
||||
dynamic = True
|
||||
|
||||
workspace_dir: str = None
|
||||
workspace_dir: str = Field(None, description="The workspace directory to display")
|
||||
|
||||
async def _get_file_tree(self, directory: str) -> str:
|
||||
contents = await self.sdk.ide.listDirectoryContents(directory, recursive=True)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from typing import List
|
||||
|
||||
from github import Auth, Github
|
||||
from pydantic import Field
|
||||
|
||||
from ...core.context import (
|
||||
ContextItem,
|
||||
|
|
@ -16,8 +17,13 @@ class GitHubIssuesContextProvider(ContextProvider):
|
|||
"""
|
||||
|
||||
title = "issues"
|
||||
repo_name: str
|
||||
auth_token: str
|
||||
repo_name: str = Field(
|
||||
..., description="The name of the GitHub repo from which to pull issues"
|
||||
)
|
||||
auth_token: str = Field(
|
||||
...,
|
||||
description="The GitHub auth token to use to authenticate with the GitHub API",
|
||||
)
|
||||
|
||||
display_title = "GitHub Issues"
|
||||
description = "Reference GitHub issues"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import json
|
|||
from typing import List
|
||||
|
||||
import aiohttp
|
||||
from pydantic import Field
|
||||
|
||||
from ...core.context import ContextProvider
|
||||
from ...core.main import ContextItem, ContextItemDescription, ContextItemId
|
||||
|
|
@ -17,9 +18,12 @@ class GoogleContextProvider(ContextProvider):
|
|||
dynamic = True
|
||||
requires_query = True
|
||||
|
||||
serper_api_key: str
|
||||
serper_api_key: str = Field(
|
||||
...,
|
||||
description="Your SerpAPI key, used to programmatically make Google searches. You can get a key at https://serper.dev.",
|
||||
)
|
||||
|
||||
GOOGLE_CONTEXT_ITEM_ID = "google_search"
|
||||
_GOOGLE_CONTEXT_ITEM_ID = "google_search"
|
||||
|
||||
@property
|
||||
def BASE_CONTEXT_ITEM(self):
|
||||
|
|
@ -29,7 +33,7 @@ class GoogleContextProvider(ContextProvider):
|
|||
name="Google Search",
|
||||
description="Enter a query to search google",
|
||||
id=ContextItemId(
|
||||
provider_title=self.title, item_id=self.GOOGLE_CONTEXT_ITEM_ID
|
||||
provider_title=self.title, item_id=self._GOOGLE_CONTEXT_ITEM_ID
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
from typing import List
|
||||
|
||||
from pydantic import Field
|
||||
from ripgrepy import Ripgrepy
|
||||
|
||||
from ...core.context import ContextProvider
|
||||
|
|
@ -18,9 +19,9 @@ class SearchContextProvider(ContextProvider):
|
|||
dynamic = True
|
||||
requires_query = True
|
||||
|
||||
SEARCH_CONTEXT_ITEM_ID = "search"
|
||||
_SEARCH_CONTEXT_ITEM_ID = "search"
|
||||
|
||||
workspace_dir: str = None
|
||||
workspace_dir: str = Field(None, description="The workspace directory to search")
|
||||
|
||||
@property
|
||||
def BASE_CONTEXT_ITEM(self):
|
||||
|
|
@ -30,7 +31,7 @@ class SearchContextProvider(ContextProvider):
|
|||
name="Search",
|
||||
description="Search the workspace for all matches of an exact string (e.g. '@search console.log')",
|
||||
id=ContextItemId(
|
||||
provider_title=self.title, item_id=self.SEARCH_CONTEXT_ITEM_ID
|
||||
provider_title=self.title, item_id=self._SEARCH_CONTEXT_ITEM_ID
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from typing import Any, Coroutine, List
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from ...core.context import ContextProvider
|
||||
from ...core.main import ChatMessage, ContextItem, ContextItemDescription, ContextItemId
|
||||
|
||||
|
|
@ -12,8 +14,9 @@ class TerminalContextProvider(ContextProvider):
|
|||
description = "Reference the contents of the terminal"
|
||||
dynamic = True
|
||||
|
||||
workspace_dir: str = None
|
||||
get_last_n_commands: int = 3
|
||||
get_last_n_commands: int = Field(
|
||||
3, description="The number of previous commands to reference"
|
||||
)
|
||||
|
||||
def _terminal_context_item(self, content: str = ""):
|
||||
return ContextItem(
|
||||
|
|
@ -32,7 +35,6 @@ class TerminalContextProvider(ContextProvider):
|
|||
return msgs
|
||||
|
||||
async def provide_context_items(self, workspace_dir: str) -> List[ContextItem]:
|
||||
self.workspace_dir = workspace_dir
|
||||
return [self._terminal_context_item()]
|
||||
|
||||
async def get_item(self, id: ContextItemId, query: str) -> ContextItem:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from typing import List
|
|||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from pydantic import Field
|
||||
|
||||
from ...core.context import ContextProvider
|
||||
from ...core.main import ContextItem, ContextItemDescription, ContextItemId
|
||||
|
|
@ -18,13 +19,16 @@ class URLContextProvider(ContextProvider):
|
|||
requires_query = True
|
||||
|
||||
# Allows users to provide a list of preset urls
|
||||
preset_urls: List[str] = []
|
||||
preset_urls: List[str] = Field(
|
||||
[],
|
||||
description="A list of preset URLs that you will be able to quickly reference by typing '@url'",
|
||||
)
|
||||
|
||||
# Static items loaded from preset_urls
|
||||
static_url_context_items: List[ContextItem] = []
|
||||
_static_url_context_items: List[ContextItem] = []
|
||||
|
||||
# There is only a single dynamic url context item, so it has a static id
|
||||
DYNAMIC_URL_CONTEXT_ITEM_ID = "url"
|
||||
_DYNAMIC_URL_CONTEXT_ITEM_ID = "url"
|
||||
|
||||
# This is a template dynamic item that will generate context item on demand
|
||||
# when get item is called
|
||||
|
|
@ -36,7 +40,7 @@ class URLContextProvider(ContextProvider):
|
|||
name="Dynamic URL",
|
||||
description="Reference the contents of a webpage (e.g. '@url https://www.w3schools.com/python/python_ref_functions.asp')",
|
||||
id=ContextItemId(
|
||||
provider_title=self.title, item_id=self.DYNAMIC_URL_CONTEXT_ITEM_ID
|
||||
provider_title=self.title, item_id=self._DYNAMIC_URL_CONTEXT_ITEM_ID
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -64,18 +68,18 @@ class URLContextProvider(ContextProvider):
|
|||
return soup.get_text(), title
|
||||
|
||||
async def provide_context_items(self, workspace_dir: str) -> List[ContextItem]:
|
||||
self.static_url_context_items = [
|
||||
self._static_url_context_items = [
|
||||
self.static_url_context_item_from_url(url) for url in self.preset_urls
|
||||
]
|
||||
|
||||
return [self.DYNAMIC_CONTEXT_ITEM] + self.static_url_context_items
|
||||
return [self.DYNAMIC_CONTEXT_ITEM] + self._static_url_context_items
|
||||
|
||||
async def get_item(self, id: ContextItemId, query: str) -> ContextItem:
|
||||
# Check if the item is a static item
|
||||
matching_static_item = next(
|
||||
(
|
||||
item
|
||||
for item in self.static_url_context_items
|
||||
for item in self._static_url_context_items
|
||||
if item.description.id.item_id == id.item_id
|
||||
),
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Type '@diff' to reference all of the changes you've made to your current branch.
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "type": "string"}' required={false} default=""/><ClassPropertyRef name='DIFF_CONTEXT_ITEM_ID' details='{"title": "Diff Context Item Id", "default": "diff", "type": "string"}' required={false} default="diff"/>
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "description": "The workspace directory in which to run `git diff`", "type": "string"}' required={false} default=""/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Type '@tree' to reference the contents of your current workspace. The LLM will b
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "type": "string"}' required={false} default=""/>
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "description": "The workspace directory to display", "type": "string"}' required={false} default=""/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ The GitHubIssuesContextProvider is a ContextProvider that allows you to search G
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='repo_name' details='{"title": "Repo Name", "type": "string"}' required={true} default=""/><ClassPropertyRef name='auth_token' details='{"title": "Auth Token", "type": "string"}' required={true} default=""/>
|
||||
<ClassPropertyRef name='repo_name' details='{"title": "Repo Name", "description": "The name of the GitHub repo from which to pull issues", "type": "string"}' required={true} default=""/><ClassPropertyRef name='auth_token' details='{"title": "Auth Token", "description": "The GitHub auth token to use to authenticate with the GitHub API", "type": "string"}' required={true} default=""/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Type '@google' to reference the results of a Google search. For example, type "@
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='serper_api_key' details='{"title": "Serper Api Key", "type": "string"}' required={true} default=""/><ClassPropertyRef name='GOOGLE_CONTEXT_ITEM_ID' details='{"title": "Google Context Item Id", "default": "google_search", "type": "string"}' required={false} default="google_search"/>
|
||||
<ClassPropertyRef name='serper_api_key' details='{"title": "Serper Api Key", "description": "Your SerpAPI key, used to programmatically make Google searches. You can get a key at https://serper.dev.", "type": "string"}' required={true} default=""/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Type '@search' to reference the results of codebase search, just like the result
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "type": "string"}' required={false} default=""/><ClassPropertyRef name='SEARCH_CONTEXT_ITEM_ID' details='{"title": "Search Context Item Id", "default": "search", "type": "string"}' required={false} default="search"/>
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "description": "The workspace directory to search", "type": "string"}' required={false} default=""/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Type '@terminal' to reference the contents of your IDE's terminal.
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='workspace_dir' details='{"title": "Workspace Dir", "type": "string"}' required={false} default=""/><ClassPropertyRef name='get_last_n_commands' details='{"title": "Get Last N Commands", "default": 3, "type": "integer"}' required={false} default="3"/>
|
||||
<ClassPropertyRef name='get_last_n_commands' details='{"title": "Get Last N Commands", "description": "The number of previous commands to reference", "default": 3, "type": "integer"}' required={false} default="3"/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Type '@url' to reference the contents of a URL. You can either reference preset
|
|||
|
||||
## Properties
|
||||
|
||||
<ClassPropertyRef name='preset_urls' details='{"title": "Preset Urls", "default": [], "type": "array", "items": {"type": "string"}}' required={false} default="[]"/><ClassPropertyRef name='static_url_context_items' details='{"title": "Static Url Context Items", "default": [], "type": "array", "items": {"$ref": "#/definitions/ContextItem"}}' required={false} default="[]"/><ClassPropertyRef name='DYNAMIC_URL_CONTEXT_ITEM_ID' details='{"title": "Dynamic Url Context Item Id", "default": "url", "type": "string"}' required={false} default="url"/>
|
||||
<ClassPropertyRef name='preset_urls' details='{"title": "Preset Urls", "description": "A list of preset URLs that you will be able to quickly reference by typing '@url'", "default": [], "type": "array", "items": {"type": "string"}}' required={false} default="[]"/>
|
||||
|
||||
### Inherited Properties
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue