Skip to content

Commit

Permalink
removed feedback ui when using local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbozarth committed Nov 12, 2024
1 parent 748eac7 commit c2712d1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
12 changes: 9 additions & 3 deletions qiskit_code_assistant_jupyterlab/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def convert_openai(model):
class ServiceUrlHandler(APIHandler):
@tornado.web.authenticated
def get(self):
self.finish(json.dumps({"url": runtime_configs["service_url"]}))
self.finish(json.dumps({
"url": runtime_configs["service_url"],
"is_openai": runtime_configs["is_openai"]
}))

@tornado.web.authenticated
def post(self):
Expand All @@ -102,7 +105,10 @@ def post(self):
except (requests.exceptions.JSONDecodeError, KeyError):
runtime_configs["is_openai"] = True
finally:
self.finish(json.dumps({"url": runtime_configs["service_url"]}))
self.finish(json.dumps({
"url": runtime_configs["service_url"],
"is_openai": runtime_configs["is_openai"]
}))


class TokenHandler(APIHandler):
Expand Down Expand Up @@ -282,7 +288,7 @@ class FeedbackHandler(APIHandler):
@tornado.web.authenticated
def post(self):
if runtime_configs["is_openai"]:
self.finish(json.dumps({"success": "true"}))
self.finish(json.dumps({"message": "Feedback not supported for this service"}))
else:
url = url_path_join(runtime_configs["service_url"], "feedback")

Expand Down
2 changes: 2 additions & 0 deletions src/QiskitCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const FEEDBACK_COMMAND = 'qiskit-code-assistant:prompt-feedback';

export let lastPrompt: ICompletionReturn | undefined = undefined;

export const wipeLastPrompt = () => (lastPrompt = undefined);

function getInputText(text: string, widget: Widget): string {
const cellsContents: string[] = [];

Expand Down
7 changes: 5 additions & 2 deletions src/StatusBarWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Message } from '@lumino/messaging';
import { refreshIcon } from '@jupyterlab/ui-components';
import { Widget } from '@lumino/widgets';

import { wipeLastPrompt } from './QiskitCompletionProvider';
import { showDisclaimer } from './service/disclaimer';
import {
getCurrentModel,
Expand Down Expand Up @@ -70,17 +71,19 @@ export class StatusBarWidget extends Widget {
async onClick() {
await checkAPIToken().then(() => {
const modelsList = getModelsList();
const dropDownList = [...modelsList.map(m => m.display_name)];
InputDialog.getItem({
title: 'Select a Model',
items: [...modelsList.map(m => m.display_name)],
current: getCurrentModel()?.display_name
items: dropDownList,
current: dropDownList.indexOf(getCurrentModel()?.display_name || '')
}).then(result => {
if (result.button.accept) {
const model = modelsList.find(m => m.display_name === result.value);

if (model) {
showDisclaimer(model._id).then(accepted => {
if (accepted) {
wipeLastPrompt();
setCurrentModel(model);
}
});
Expand Down
29 changes: 22 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import { StatusBarWidget } from './StatusBarWidget';
import {
lastPrompt,
QiskitCompletionProvider,
QiskitInlineCompletionProvider
QiskitInlineCompletionProvider,
wipeLastPrompt
} from './QiskitCompletionProvider';
import { postServiceUrl } from './service/api';
import { getFeedbackStatusBarWidget, getFeedback } from './service/feedback';
Expand Down Expand Up @@ -73,10 +74,21 @@ const plugin: JupyterFrontEndPlugin<void> = {
const settings = await settingRegistry.load(plugin.id);
console.debug(EXTENSION_ID + ' settings loaded:', settings.composite);

postServiceUrl(settings.composite['serviceUrl'] as string);
let is_openai = false;

postServiceUrl(settings.composite['serviceUrl'] as string).then(
response => {
is_openai = response.is_openai;
wipeLastPrompt();
}
);
settings.changed.connect(() =>
postServiceUrl(settings.composite['serviceUrl'] as string).then(() =>
refreshModelsList()
postServiceUrl(settings.composite['serviceUrl'] as string).then(
response => {
is_openai = response.is_openai;
wipeLastPrompt();
refreshModelsList();
}
)
);

Expand All @@ -87,7 +99,8 @@ const plugin: JupyterFrontEndPlugin<void> = {

statusBar.registerStatusItem(EXTENSION_ID + ':feedback', {
item: getFeedbackStatusBarWidget(),
align: 'left'
align: 'left',
isActive: () => !is_openai
});

const statusBarWidget = new StatusBarWidget();
Expand All @@ -104,11 +117,13 @@ const plugin: JupyterFrontEndPlugin<void> = {
label: 'Give feedback for the Qiskit Code Assistant',
icon: feedbackIcon,
execute: () => getFeedback(),
isEnabled: () => lastPrompt !== undefined,
isEnabled: () => !is_openai && lastPrompt !== undefined,
isVisible: () =>
!is_openai &&
['code', 'markdown'].includes(
notebookTracker.activeCell?.model.type || ''
) && lastPrompt !== undefined
) &&
lastPrompt !== undefined
});

app.commands.addCommand(CommandIDs.updateApiToken, {
Expand Down
10 changes: 7 additions & 3 deletions src/service/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
IModelDisclaimer,
IModelInfo,
IModelPromptResponse,
IResponseMessage
IResponseMessage,
IServiceResponse
} from '../utils/schema';

const AUTH_ERROR_CODES = [401, 403, 422];
Expand All @@ -40,14 +41,17 @@ async function notifyInvalid(response: Response): Promise<void> {
}

// POST /service
export async function postServiceUrl(newUrl: string): Promise<void> {
export async function postServiceUrl(
newUrl: string
): Promise<IServiceResponse> {
return await requestAPI('service', {
method: 'POST',
body: JSON.stringify({ url: newUrl })
}).then(response => {
if (response.ok) {
response.json().then(json => {
return response.json().then(json => {
console.debug('Updated service URL:', json.url);
return json;
});
} else {
console.error(
Expand Down
5 changes: 5 additions & 0 deletions src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ export interface IFeedbackForm {
input?: string;
output?: string;
}

export interface IServiceResponse {
url: string;
is_openai: boolean;
}

0 comments on commit c2712d1

Please sign in to comment.