Nate/jetbrains (#577)

* 🥅 better error handling in ggml

* 🐛 fixing a few jetbrains bugs
This commit is contained in:
Nate Sesti 2023-10-23 18:19:00 -07:00 • committed by GitHub
parent 1c5972eedd
commit 537ac8a9d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 81 additions and 38 deletions

View file

@ -4,7 +4,7 @@ pluginGroup = com.github.continuedev.continueintellijextension
pluginName = continue-intellij-extension
pluginRepositoryUrl = https://github.com/continuedev/continue
# SemVer format -> https://semver.org
pluginVersion = 0.0.13
pluginVersion = 0.0.14
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223

View file

@ -12,11 +12,15 @@ import com.google.gson.Gson
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.CustomShortcutSet
import com.intellij.openapi.actionSystem.KeyboardShortcut
import com.intellij.openapi.actionSystem.Shortcut
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.keymap.KeymapManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.ui.DialogWrapper
@ -469,22 +473,27 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable {
}
private fun getPlatformSpecificKeyStroke(key: String): String {
val osName = System.getProperty("os.name").lowercase()
val osName = System.getProperty("os.name").toLowerCase()
val modifier = if (osName.contains("mac")) "meta" else "control"
return "$modifier $key"
}
private fun removeShortcutFromAction(shortcut: String) {
val actionManager = ActionManager.getInstance()
val keymap = KeymapManager.getInstance().activeKeymap
val keyStroke = KeyStroke.getKeyStroke(shortcut)
val actionIds = actionManager.getActionIds(keyStroke)
val actionIds = keymap.getActionIds(keyStroke)
for (actionId in actionIds) {
val action = actionManager.getAction(actionId)
val shortcuts = action.shortcutSet.shortcuts.filterNot { it is KeyboardShortcut && it.firstKeyStroke == keyStroke }.toTypedArray()
action.registerCustomShortcutSet(Shortcut { shortcuts }, null)
}
val actionManager = ActionManager.getInstance()
for (actionId in actionIds) {
if (actionId.startsWith("continue")) {
continue
}
val action = actionManager.getAction(actionId)
val shortcuts = action.shortcutSet.shortcuts.filterNot { it is KeyboardShortcut && it.firstKeyStroke == keyStroke }.toTypedArray()
val newShortcutSet = CustomShortcutSet(*shortcuts)
action.registerCustomShortcutSet(newShortcutSet, null)
}
}
private fun initializePlugin(project: Project) {

View file

@ -133,7 +133,7 @@ class IdeProtocolClient(
object : TypeToken<Map<String, Any>>() {}.type
)
val messageType = parsedMessage["messageType"] as? String
val data = parsedMessage["data"] as Map<String, Any>
val data = parsedMessage["data"] as Map<*, *>
try {
when (messageType) {

View file

@ -27,6 +27,7 @@ class CustomSchemeHandlerFactory : CefSchemeHandlerFactory {
class CustomResourceHandler : CefResourceHandler {
private var state: ResourceHandlerState = ClosedConnection
private var currentUrl: String? = null
override fun processRequest(
cefRequest: CefRequest,
cefCallback: CefCallback
@ -36,6 +37,7 @@ class CustomResourceHandler : CefResourceHandler {
val pathToResource = url.replace("http://continue", "webview/")
val newUrl = javaClass.classLoader.getResource(pathToResource)
state = OpenedConnection(newUrl?.openConnection())
currentUrl = url
cefCallback.Continue()
true
} else {
@ -48,6 +50,15 @@ class CustomResourceHandler : CefResourceHandler {
responseLength: IntRef,
redirectUrl: StringRef
) {
if (currentUrl !== null){
when {
currentUrl!!.contains("css") -> cefResponse.mimeType = "text/css"
currentUrl!!.contains("js") -> cefResponse.mimeType = "text/javascript"
currentUrl!!.contains("html") -> cefResponse.mimeType = "text/html"
else -> {}
}
}
state.getResponseHeaders(cefResponse, responseLength, redirectUrl)
}

View file

@ -1,6 +1,6 @@
> 🎁 **New! [Try out the new JetBrains extension (Alpha)](https://plugins.jetbrains.com/plugin/22707-continue-extension)**
![Continue logo](c_d.png)
![Continue logo](media/c_d.png)
<h1 align="center">Continue</h1>
@ -24,7 +24,7 @@
<p></p>
![Editing With Continue](readme.gif)
![Editing With Continue](media/readme.gif)
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 MiB

View file

@ -681,21 +681,17 @@ Please output the code to be inserted at the cursor in order to fulfill the user
current_line_in_file += 1
# Debounce the diff updates, last in only out for each period
coro = sendDiffUpdate(
lines
+ [
common_whitespace
if unfinished_line.startswith("<")
else (common_whitespace + unfinished_line)
],
sdk,
)
if last_task_time is None:
if last_task_time is None or time.time() - last_task_time > 0.15:
last_task_time = time.time()
await coro
elif time.time() - last_task_time > 0.15:
last_task_time = time.time()
await coro
await sendDiffUpdate(
lines
+ [
common_whitespace
if unfinished_line.startswith("<")
else (common_whitespace + unfinished_line)
],
sdk,
)
finally:
await generator.aclose()

View file

@ -3,7 +3,7 @@ from typing import Any, Callable, Coroutine, Dict, List, Literal, Optional
from pydantic import Field
from ...core.main import ChatMessage
from ...core.main import ChatMessage, ContinueCustomException
from ..util.logging import logger
from .base import LLM, CompletionOptions
from .openai import CHAT_MODELS
@ -38,7 +38,7 @@ class GGML(LLM):
model: str = Field(
"ggml", description="The name of the model to use (optional for the GGML class)"
)
api_base: Optional[str] = Field(None, description="OpenAI API base URL.")
api_type: Optional[Literal["azure", "openai"]] = Field(
@ -75,7 +75,7 @@ class GGML(LLM):
headers["Authorization"] = f"Bearer {self.api_key}"
return headers
def get_full_server_url(self, endpoint: str):
endpoint = endpoint.lstrip("/").rstrip("/")
@ -84,7 +84,7 @@ class GGML(LLM):
raise Exception(
"For Azure OpenAI Service, you must specify engine, api_version, and api_base."
)
return f"{self.api_base}/openai/deployments/{self.engine}/{endpoint}?api-version={self.api_version}"
else:
return f"{self.server_url}/v1/{endpoint}"
@ -143,10 +143,29 @@ class GGML(LLM):
proxy=self.proxy,
) as resp:
if resp.status != 200:
raise Exception(
detail = (
f"Error calling /chat/completions endpoint: {resp.status}"
)
try:
json_detail = await resp.json()
if (
"detail" in json_detail
and "error" in json_detail["detail"]
and "message" in json_detail["detail"]["error"]
):
detail = json_detail["detail"]["error"]["message"]
elif "message" in json_detail:
detail = json_detail["message"]
elif "detail" in json_detail:
detail = json_detail["detail"]
except:
pass
raise ContinueCustomException(
title=f"Error calling /chat/completions endpoint: {resp.status}",
message=detail,
)
async for line, end in resp.content.iter_chunks():
json_chunk = line.decode("utf-8")
chunks = json_chunk.split("\n")

View file

@ -125,12 +125,20 @@ class FileContextProvider(ContextProvider):
for filepath in contents[:1000]:
absolute_filepaths.append(filepath)
items = await asyncio.gather(
*[
self.get_context_item_for_filepath(filepath)
for filepath in absolute_filepaths
]
)
items = []
i = 0
while i < len(absolute_filepaths):
# Don't want to flood with too many requests
items += await asyncio.gather(
*[
self.get_context_item_for_filepath(filepath)
for filepath in absolute_filepaths[i : i + 100]
]
)
i += 100
asyncio.sleep(0.1)
items = list(filter(lambda item: item is not None, items))
return items