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 {
MathService,
FullScreenService,
FullScreenToolGroupService,
// ExternalAPIContentService,
} from 'wax-prosemirror-services';
import { QuestionsService } from 'wax-questions-service';
......@@ -21,71 +20,6 @@ import { TablesService, tableEditing, columnResizing } from 'wax-table-service';
import { DefaultSchema } from 'wax-prosemirror-core';
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 {
MenuService: [
......@@ -107,7 +41,6 @@ export default {
'Lists',
'Images',
'Tables',
// 'ExternalAPIContent',
'QuestionsDropDown',
'FullScreen',
],
......@@ -120,10 +53,11 @@ export default {
templateArea: 'MultipleDropDown',
toolGroups: ['MultipleDropDown'],
},
{
templateArea: 'NumericalAnswer',
toolGroups: ['NumericalAnswer'],
},
],
// ExternalAPIContentService: {
// ExternalAPIContentTransformation: ExternalAPIContentTransformation,
// },
SchemaService: DefaultSchema,
RulesService: [emDash, ellipsis],
......@@ -131,7 +65,6 @@ export default {
PmPlugins: [invisibles([hardBreak()])],
services: [
// new ExternalAPIContentService(),
new QuestionsService(),
new ListsService(),
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'
import NumericalAnswerQuestion from './NumericalAnswerQuestion';
import NumericalAnswerContainerNodeView from './NumericalAnswerContainerNodeView';
import NumericalAnswerContainerComponent from './components/NumericalAnswerContainerComponent';
import NumericalAnswerDropDownService from './NumericalAnswerDropDownService/NumericalAnswerDropDownService';
import './numericalAnswer.css';
class NumericalAnswerService extends Service {
......@@ -22,7 +23,7 @@ class NumericalAnswerService extends Service {
});
}
dependencies = [];
dependencies = [new NumericalAnswerDropDownService()];
}
export default NumericalAnswerService;
......@@ -4,9 +4,9 @@ import { ToolGroup } from 'wax-prosemirror-core';
@injectable()
class NumericalAnswer extends ToolGroup {
tools = [];
constructor() {
constructor(@inject('NumericalAnswerDropDown') NumericalAnswerDropDown) {
super();
this.tools = [];
this.tools = [NumericalAnswerDropDown];
}
}
......
......@@ -53,7 +53,7 @@ export default ({ node, view, getPos }) => {
pmViews: { main },
} = context;
const FillTheGapTool = ComponentPlugin('fillTheGap');
const NumericalAnswerTool = ComponentPlugin('NumericalAnswer');
const customProps = main.props.customValues;
const { testMode } = customProps;
......@@ -84,7 +84,7 @@ export default ({ node, view, getPos }) => {
<div>
{!testMode && !readOnly && (
<NumericalAnswerContainerTool>
<FillTheGapTool />
<NumericalAnswerTool />
<ActionButton
aria-label="delete this question"
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