Skip to content

Commit

Permalink
Merge branch 'main' into docs_env_key
Browse files Browse the repository at this point in the history
  • Loading branch information
srdas authored Feb 4, 2025
2 parents 670fb07 + c79f89d commit d5300b1
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: jlpm install

- name: Set up browser cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/pw-browsers
Expand Down
23 changes: 21 additions & 2 deletions packages/jupyter-ai/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
tsconfigRootDir: __dirname,
project: './tsconfig.json'
},
plugins: ['@typescript-eslint'],
plugins: ['@stylistic', '@typescript-eslint'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
Expand All @@ -27,13 +27,32 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
'@stylistic/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false }
],
curly: ['error', 'all'],
eqeqeq: 'error',
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@mui/icons-material',

message:
"Please import icons using path imports, e.g. `import AddIcon from '@mui/icons-material/Add'`"
}
],
patterns: [
{
group: ['@mui/*/*/*'],
message: '3rd level imports in mui are considered private'
}
]
}
],
'prefer-arrow-callback': 'error'
},
overrides: [
Expand Down
3 changes: 2 additions & 1 deletion packages/jupyter-ai/jupyter_ai/completions/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ async def handle_exc(self, e: Exception, request: InlineCompletionRequest):
`handle_stream_request()`. This base class provides a default
implementation, which may be overridden by subclasses.
"""
title = e.args[0] if e.args else "Exception"
error = CompletionError(
type=e.__class__.__name__,
title=e.args[0] if e.args else "Exception",
title=title,
traceback=traceback.format_exc(),
)
self.reply(
Expand Down
31 changes: 26 additions & 5 deletions packages/jupyter-ai/jupyter_ai/tests/completions/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ class MockProvider(BaseProvider, FakeListLLM):
name = "My Provider"
model_id_key = "model"
models = ["model"]
raise_exc: bool = False

def __init__(self, **kwargs):
if "responses" not in kwargs:
kwargs["responses"] = ["Test response"]
super().__init__(**kwargs)

async def _acall(self, *args, **kwargs):
if self.raise_exc:
raise Exception("Test exception")
else:
return super()._call(*args, **kwargs)


class MockCompletionHandler(DefaultInlineCompletionHandler):
def __init__(self, lm_provider=None, lm_provider_params=None):
def __init__(self, lm_provider=None, lm_provider_params=None, raise_exc=False):
self.request = HTTPServerRequest()
self.application = Application()
self.messages = []
Expand All @@ -50,10 +57,6 @@ def reply(
) -> None:
self.messages.append(message)

async def handle_exc(self, e: Exception, _request: InlineCompletionRequest):
# raise all exceptions during testing rather
raise e


@fixture
def inline_handler() -> MockCompletionHandler:
Expand Down Expand Up @@ -191,3 +194,21 @@ async def test_handle_stream_request():
assert third.type == "stream"
assert third.response.insertText == "test"
assert third.done is True


async def test_handle_request_with_error(inline_handler):
inline_handler = MockCompletionHandler(
lm_provider=MockProvider,
lm_provider_params={
"model_id": "model",
"responses": ["test"],
"raise_exc": True,
},
)
dummy_request = InlineCompletionRequest(
number=1, prefix="", suffix="", mime="", stream=True
)
await inline_handler.on_message(json.dumps(dict(dummy_request)))
await inline_handler.tasks[0]
error = inline_handler.messages[-1].model_dump().get("error", None)
assert error is not None
7 changes: 4 additions & 3 deletions packages/jupyter-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@
"@babel/preset-env": "^7.0.0",
"@jupyterlab/builder": "^4.2.0",
"@jupyterlab/testutils": "^4.2.0",
"@stylistic/eslint-plugin": "^3.0.1",
"@types/jest": "^29",
"@types/react-dom": "^18.2.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint": "^7.14.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^29",
Expand Down
12 changes: 8 additions & 4 deletions packages/jupyter-ai/src/completions/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@ export class JaiInlineProvider
label: 'Show Traceback',
callback: () => {
showErrorMessage('Inline completion failed on the server side', {
message: error.traceback
message: `${error.title}\n${error.traceback}`
});
}
}
]
});
throw new Error(
`Inline completion failed: ${error.type}\n${error.traceback}`
);
const items = [
{
error: { message: error.title },
insertText: ''
}
];
return { items };
}
return result.list;
}
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-ai/src/completions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export namespace AiCompleterService {
export type CompletionError = {
type: string;
traceback: string;
title: string;
};

export type InlineCompletionReply = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {
TextField,
InputAdornment
} from '@mui/material';
import {
Edit,
DeleteOutline,
Cancel,
Check,
Visibility,
VisibilityOff
} from '@mui/icons-material';
import Edit from '@mui/icons-material/Edit';
import DeleteOutline from '@mui/icons-material/DeleteOutline';
import Cancel from '@mui/icons-material/Cancel';
import Check from '@mui/icons-material/Check';
import Visibility from '@mui/icons-material/Visibility';
import VisibilityOff from '@mui/icons-material/VisibilityOff';
import { AsyncIconButton } from '../mui-extras/async-icon-button';

import { AiService } from '../../handler';
Expand Down
18 changes: 8 additions & 10 deletions packages/jupyter-ai/src/slash-autocompletion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import {
AutocompleteCommand,
IAutocompletionCommandsProps
} from '@jupyter/chat';
import {
Download,
FindInPage,
Help,
MoreHoriz,
MenuBook,
School,
HideSource,
AutoFixNormal
} from '@mui/icons-material';
import Download from '@mui/icons-material/Download';
import FindInPage from '@mui/icons-material/FindInPage';
import Help from '@mui/icons-material/Help';
import MoreHoriz from '@mui/icons-material/MoreHoriz';
import MenuBook from '@mui/icons-material/MenuBook';
import School from '@mui/icons-material/School';
import HideSource from '@mui/icons-material/HideSource';
import AutoFixNormal from '@mui/icons-material/AutoFixNormal';
import { Box, Typography } from '@mui/material';
import React from 'react';
import { AiService } from './handler';
Expand Down
Loading

0 comments on commit d5300b1

Please sign in to comment.