Skip to content

Commit

Permalink
fix(prompt): disable saveble for interpreter edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk committed Dec 16, 2024
1 parent b910a41 commit 2324807
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
36 changes: 36 additions & 0 deletions .changeset/unlucky-hounds-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
'@difizen/libro-cofine-editor': patch
'@difizen/libro-prompt-cell': patch
'@difizen/libro-core': patch
'@difizen/libro-docs': patch
'@difizen/libro-ai-native': patch
'@difizen/libro-app': patch
'@difizen/libro-code-cell': patch
'@difizen/libro-code-editor': patch
'@difizen/libro-codemirror': patch
'@difizen/libro-cofine-editor-contribution': patch
'@difizen/libro-cofine-editor-core': patch
'@difizen/libro-cofine-textmate': patch
'@difizen/libro-common': patch
'@difizen/libro-jupyter': patch
'@difizen/libro-kernel': patch
'@difizen/libro-l10n': patch
'@difizen/libro-lab': patch
'@difizen/libro-language-client': patch
'@difizen/libro-lsp': patch
'@difizen/libro-markdown': patch
'@difizen/libro-markdown-cell': patch
'@difizen/libro-output': patch
'@difizen/libro-raw-cell': patch
'@difizen/libro-rendermime': patch
'@difizen/libro-search': patch
'@difizen/libro-search-code-cell': patch
'@difizen/libro-shared-model': patch
'@difizen/libro-sql-cell': patch
'@difizen/libro-terminal': patch
'@difizen/libro-toc': patch
'@difizen/libro-virtualized': patch
'@difizen/libro-widget': patch
---

feat: add interpreter for prompt cell
56 changes: 30 additions & 26 deletions packages/libro-prompt-cell/src/prompt-cell-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
Deferred,
} from '@difizen/mana-app';
import { l10n } from '@difizen/mana-l10n';
import { Select, Switch, Tag } from 'antd';
import { Select, Tag } from 'antd';
import type { DefaultOptionType } from 'antd/es/select/index.js';
import classNames from 'classnames';
import React, { useEffect, useState } from 'react';
Expand Down Expand Up @@ -109,14 +109,14 @@ const ChatObjectOptions = (type: string): ChatObjectOptions => {

const InterpreterMode = () => {
const instance = useInject<LibroPromptCellView>(ViewInstance);
const handleInterpreterSwitch = (checked: boolean) => {
instance.model.interpreterEnabled = checked;
if (instance.model.chatKey) {
instance.switchInterpreterMode(instance.model.chatKey, checked);
instance.model.promptOutput = undefined;
instance.model.interpreterCode = undefined;
}
};
// const handleInterpreterSwitch = (checked: boolean) => {
// instance.model.interpreterEnabled = checked;
// if (instance.model.chatKey) {
// instance.switchInterpreterMode(instance.model.chatKey, checked);
// instance.model.promptOutput = undefined;
// instance.model.interpreterCode = undefined;
// }
// };

if (instance.model.supportInterpreter === 'immutable') {
return (
Expand All @@ -126,20 +126,20 @@ const InterpreterMode = () => {
);
}

if (instance.model.supportInterpreter === 'dynamic') {
return (
<div>
<span className="libro-prompt-cell-interpreter-switch-tip">
{instance.model.interpreterEnabled ? '关闭 Interpreter' : '开启 Interpreter'}
</span>
<Switch
size="small"
className="libro-prompt-cell-interpreter-switch"
onChange={handleInterpreterSwitch}
/>
</div>
);
}
// if (instance.model.supportInterpreter === 'dynamic') {
// return (
// <div>
// <span className="libro-prompt-cell-interpreter-switch-tip">
// {instance.model.interpreterEnabled ? '关闭 Interpreter' : '开启 Interpreter'}
// </span>
// <Switch
// size="small"
// className="libro-prompt-cell-interpreter-switch"
// onChange={handleInterpreterSwitch}
// />
// </div>
// );
// }
return null;
};

Expand Down Expand Up @@ -206,7 +206,7 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handleChange = (value: string, options: DefaultOptionType) => {
const handleChange = (value: string, options?: DefaultOptionType) => {
instance.handleModelNameChange(value, options);
setSelectedModel(value);
};
Expand Down Expand Up @@ -327,8 +327,10 @@ export class LibroPromptCellView extends LibroEditableExecutableCellView {
this.model.mimeType = MIME.python;
this.outputArea.clear();
this.parent.enterEditMode();
this.parent.model.savable = false;
this.parent.model.runnable = false;
} else {
this.parent.model.savable = true;
this.model.interpreterCode = this.model.value;
this.model.mimeType = 'application/vnd.libro.prompt+json';
this.parent.model.runnable = true;
Expand Down Expand Up @@ -774,9 +776,11 @@ export class LibroPromptCellView extends LibroEditableExecutableCellView {
) > -1
);
};
handleModelNameChange = (value: string, option: DefaultOptionType) => {
handleModelNameChange = (value: string, option?: DefaultOptionType) => {
this.model.chatKey = value;
this.model.supportInterpreter = option['support_interpreter'];
if (option) {
this.model.supportInterpreter = option['support_interpreter'];
}
};
handleVariableNameChange = (value?: string) => {
this.model.variableName = value;
Expand Down

0 comments on commit 2324807

Please sign in to comment.