Promptrix. A prompt layout manager for LLMs
Project description
promptrix-py
Promptrix is a prompt layout engine for Large Language Models.
Here is a first trivial example:
from promptrix import promptrixTypes, VolatileMemory, FunctionRegistry, GPT3Tokenizer
from promptrix.Prompt import Prompt
from promptrix.SystemMessage import SystemMessage
from promptrix.UserMessage import UserMessage
from promptrix.AssistantMessage import AssistantMessage
from promptrix.ConversationHistory import ConversationHistory
functions = FunctionRegistry()
tokenizer = GPT3Tokenizer()
memory = VolatileMemory({'input':'', 'history':[]})
max_tokens = 2000
prompt_text = 'You are helpful, creative, clever, and very friendly. '
PROMPT = Prompt([
UserMessage(prompt_text),
ConversationHistory('history', .5), # allow history to use up 1/2 the remaining token budget left after the prompt and input
UserMessage('{{$input}}')
])
async def render_messages_completion():
as_msgs = await PROMPT.renderAsMessages(memory, functions, tokenizer, max_tokens)
msgs = []
if not as_msgs.tooLong:
msgs = as_msgs.output
return msgs
### basic chat loop
while True:
memory.set('input', query)
msgs = asyncio.run(render_messages_completion())
response = ... your favorite llm api (model, msgs, ...)
print(response)
history = memory.get('history')
history.append({'role':USER_PREFIX, 'content': query})
history.append({'role': ASSISTANT_PREFIX, 'content': response})
memory.set('history', history)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
promptrix-0.2.6.tar.gz
(9.4 kB
view hashes)
Built Distribution
promptrix-0.2.6-py3-none-any.whl
(13.2 kB
view hashes)
Close
Hashes for promptrix-0.2.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7f15763a788d780c765b73aea1f482c8676f47a374548c0192080577c7d6930 |
|
MD5 | 48f52e4ef8a45841ae65628a4009d59b |
|
BLAKE2b-256 | 486d9c41a1501a999abe6d7e5a913d20ada2fc7ce7e55a4c90715bf0f335a2e8 |