66 <a href="https://pypi.org/project/prompt-string/">
77 <img src="https://img.shields.io/pypi/v/prompt-string.svg">
88 </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>
915</div >
1016
1117
1218
19+
1320Prompt is essentially a string, but it should behave somewhat differently from a standard string:
1421
1522📏 ** 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
4653
4754prompt = P(" you're a helpful assistant." )
4855
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 ])
5259```
5360
5461` 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])
6067prompt = P(" you're a helpful assistant. {temp} " )
6168
6269print (len (prompt.format(temp = " End of instructions" )))
63- print (len (prompt.replace(" {temp} " , " " ))
70+ print (len (prompt.replace(" {temp} " , " " )))
6471```
6572
6673> 🧐 Raise an issue if you think other methods should be supported
@@ -75,7 +82,7 @@ from prompt_string import P
7582sp = P(" you're a helpful assistant." , role = " system" )
7683up = P(" How are you?" , role = " user" )
7784
78- print (sp.role, up.role, (sp+ up).roles )
85+ print (sp.role, up.role, (sp+ up).role )
7986print (sp + up)
8087
8188print (sp.message())
@@ -84,7 +91,7 @@ print(sp.message())
8491- role can be ` None ` , ` str ` for ` P `
8592- For single prompt, like ` sp ` , the role is ` str ` (* e.g.* ` system ` ) or ` None `
8693- ` 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 `
8895
8996
9097- ` .message(...) ` return a JSON object of this prompt.
0 commit comments