ScottLogic / prompt-injection

Application which investigates defensive measures against prompt injection attacks on an LLM, with a focus on the exposure of external tools.
MIT License
16 stars 10 forks source link

Import services methods in object rather than separately #820

Closed pmarsh-scottlogic closed 8 months ago

pmarsh-scottlogic commented 8 months ago

Description

In the frontend we now import service methods like import * as someService from '@src/service/someService' then do someService.serviceMethod() in the code.

This is to clear up the many instances of confusing code like

function addInfoMessage(message: string) {
    addChatMessage({
        message,
        type: 'GENERIC_INFO',
    });
    // asynchronously add message to chat history
    void addInfoMessageToChatHistory(message, 'GENERIC_INFO', currentLevel);
}

where it is not clear what things will call the api and which things are only doing things in the frontend.

Concerns

Checklist

Have you done the following?

chriswilty commented 8 months ago

I wonder if there is a way to enforce that we import from our services like this

There is, kind of: use an index.ts file in @src/service, and inside that put e.g.

import * as chatService from './chatService';
import * as configService from './configService';

export {
  chatService,
  configService,
}

Then you would import your services from the directory:

import { chatService } from '@src/service';

You can enforce directory-level imports in eslint config, if I recall, but we're not ready for that yet as we'd need index files throughout our codebase. That was on my (distant) todo list at some stage.