summaryrefslogtreecommitdiff
path: root/continuedev/src/continuedev/core
diff options
context:
space:
mode:
authorNate Sesti <33237525+sestinj@users.noreply.github.com>2023-09-28 01:02:52 -0700
committerGitHub <noreply@github.com>2023-09-28 01:02:52 -0700
commit95363a5b52f3bf73531ac76b00178fa79ca97661 (patch)
tree9b9c1614556f1f0d21f363e6a9fe950069affb5d /continuedev/src/continuedev/core
parentd4acf4bb11dbd7d3d6210e2949d21143d721e81e (diff)
downloadsncontinue-95363a5b52f3bf73531ac76b00178fa79ca97661.tar.gz
sncontinue-95363a5b52f3bf73531ac76b00178fa79ca97661.tar.bz2
sncontinue-95363a5b52f3bf73531ac76b00178fa79ca97661.zip
Past input (#513)
* feat: :construction: use ComboBox in place of UserInputContainer * feat: :construction: adding context to previous inputs steps * feat: :sparkles: preview context items on click * feat: :construction: more work on context items ui * style: :construction: working out the details of ctx item buttons * feat: :sparkles: getting the final details * fix: :bug: fix height of ctx items bar * fix: :bug: last couple of details * fix: :bug: pass model param through to hf inference api * fix: :loud_sound: better logging for timeout * feat: :sparkles: option to set the meilisearch url * fix: :bug: fix height of past inputs
Diffstat (limited to 'continuedev/src/continuedev/core')
-rw-r--r--continuedev/src/continuedev/core/autopilot.py47
-rw-r--r--continuedev/src/continuedev/core/context.py26
-rw-r--r--continuedev/src/continuedev/core/main.py2
3 files changed, 63 insertions, 12 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py
index 0155e755..9ebf288b 100644
--- a/continuedev/src/continuedev/core/autopilot.py
+++ b/continuedev/src/continuedev/core/autopilot.py
@@ -37,7 +37,7 @@ from ..plugins.steps.core.core import (
)
from ..plugins.steps.on_traceback import DefaultOnTracebackStep
from ..server.ide_protocol import AbstractIdeProtocolServer
-from ..server.meilisearch_server import stop_meilisearch
+from ..server.meilisearch_server import get_meilisearch_url, stop_meilisearch
from .config import ContinueConfig
from .context import ContextManager
from .main import (
@@ -179,6 +179,7 @@ class Autopilot(ContinueBaseModel):
config=self.continue_sdk.config,
saved_context_groups=self._saved_context_groups,
context_providers=self.context_manager.get_provider_descriptions(),
+ meilisearch_url=get_meilisearch_url(),
)
self.full_state = full_state
return full_state
@@ -306,7 +307,8 @@ class Autopilot(ContinueBaseModel):
await self.update_subscribers()
async def edit_step_at_index(self, user_input: str, index: int):
- step_to_rerun = self.history.timeline[index].step.copy()
+ node_to_rerun = self.history.timeline[index].copy()
+ step_to_rerun = node_to_rerun.step
step_to_rerun.user_input = user_input
step_to_rerun.description = user_input
@@ -318,13 +320,29 @@ class Autopilot(ContinueBaseModel):
node_to_delete.deleted = True
self.history.current_index = index - 1
+
+ # Set the context to the context used by that step
+ await self.context_manager.clear_context()
+ for context_item in node_to_rerun.context_used:
+ await self.context_manager.manually_add_context_item(context_item)
+
await self.update_subscribers()
# Rerun from the current step
await self.run_from_step(step_to_rerun)
- async def delete_context_with_ids(self, ids: List[str]):
- await self.context_manager.delete_context_with_ids(ids)
+ async def delete_context_with_ids(
+ self, ids: List[str], index: Optional[int] = None
+ ):
+ if index is None:
+ await self.context_manager.delete_context_with_ids(ids)
+ else:
+ self.history.timeline[index].context_used = list(
+ filter(
+ lambda item: item.description.id.to_string() not in ids,
+ self.history.timeline[index].context_used,
+ )
+ )
await self.update_subscribers()
async def toggle_adding_highlighted_code(self):
@@ -380,7 +398,12 @@ class Autopilot(ContinueBaseModel):
# Update history - do this first so we get top-first tree ordering
index_of_history_node = self.history.add_node(
- HistoryNode(step=step, observation=None, depth=self._step_depth)
+ HistoryNode(
+ step=step,
+ observation=None,
+ depth=self._step_depth,
+ context_used=await self.context_manager.get_selected_items(),
+ )
)
# Call all subscribed callbacks
@@ -600,7 +623,7 @@ class Autopilot(ContinueBaseModel):
async def accept_user_input(self, user_input: str):
self._main_user_input_queue.append(user_input)
- await self.update_subscribers()
+ # await self.update_subscribers()
if len(self._main_user_input_queue) > 1:
return
@@ -609,7 +632,7 @@ class Autopilot(ContinueBaseModel):
# Just run the step that takes user input, and
# then up to the policy to decide how to deal with it.
self._main_user_input_queue.pop(0)
- await self.update_subscribers()
+ # await self.update_subscribers()
await self.run_from_step(UserInputStep(user_input=user_input))
while len(self._main_user_input_queue) > 0:
@@ -635,6 +658,16 @@ class Autopilot(ContinueBaseModel):
await self.context_manager.select_context_item(id, query)
await self.update_subscribers()
+ async def select_context_item_at_index(self, id: str, query: str, index: int):
+ # TODO: This is different from how it works for the main input
+ # Ideally still tracked through the ContextProviders
+ # so they can watch for duplicates
+ context_item = await self.context_manager.get_context_item(id, query)
+ if context_item is None:
+ return
+ self.history.timeline[index].context_used.append(context_item)
+ await self.update_subscribers()
+
async def set_config_attr(self, key_path: List[str], value: redbaron.RedBaron):
edit_config_property(key_path, value)
await self.update_subscribers()
diff --git a/continuedev/src/continuedev/core/context.py b/continuedev/src/continuedev/core/context.py
index f2658602..d374dd02 100644
--- a/continuedev/src/continuedev/core/context.py
+++ b/continuedev/src/continuedev/core/context.py
@@ -10,7 +10,11 @@ from ..libs.util.create_async_task import create_async_task
from ..libs.util.devdata import dev_data_logger
from ..libs.util.logging import logger
from ..libs.util.telemetry import posthog_logger
-from ..server.meilisearch_server import poll_meilisearch_running, restart_meilisearch
+from ..server.meilisearch_server import (
+ get_meilisearch_url,
+ poll_meilisearch_running,
+ restart_meilisearch,
+)
from .main import (
ChatMessage,
ContextItem,
@@ -127,7 +131,7 @@ class ContextProvider(BaseModel):
Default implementation uses the search index to get the item.
"""
- async with Client("http://localhost:7700") as search_client:
+ async with Client(get_meilisearch_url()) as search_client:
try:
result = await search_client.index(SEARCH_INDEX_NAME).get_document(
id.to_string()
@@ -295,7 +299,7 @@ class ContextManager:
}
for item in context_items
]
- async with Client("http://localhost:7700") as search_client:
+ async with Client(get_meilisearch_url()) as search_client:
async def add_docs():
index = await search_client.get_index(SEARCH_INDEX_NAME)
@@ -313,7 +317,7 @@ class ContextManager:
"""
Deletes the documents in the search index.
"""
- async with Client("http://localhost:7700") as search_client:
+ async with Client(get_meilisearch_url()) as search_client:
await asyncio.wait_for(
search_client.index(SEARCH_INDEX_NAME).delete_documents(ids),
timeout=20,
@@ -321,7 +325,7 @@ class ContextManager:
async def load_index(self, workspace_dir: str, should_retry: bool = True):
try:
- async with Client("http://localhost:7700") as search_client:
+ async with Client(get_meilisearch_url()) as search_client:
# First, create the index if it doesn't exist
# The index is currently shared by all workspaces
await search_client.create_index(SEARCH_INDEX_NAME)
@@ -422,6 +426,18 @@ class ContextManager:
)
await self.context_providers[id.provider_title].add_context_item(id, query)
+ async def get_context_item(self, id: str, query: str) -> ContextItem:
+ """
+ Returns the ContextItem with the given id.
+ """
+ id: ContextItemId = ContextItemId.from_string(id)
+ if id.provider_title not in self.provider_titles:
+ raise ValueError(
+ f"Context provider with title {id.provider_title} not found"
+ )
+
+ return await self.context_providers[id.provider_title].get_item(id, query)
+
async def delete_context_with_ids(self, ids: List[str]):
"""
Deletes the ContextItems with the given IDs, lets ContextProviders recalculate.
diff --git a/continuedev/src/continuedev/core/main.py b/continuedev/src/continuedev/core/main.py
index cf41aab9..617a5aaa 100644
--- a/continuedev/src/continuedev/core/main.py
+++ b/continuedev/src/continuedev/core/main.py
@@ -108,6 +108,7 @@ class HistoryNode(ContinueBaseModel):
deleted: bool = False
active: bool = True
logs: List[str] = []
+ context_used: List["ContextItem"] = []
def to_chat_messages(self) -> List[ChatMessage]:
if self.step.description is None or self.step.manage_own_chat_context:
@@ -312,6 +313,7 @@ class FullState(ContinueBaseModel):
config: ContinueConfig
saved_context_groups: Dict[str, List[ContextItem]] = {}
context_providers: List[ContextProviderDescription] = []
+ meilisearch_url: Optional[str] = None
class ContinueSDK: