docs: 📝 additional cleanup for context providers docs

This commit is contained in:
Nate Sesti 2023-09-12 01:16:41 -07:00
parent 84fc394076
commit db3277bdc2
14 changed files with 51 additions and 30 deletions

View file

@ -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
),
),
)

View file

@ -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)

View file

@ -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"

View file

@ -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
),
),
)

View file

@ -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
),
),
)

View file

@ -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:

View file

@ -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,

View file

@ -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='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/><ClassPropertyRef name='DIFF_CONTEXT_ITEM_ID' details='{&quot;title&quot;: &quot;Diff Context Item Id&quot;, &quot;default&quot;: &quot;diff&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default="diff"/>
<ClassPropertyRef name='workspace_dir' details='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;description&quot;: &quot;The workspace directory in which to run `git diff`&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/>
### Inherited Properties

View file

@ -8,7 +8,7 @@ Type '@tree' to reference the contents of your current workspace. The LLM will b
## Properties
<ClassPropertyRef name='workspace_dir' details='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/>
<ClassPropertyRef name='workspace_dir' details='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;description&quot;: &quot;The workspace directory to display&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/>
### Inherited Properties

View file

@ -8,7 +8,7 @@ The GitHubIssuesContextProvider is a ContextProvider that allows you to search G
## Properties
<ClassPropertyRef name='repo_name' details='{&quot;title&quot;: &quot;Repo Name&quot;, &quot;type&quot;: &quot;string&quot;}' required={true} default=""/><ClassPropertyRef name='auth_token' details='{&quot;title&quot;: &quot;Auth Token&quot;, &quot;type&quot;: &quot;string&quot;}' required={true} default=""/>
<ClassPropertyRef name='repo_name' details='{&quot;title&quot;: &quot;Repo Name&quot;, &quot;description&quot;: &quot;The name of the GitHub repo from which to pull issues&quot;, &quot;type&quot;: &quot;string&quot;}' required={true} default=""/><ClassPropertyRef name='auth_token' details='{&quot;title&quot;: &quot;Auth Token&quot;, &quot;description&quot;: &quot;The GitHub auth token to use to authenticate with the GitHub API&quot;, &quot;type&quot;: &quot;string&quot;}' required={true} default=""/>
### Inherited Properties

View file

@ -8,7 +8,7 @@ Type '@google' to reference the results of a Google search. For example, type "@
## Properties
<ClassPropertyRef name='serper_api_key' details='{&quot;title&quot;: &quot;Serper Api Key&quot;, &quot;type&quot;: &quot;string&quot;}' required={true} default=""/><ClassPropertyRef name='GOOGLE_CONTEXT_ITEM_ID' details='{&quot;title&quot;: &quot;Google Context Item Id&quot;, &quot;default&quot;: &quot;google_search&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default="google_search"/>
<ClassPropertyRef name='serper_api_key' details='{&quot;title&quot;: &quot;Serper Api Key&quot;, &quot;description&quot;: &quot;Your SerpAPI key, used to programmatically make Google searches. You can get a key at https://serper.dev.&quot;, &quot;type&quot;: &quot;string&quot;}' required={true} default=""/>
### Inherited Properties

View file

@ -8,7 +8,7 @@ Type '@search' to reference the results of codebase search, just like the result
## Properties
<ClassPropertyRef name='workspace_dir' details='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/><ClassPropertyRef name='SEARCH_CONTEXT_ITEM_ID' details='{&quot;title&quot;: &quot;Search Context Item Id&quot;, &quot;default&quot;: &quot;search&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default="search"/>
<ClassPropertyRef name='workspace_dir' details='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;description&quot;: &quot;The workspace directory to search&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/>
### Inherited Properties

View file

@ -8,7 +8,7 @@ Type '@terminal' to reference the contents of your IDE's terminal.
## Properties
<ClassPropertyRef name='workspace_dir' details='{&quot;title&quot;: &quot;Workspace Dir&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default=""/><ClassPropertyRef name='get_last_n_commands' details='{&quot;title&quot;: &quot;Get Last N Commands&quot;, &quot;default&quot;: 3, &quot;type&quot;: &quot;integer&quot;}' required={false} default="3"/>
<ClassPropertyRef name='get_last_n_commands' details='{&quot;title&quot;: &quot;Get Last N Commands&quot;, &quot;description&quot;: &quot;The number of previous commands to reference&quot;, &quot;default&quot;: 3, &quot;type&quot;: &quot;integer&quot;}' required={false} default="3"/>
### Inherited Properties

View file

@ -8,7 +8,7 @@ Type '@url' to reference the contents of a URL. You can either reference preset
## Properties
<ClassPropertyRef name='preset_urls' details='{&quot;title&quot;: &quot;Preset Urls&quot;, &quot;default&quot;: [], &quot;type&quot;: &quot;array&quot;, &quot;items&quot;: {&quot;type&quot;: &quot;string&quot;}}' required={false} default="[]"/><ClassPropertyRef name='static_url_context_items' details='{&quot;title&quot;: &quot;Static Url Context Items&quot;, &quot;default&quot;: [], &quot;type&quot;: &quot;array&quot;, &quot;items&quot;: {&quot;$ref&quot;: &quot;#/definitions/ContextItem&quot;}}' required={false} default="[]"/><ClassPropertyRef name='DYNAMIC_URL_CONTEXT_ITEM_ID' details='{&quot;title&quot;: &quot;Dynamic Url Context Item Id&quot;, &quot;default&quot;: &quot;url&quot;, &quot;type&quot;: &quot;string&quot;}' required={false} default="url"/>
<ClassPropertyRef name='preset_urls' details='{&quot;title&quot;: &quot;Preset Urls&quot;, &quot;description&quot;: &quot;A list of preset URLs that you will be able to quickly reference by typing &#x27;@url&#x27;&quot;, &quot;default&quot;: [], &quot;type&quot;: &quot;array&quot;, &quot;items&quot;: {&quot;type&quot;: &quot;string&quot;}}' required={false} default="[]"/>
### Inherited Properties