1
1
import asyncio
2
+ import inspect
2
3
import json
3
4
from importlib import import_module
4
5
from pathlib import Path
9
10
from ragbits .cli import print_output
10
11
from ragbits .core .config import core_config
11
12
from ragbits .core .llms .base import LLM , LLMType
13
+ from ragbits .core .prompt .discovery import PromptDiscovery
12
14
from ragbits .core .prompt .prompt import ChatFormat , Prompt
13
15
14
16
prompts_app = typer .Typer (no_args_is_help = True )
@@ -21,6 +23,16 @@ class LLMResponseCliOutput(BaseModel):
21
23
answer : str | BaseModel | None = None
22
24
23
25
26
+ class PromptInfo (BaseModel ):
27
+ """Information about a Prompt class for CLI display"""
28
+
29
+ name : str
30
+ import_path : str
31
+ description : str
32
+ input_type : str
33
+ output_type : str
34
+
35
+
24
36
def _render (prompt_path : str , payload : str | None ) -> Prompt :
25
37
module_stringified , object_stringified = prompt_path .split (":" )
26
38
prompt_cls = getattr (import_module (module_stringified ), object_stringified )
@@ -34,7 +46,7 @@ def _render(prompt_path: str, payload: str | None) -> Prompt:
34
46
35
47
36
48
@prompts_app .command ()
37
- def generate_promptfoo_configs (
49
+ def promptfoo (
38
50
file_pattern : str = core_config .prompt_path_pattern ,
39
51
root_path : Path = Path .cwd (), # noqa: B008
40
52
target_path : Path = Path ("promptfooconfigs" ),
@@ -49,6 +61,25 @@ def generate_promptfoo_configs(
49
61
generate_configs (file_pattern = file_pattern , root_path = root_path , target_path = target_path )
50
62
51
63
64
+ @prompts_app .command ()
65
+ def search (file_pattern : str = core_config .prompt_path_pattern , root_path : Path = Path .cwd ()) -> None : # noqa: B008
66
+ """
67
+ Lists all available prompts that can be used with the 'render' and 'exec' commands.
68
+ """
69
+ prompt_classes = PromptDiscovery (file_pattern = file_pattern , root_path = root_path ).discover ()
70
+ prompt_infos = [
71
+ PromptInfo (
72
+ name = prompt_cls .__name__ ,
73
+ import_path = f"{ prompt_cls .__module__ } :{ prompt_cls .__name__ } " ,
74
+ description = inspect .getdoc (prompt_cls ) or "" ,
75
+ input_type = getattr (prompt_cls .input_type , "__name__" , str (prompt_cls .input_type )),
76
+ output_type = getattr (prompt_cls .output_type , "__name__" , str (prompt_cls .output_type )),
77
+ )
78
+ for prompt_cls in prompt_classes
79
+ ]
80
+ print_output (prompt_infos )
81
+
82
+
52
83
@prompts_app .command ()
53
84
def render (prompt_path : str , payload : str | None = None ) -> None :
54
85
"""
0 commit comments