Skip to content

Commit

Permalink
ESLint work and happy
Browse files Browse the repository at this point in the history
  • Loading branch information
hejny committed Oct 26, 2023
1 parent d4bef34 commit cf0ed03
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 155 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ module.exports = {
},
plugins: ['@typescript-eslint'],
rules: {
indent: ['error', 4],
// Note: Indentation is fully managed by Prettier
// indent: ['error', 4],
'linebreak-style': ['error', 'unix'],

// Note: There are places I want to use ${variable} in strings but not using yet
// quotes: ['error', 'single'],
semi: ['error', 'always'],
},
Expand Down
3 changes: 2 additions & 1 deletion src/classes/PromptTemplatePipelineLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export class PromptTemplatePipelineLibrary {
* Checks whether prompt is in the library
*/
public isPromptInLibrary(prompt: Prompt): boolean {
// TODO: DO not hardcode this, really validate whether the prompt is in the library
// TODO: [🎛] DO not hardcode this, really validate whether the prompt is in the library
prompt;
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/conversion/parseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function parseCommand(listItem: string_markdown_text): Command {
let type = listItem.trim();
type = type.split('`').join('');
type = type.split('"').join('');
type = type.split('\'').join('');
type = type.split("'").join('');
type = type.split('~').join('');
type = type.split('[').join('');
type = type.split(']').join('');
Expand Down Expand Up @@ -146,12 +146,12 @@ export function parseCommand(listItem: string_markdown_text): Command {
throw new Error(
spaceTrim(
(block) => `
Unknown variant in command:
Unknown variant in command:
- ${listItem}
- ${listItem}
Supported variants are:
${block(['CHAT', 'COMPLETION'].join(', '))}
Supported variants are:
${block(['CHAT', 'COMPLETION'].join(', '))}
`,
),
);
Expand Down Expand Up @@ -187,7 +187,7 @@ export function parseCommand(listItem: string_markdown_text): Command {
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
throw new Error(
spaceTrim(
(block) => `
`
Parameter {${parameterName}} can not contain another parameter in description:
- ${listItem}
Expand Down
105 changes: 54 additions & 51 deletions src/conversion/promptTemplatePipelineStringToJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DEFAULT_MODEL_REQUIREMENTS, PTP_VERSION } from '../config';
import { ParameterCommand, PostprocessCommand } from '../types/Command';
import { ExecutionType } from '../types/ExecutionTypes';
import { ModelRequirements } from '../types/ModelRequirements';
import { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
import { ScriptLanguage, SUPPORTED_SCRIPT_LANGUAGES } from '../types/ScriptLanguage';
Expand Down Expand Up @@ -50,7 +51,9 @@ export function promptTemplatePipelineStringToJson(
const addParam = (parameterCommand: Omit<ParameterCommand, 'type'>) => {
const { parameterName, parameterDescription, isInputParameter } = parameterCommand;

const existingParameter = ptpJson.parameters.find((parameter) => parameter.name === parameterName);
const existingParameter = ptpJson.parameters.find(
(parameter: PromptTemplateParameterJson) => parameter.name === parameterName,
);
if (
existingParameter &&
existingParameter.description &&
Expand Down Expand Up @@ -121,26 +124,26 @@ export function promptTemplatePipelineStringToJson(
const command = parseCommand(listItem);

switch (command.type) {
case 'PTP_URL':
ptpJson.ptpUrl = command.ptpUrl.href;
break;
case 'PTP_URL':
ptpJson.ptpUrl = command.ptpUrl.href;
break;

case 'PTP_VERSION':
ptpJson.ptpVersion = command.ptpVersion;
break;
case 'PTP_VERSION':
ptpJson.ptpVersion = command.ptpVersion;
break;

case 'USE':
defaultModelRequirements[command.key] = command.value;
break;
case 'USE':
defaultModelRequirements[command.key] = command.value;
break;

case 'PARAMETER':
addParam(command);
break;
case 'PARAMETER':
addParam(command);
break;

default:
throw new Error(
`Command ${command.type} is not allowed in the head of the prompt template pipeline ONLY at the prompt template block`,
);
default:
throw new Error(
`Command ${command.type} is not allowed in the head of the prompt template pipeline ONLY at the prompt template block`,
);
}
}

Expand All @@ -156,32 +159,32 @@ export function promptTemplatePipelineStringToJson(
for (const listItem of listItems) {
const command = parseCommand(listItem);
switch (command.type) {
case 'EXECUTE':
if (isExecutionTypeChanged) {
case 'EXECUTE':
if (isExecutionTypeChanged) {
throw new Error(
'Execution type is already defined in the prompt template. It can be defined only once.',
);
}
executionType = command.executionType;
isExecutionTypeChanged = true;
break;

case 'USE':
templateModelRequirements[command.key] = command.value;
break;

case 'PARAMETER':
addParam(command);
break;

case 'POSTPROCESS':
postprocessingCommands.push(command);
break;

default:
throw new Error(
'Execution type is already defined in the prompt template. It can be defined only once.',
`Command ${command.type} is not allowed in the block of the prompt template ONLY at the head of the prompt template pipeline`,
);
}
executionType = command.executionType;
isExecutionTypeChanged = true;
break;

case 'USE':
templateModelRequirements[command.key] = command.value;
break;

case 'PARAMETER':
addParam(command);
break;

case 'POSTPROCESS':
postprocessingCommands.push(command);
break;

default:
throw new Error(
`Command ${command.type} is not allowed in the block of the prompt template ONLY at the head of the prompt template pipeline`,
);
}
}

Expand All @@ -206,7 +209,7 @@ export function promptTemplatePipelineStringToJson(
}

const lastLine = section.content.split('\n').pop()!;
const match = /^\-\>\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
const match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
throw new Error(
spaceTrim(
Expand All @@ -215,12 +218,12 @@ export function promptTemplatePipelineStringToJson(
Invalid section:
${block(
// TODO: Show code of invalid sections each time + DRY
section.content
.split('\n')
.map((line) => `> ${line}`)
.join('\n'),
)}
// TODO: Show code of invalid sections each time + DRY
section.content
.split('\n')
.map((line) => `> ${line}`)
.join('\n'),
)}
`,
),
);
Expand All @@ -244,9 +247,9 @@ export function promptTemplatePipelineStringToJson(
postprocessingCommands.length <= i
? resultingParameterName
: normalizeTo_camelCase(
`${resultingParameterName} before ${postprocessingCommands[i]!.functionName}`,
// <- TODO: Make this work even if using multiple same postprocessing functions
);
`${resultingParameterName} before ${postprocessingCommands[i]!.functionName}`,
// <- TODO: Make this work even if using multiple same postprocessing functions
);

const isParameterDefined = ptpJson.parameters.some((parameter) => parameter.name === parameterName);

Expand Down
Loading

0 comments on commit cf0ed03

Please sign in to comment.