6
6
<a href="https://pypi.org/project/prompt-string/">
7
7
<img src="https://img.shields.io/pypi/v/prompt-string.svg">
8
8
</a>
9
+ <a href="https://github.com/memodb-io/prompt-string/actions/workflows/test.yml" >
10
+ <img src="https://github.com/memodb-io/prompt-string/actions/workflows/test.yml/badge.svg"/>
11
+ </a>
12
+ <a href="https://codecov.io/github/memodb-io/prompt-string" >
13
+ <img src="https://codecov.io/github/memodb-io/prompt-string/graph/badge.svg?token=kgeW8G0HYW"/>
14
+ </a>
9
15
</div >
10
16
11
17
12
18
19
+
13
20
Prompt is essentially a string, but it should behave somewhat differently from a standard string:
14
21
15
22
📏 ** Length & Slicing** : A prompt string should consider the length in terms of tokens, not characters, and slicing should be done accordingly.
@@ -46,9 +53,9 @@ from prompt_string import P
46
53
47
54
prompt = P(" you're a helpful assistant." )
48
55
49
- print (" Total token size" , len (prompt))
50
- print (" Decoded result of the second token" , prompt[2 ])
51
- print (" The decoded result of first five tokens" , prompt[:5 ])
56
+ print (" Total token size: " , len (prompt))
57
+ print (" Decoded result of the second token: " , prompt[2 ])
58
+ print (" The decoded result of first three tokens: " , prompt[:3 ])
52
59
```
53
60
54
61
` P ` supports some ` str ` native methods to still return a ` P ` object:
@@ -60,7 +67,7 @@ print("The decoded result of first five tokens", prompt[:5])
60
67
prompt = P(" you're a helpful assistant. {temp} " )
61
68
62
69
print (len (prompt.format(temp = " End of instructions" )))
63
- print (len (prompt.replace(" {temp} " , " " ))
70
+ print (len (prompt.replace(" {temp} " , " " )))
64
71
```
65
72
66
73
> 🧐 Raise an issue if you think other methods should be supported
@@ -75,7 +82,7 @@ from prompt_string import P
75
82
sp = P(" you're a helpful assistant." , role = " system" )
76
83
up = P(" How are you?" , role = " user" )
77
84
78
- print (sp.role, up.role, (sp+ up).roles )
85
+ print (sp.role, up.role, (sp+ up).role )
79
86
print (sp + up)
80
87
81
88
print (sp.message())
@@ -84,7 +91,7 @@ print(sp.message())
84
91
- role can be ` None ` , ` str ` for ` P `
85
92
- For single prompt, like ` sp ` , the role is ` str ` (* e.g.* ` system ` ) or ` None `
86
93
- ` sp+up ` will concatenate two prompt string and generate a new ` P ` , whose role will be updated if the latter one has one.
87
- - For example, `sp+ up` ' s role is `user`, `sp+P(' Hi' )`' s role is `system`
94
+ - For example, ` sp+up ` 's role is ` user ` ; ` sp+P('Hi') ` 's role is ` system `
88
95
89
96
90
97
- ` .message(...) ` return a JSON object of this prompt.
0 commit comments