diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-29 17:32:03 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-29 17:32:03 -0700 |
commit | 03aac35a076caaa14eeeaf2115555cfcc65ea0e1 (patch) | |
tree | 065f2bcf6d9d4fedbfb6f9679eda58e11b64b275 | |
parent | 2719d7ad18c2e8935f111bac3a49bacd6af86c8c (diff) | |
download | sncontinue-03aac35a076caaa14eeeaf2115555cfcc65ea0e1.tar.gz sncontinue-03aac35a076caaa14eeeaf2115555cfcc65ea0e1.tar.bz2 sncontinue-03aac35a076caaa14eeeaf2115555cfcc65ea0e1.zip |
small fixes
-rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 2 | ||||
-rw-r--r-- | continuedev/src/continuedev/core/main.py | 2 | ||||
-rw-r--r-- | continuedev/src/continuedev/steps/chat.py | 23 | ||||
-rw-r--r-- | continuedev/src/continuedev/steps/core/core.py | 2 | ||||
-rw-r--r-- | extension/react-app/src/components/CodeBlock.tsx | 91 |
5 files changed, 70 insertions, 50 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index 7d149e7e..8da3ad3b 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -31,6 +31,8 @@ def get_error_title(e: Exception) -> str: return e._message elif isinstance(e, ClientPayloadError): return "The request to OpenAI failed. Please try again." + elif isinstance(e, openai_errors.APIConnectionError): + return "The request failed. Please check your internet connection and try again." return e.__repr__() diff --git a/continuedev/src/continuedev/core/main.py b/continuedev/src/continuedev/core/main.py index 1d2b0cad..4c6f4dc2 100644 --- a/continuedev/src/continuedev/core/main.py +++ b/continuedev/src/continuedev/core/main.py @@ -111,7 +111,7 @@ class HistoryNode(ContinueBaseModel): content=json.dumps({ "description": self.step.description or "Function complete", }), - summary=f"Ran function {self.step.name}" + summary=f"Called function {self.step.name}" )] diff --git a/continuedev/src/continuedev/steps/chat.py b/continuedev/src/continuedev/steps/chat.py index ccb7f62a..58f61198 100644 --- a/continuedev/src/continuedev/steps/chat.py +++ b/continuedev/src/continuedev/steps/chat.py @@ -1,6 +1,8 @@ import json from typing import Any, Coroutine, List +from pydantic import Field + from .main import EditHighlightedCodeStep from .core.core import MessageStep from ..core.main import FunctionCall, Models @@ -113,8 +115,10 @@ class ViewDirectoryTreeStep(Step): class EditFileStep(Step): name: str = "Edit File" description: str = "Edit a file in the workspace that is not currently open." - filename: str - instructions: str + filename: str = Field( + ..., description="The name of the file to edit.") + instructions: str = Field( + ..., description="The instructions to edit the file.") hide: bool = True async def run(self, sdk: ContinueSDK): @@ -201,7 +205,7 @@ class ChatWithFunctions(Step): # name=func_name, # arguments=func_args # ), - # summary=f"Ran function {func_name}" + # summary=f"Called function {func_name}" # )) # self.chat_context.append(ChatMessage( # role="user", @@ -212,7 +216,11 @@ class ChatWithFunctions(Step): # continue # Call the function, then continue to chat func_args = "{}" if func_args == "" else func_args - fn_call_params = json.loads(func_args) + try: + fn_call_params = json.loads(func_args) + except json.JSONDecodeError: + raise Exception( + "The model returned invalid JSON. Please try again") self.chat_context.append(ChatMessage( role="assistant", content=None, @@ -220,7 +228,7 @@ class ChatWithFunctions(Step): name=func_name, arguments=func_args ), - summary=f"Ran function {func_name}" + summary=f"Called function {func_name}" )) last_function_called_index_in_history = sdk.history.current_index + 1 step_to_run = step_name_step_class_map[func_name]( @@ -234,5 +242,10 @@ class ChatWithFunctions(Step): # self.description += f"\nAdded directory `{func_args['directory_name']}`" # else: # self.description += f"\n`Running function {func_name}`\n\n" + if func_name == "EditHighlightedCodeStep": + step_to_run.user_input = self.user_input + elif func_name == "EditFile": + step_to_run.instructions = self.user_input + await sdk.run_step(step_to_run) await sdk.update_ui() diff --git a/continuedev/src/continuedev/steps/core/core.py b/continuedev/src/continuedev/steps/core/core.py index c8acd7c5..887a6434 100644 --- a/continuedev/src/continuedev/steps/core/core.py +++ b/continuedev/src/continuedev/steps/core/core.py @@ -454,7 +454,7 @@ class DefaultModelEditCodeStep(Step): self._prompt_and_completion += prompt + completion async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]: - self.description = f"{self.user_input}" + self.description = f"`{self.user_input}`" await sdk.update_ui() rif_with_contents = [] diff --git a/extension/react-app/src/components/CodeBlock.tsx b/extension/react-app/src/components/CodeBlock.tsx index 508dcc83..1624b986 100644 --- a/extension/react-app/src/components/CodeBlock.tsx +++ b/extension/react-app/src/components/CodeBlock.tsx @@ -65,51 +65,56 @@ function CodeBlock(props: { children: React.ReactNode }) { const [result, setResult] = useState<AutoHighlightResult | undefined>( undefined ); + + const [highlightTimeout, setHighlightTimeout] = useState< + NodeJS.Timeout | undefined + >(undefined); + useEffect(() => { - const result = hljs.highlightAuto( - (props.children as any).props.children[0], - [ - "python", - "javascript", - "typescript", - "bash", - "html", - "css", - "json", - "yaml", - "markdown", - "sql", - "java", - "c", - "cpp", - "csharp", - "go", - "kotlin", - "php", - "ruby", - "rust", - "scala", - "swift", - "dart", - "haskell", - "perl", - "r", - "matlab", - "powershell", - "lua", - "elixir", - "clojure", - "groovy", - "julia", - "vbnet", - "objectivec", - "fsharp", - "erlang", - "ocaml", - ] + // Don't highlight more than once every 100ms + if (highlightTimeout) { + return; + } + + setHighlightTimeout( + setTimeout(() => { + const result = hljs.highlightAuto( + (props.children as any).props.children[0], + [ + "python", + "javascript", + "typescript", + "bash", + "html", + "css", + "json", + "yaml", + "markdown", + "sql", + "java", + "c", + "cpp", + "csharp", + "go", + "kotlin", + "php", + "ruby", + "rust", + "scala", + "swift", + "dart", + "haskell", + "perl", + "r", + "julia", + "objectivec", + "ocaml", + ] + ); + setResult(result); + setHighlightTimeout(undefined); + }, 100) ); - console.log(result); - setResult(result); }, [props.children]); const [hovered, setHovered] = useState<boolean>(false); |