summaryrefslogtreecommitdiff
path: root/server/continuedev/plugins/steps/input/nl_multiselect.py
blob: f4b5e7a6f6b0f3cd8840429ebbf5c2fe2ab2a793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from typing import List, Union

from ....core.main import Step
from ....core.sdk import ContinueSDK
from ....core.steps import WaitForUserInputStep


class NLMultiselectStep(Step):
    hide: bool = True

    prompt: str
    options: List[str]

    async def run(self, sdk: ContinueSDK):
        user_response = (
            await sdk.run_step(WaitForUserInputStep(prompt=self.prompt))
        ).text

        def extract_option(text: str) -> Union[str, None]:
            for option in self.options:
                if option in text:
                    return option
            return None

        first_try = extract_option(user_response.lower())
        if first_try is not None:
            return first_try

        gpt_parsed = await sdk.models.default.complete(
            f"These are the available options are: [{', '.join(self.options)}]. The user requested {user_response}. This is the exact string from the options array that they selected:"
        )
        return extract_option(gpt_parsed) or self.options[0]