Skip to content
Snippets Groups Projects
Commit 13ef4568 authored by chris's avatar chris
Browse files

connect new tool

parent 9480887a
No related branches found
No related tags found
1 merge request!511Numerical answer
...@@ -13,7 +13,6 @@ import { ...@@ -13,7 +13,6 @@ import {
MathService, MathService,
FullScreenService, FullScreenService,
FullScreenToolGroupService, FullScreenToolGroupService,
// ExternalAPIContentService,
} from 'wax-prosemirror-services'; } from 'wax-prosemirror-services';
import { QuestionsService } from 'wax-questions-service'; import { QuestionsService } from 'wax-questions-service';
...@@ -21,71 +20,6 @@ import { TablesService, tableEditing, columnResizing } from 'wax-table-service'; ...@@ -21,71 +20,6 @@ import { TablesService, tableEditing, columnResizing } from 'wax-table-service';
import { DefaultSchema } from 'wax-prosemirror-core'; import { DefaultSchema } from 'wax-prosemirror-core';
import invisibles, { hardBreak } from '@guardian/prosemirror-invisibles'; import invisibles, { hardBreak } from '@guardian/prosemirror-invisibles';
const API_KEY = '';
async function ExternalAPIContentTransformation(prompt) {
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`,
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'user',
content: prompt,
},
],
temperature: 0,
// max_tokens: 400,
// n: 1,
// stop: null,
}),
});
try {
const data = await response.json();
console.log(data);
return data.choices[0].message.content;
} catch (e) {
console.error(e);
alert(
'That model is currently overloaded with other requests. You can retry your request.',
);
} finally {
}
return prompt;
}
// async function ExternalAPIContentTransformation(prompt) {
// const response = await fetch('https://api.openai.com/v1/completions', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// Authorization: `Bearer ${API_KEY}`,
// },
// body: JSON.stringify({
// model: 'text-davinci-003',
// prompt: prompt,
// max_tokens: 1400,
// n: 1,
// stop: null,
// temperature: 0.5,
// }),
// });
// try {
// const data = await response.json();
// console.log(data);
// return data.choices[0].text.trim();
// } catch (e) {
// console.error(e);
// } finally {
// }
// return prompt;
// }
export default { export default {
MenuService: [ MenuService: [
...@@ -107,7 +41,6 @@ export default { ...@@ -107,7 +41,6 @@ export default {
'Lists', 'Lists',
'Images', 'Images',
'Tables', 'Tables',
// 'ExternalAPIContent',
'QuestionsDropDown', 'QuestionsDropDown',
'FullScreen', 'FullScreen',
], ],
...@@ -120,10 +53,11 @@ export default { ...@@ -120,10 +53,11 @@ export default {
templateArea: 'MultipleDropDown', templateArea: 'MultipleDropDown',
toolGroups: ['MultipleDropDown'], toolGroups: ['MultipleDropDown'],
}, },
{
templateArea: 'NumericalAnswer',
toolGroups: ['NumericalAnswer'],
},
], ],
// ExternalAPIContentService: {
// ExternalAPIContentTransformation: ExternalAPIContentTransformation,
// },
SchemaService: DefaultSchema, SchemaService: DefaultSchema,
RulesService: [emDash, ellipsis], RulesService: [emDash, ellipsis],
...@@ -131,7 +65,6 @@ export default { ...@@ -131,7 +65,6 @@ export default {
PmPlugins: [invisibles([hardBreak()])], PmPlugins: [invisibles([hardBreak()])],
services: [ services: [
// new ExternalAPIContentService(),
new QuestionsService(), new QuestionsService(),
new ListsService(), new ListsService(),
new LinkService(), new LinkService(),
......
import { injectable } from 'inversify';
import { Fragment } from 'prosemirror-model';
import { v4 as uuidv4 } from 'uuid';
import { Tools } from 'wax-prosemirror-core';
@injectable()
class NumericalAnswerDropDown extends Tools {
title = 'Select Numerical Answer Option';
icon = '';
name = 'Select Numerical Answer';
label = 'Select Numerical Answer';
get run() {}
select = (state, activeViewId, activeView) => {
if (activeView.props.type && activeView.props.type === 'filltheGapContaier')
return true;
return false;
};
}
export default NumericalAnswerDropDown;
import { Service } from 'wax-prosemirror-core';
import NumericalAnswerDropDown from './NumericalAnswerDropDown';
import NumericalAnswerToolGroupService from '../NumericalAnswerToolGroupService/NumericalAnswerToolGroupService';
class NumericalAnswerDropDownService extends Service {
register() {
this.container.bind('NumericalAnswerDropDown').to(NumericalAnswerDropDown);
}
dependencies = [new NumericalAnswerToolGroupService()];
}
export default NumericalAnswerDropDownService;
...@@ -3,6 +3,7 @@ import NumericalAnswerContainerNode from './schema/NumericalAnswerContainerNode' ...@@ -3,6 +3,7 @@ import NumericalAnswerContainerNode from './schema/NumericalAnswerContainerNode'
import NumericalAnswerQuestion from './NumericalAnswerQuestion'; import NumericalAnswerQuestion from './NumericalAnswerQuestion';
import NumericalAnswerContainerNodeView from './NumericalAnswerContainerNodeView'; import NumericalAnswerContainerNodeView from './NumericalAnswerContainerNodeView';
import NumericalAnswerContainerComponent from './components/NumericalAnswerContainerComponent'; import NumericalAnswerContainerComponent from './components/NumericalAnswerContainerComponent';
import NumericalAnswerDropDownService from './NumericalAnswerDropDownService/NumericalAnswerDropDownService';
import './numericalAnswer.css'; import './numericalAnswer.css';
class NumericalAnswerService extends Service { class NumericalAnswerService extends Service {
...@@ -22,7 +23,7 @@ class NumericalAnswerService extends Service { ...@@ -22,7 +23,7 @@ class NumericalAnswerService extends Service {
}); });
} }
dependencies = []; dependencies = [new NumericalAnswerDropDownService()];
} }
export default NumericalAnswerService; export default NumericalAnswerService;
...@@ -4,9 +4,9 @@ import { ToolGroup } from 'wax-prosemirror-core'; ...@@ -4,9 +4,9 @@ import { ToolGroup } from 'wax-prosemirror-core';
@injectable() @injectable()
class NumericalAnswer extends ToolGroup { class NumericalAnswer extends ToolGroup {
tools = []; tools = [];
constructor() { constructor(@inject('NumericalAnswerDropDown') NumericalAnswerDropDown) {
super(); super();
this.tools = []; this.tools = [NumericalAnswerDropDown];
} }
} }
......
...@@ -53,7 +53,7 @@ export default ({ node, view, getPos }) => { ...@@ -53,7 +53,7 @@ export default ({ node, view, getPos }) => {
pmViews: { main }, pmViews: { main },
} = context; } = context;
const FillTheGapTool = ComponentPlugin('fillTheGap'); const NumericalAnswerTool = ComponentPlugin('NumericalAnswer');
const customProps = main.props.customValues; const customProps = main.props.customValues;
const { testMode } = customProps; const { testMode } = customProps;
...@@ -84,7 +84,7 @@ export default ({ node, view, getPos }) => { ...@@ -84,7 +84,7 @@ export default ({ node, view, getPos }) => {
<div> <div>
{!testMode && !readOnly && ( {!testMode && !readOnly && (
<NumericalAnswerContainerTool> <NumericalAnswerContainerTool>
<FillTheGapTool /> <NumericalAnswerTool />
<ActionButton <ActionButton
aria-label="delete this question" aria-label="delete this question"
onClick={removeQuestion} onClick={removeQuestion}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment