Skip to content

Commit 15ad998

Browse files
committed
docs: add spec
1 parent e4f6184 commit 15ad998

File tree

8 files changed

+132
-0
lines changed

8 files changed

+132
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Created by https://www.toptal.com/developers/gitignore/api/python
22
# Edit at https://www.toptal.com/developers/gitignore?templates=python
33

4+
.DS_Store
45
### Python ###
56
# Byte-compiled / optimized / DLL files
67
__pycache__/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include readme.md

prompt_string/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__author__ = "Gus Ye"
2+
__version__ = "0.0.1.dev"
3+
__url__ = "https://github.com/memodb/prompt-string"
4+
5+
print("prompt-string is testing")

prompt_string/types.py

Whitespace-only changes.

readme.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<div align="center">
2+
<h1><code>prompt-string</code></h1>
3+
<p><strong>Treat prompt as a data type in Python</strong></p>
4+
<p>
5+
<img src="https://img.shields.io/badge/python->=3.11-blue">
6+
<a href="https://pypi.org/project/prompt-string/">
7+
<img src="https://img.shields.io/pypi/v/prompt-string.svg">
8+
</a>
9+
</div>
10+
11+
12+
13+
Prompt is essentially a string, but it should behave somewhat differently from a standard string:
14+
15+
📏 **Length & Slicing**: A prompt string should consider the length in terms of tokens, not characters, and slicing should be done accordingly.
16+
17+
👨 **Role & Concatenation**: Prompt strings should have designated roles (e.g., `system`, `user`, `assistant`) and should be concatenated in a specific manner.
18+
19+
🦆 **Binding Functions**: A prompt string contains logic and instructions, so having some binding functions for AI-related stuff is beneficial and necessary (e.g., convert to OpenAI Message Format).
20+
21+
22+
23+
**Few promises in `prompt-string`:**
24+
25+
- `prompt-string` inherits from `string`. Therefore, aside from the mentioned features, its other behaviors are just like those of a `string` in Python.
26+
- `prompt-string` won't add OpenAI and other AI SDKs as dependencies; it is simply a toolkit for prompts.
27+
- `prompt-string` will be super light and fast, with no heavy processes running behind the scenes.
28+
29+
30+
31+
## Install
32+
33+
```bash
34+
pip install prompt-string
35+
```
36+
37+
38+
39+
## Quick Start
40+
41+
#### Length & Slicing
42+
43+
```python
44+
from prompt_string import P
45+
46+
prompt = P("you're a helpful assistant.")
47+
48+
print("Total token size", len(prompt))
49+
print("Decoded result of the second token", prompt[2])
50+
print("The decoded result of first five tokens", prompt[:5])
51+
```
52+
53+
54+
55+
#### Role & Concatenation
56+
57+
```python
58+
from prompt_string import P
59+
60+
sp = P("you're a helpful assistant.", "system")
61+
up = P("How are you?", "user")
62+
63+
print(sp.role, up.role, (sp+up).role)
64+
print(sp + up)
65+
```
66+
67+
- role can be `None`, `str`, `list[str]`
68+
- For single prompt, like `sp`, the role is `str`(*e.g.* `system`) or `None`
69+
- For concatenated prompts, like `sp+up`, the role is `list[str]`(*e.g.* `['system', 'user']`)
70+
71+
72+
73+
#### Binding Functions
74+
75+
```python
76+
from prompt_string import P
77+
78+
sp = P("you're a helpful assistant.")
79+
up = P("How are you?")
80+
81+
print((sp+up).messages())
82+
```
83+
84+
- `messages` will return the OpenAI-Compatible messages format, where you can directly pass it to `client.chat.completions.create(messages=...)`

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tiktoken

setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import setuptools
2+
from setuptools import find_packages
3+
4+
with open("readme.md", "r") as fh:
5+
long_description = fh.read()
6+
7+
8+
vars2find = ["__author__", "__version__", "__url__"]
9+
vars2readme = {}
10+
with open("./prompt_string/__init__.py") as f:
11+
for line in f.readlines():
12+
for v in vars2find:
13+
if line.startswith(v):
14+
line = line.replace(" ", "").replace('"', "").replace("'", "").strip()
15+
vars2readme[v] = line.split("=")[1]
16+
17+
deps = []
18+
with open("./requirements.txt") as f:
19+
for line in f.readlines():
20+
if not line.strip():
21+
continue
22+
deps.append(line.strip())
23+
24+
setuptools.setup(
25+
name="prompt-string",
26+
url=vars2readme["__url__"],
27+
version=vars2readme["__version__"],
28+
author=vars2readme["__author__"],
29+
description="Treat prompt as a data type in Python",
30+
long_description=long_description,
31+
long_description_content_type="text/markdown",
32+
packages=find_packages(exclude=["tests"]),
33+
classifiers=[
34+
"Programming Language :: Python :: 3",
35+
"License :: OSI Approved :: MIT License",
36+
"Operating System :: OS Independent",
37+
],
38+
python_requires=">=3.11",
39+
install_requires=deps,
40+
)

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)