logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

Updated 10 months ago

prompt

Prompt Template


Desription

Prompt Template.


Code Example

Example


from towhee import ops, pipe
import requests

towhee_docs = requests.get('https://raw.githubusercontent.com/towhee-io/towhee/main/README.md').content

temp = """{question}

input:
{context}
"""

sys_message = """Your name is TowheeChat."""

p = (
    pipe.input('question', 'doc', 'history')
    .map('doc', 'doc', lambda x: x[:2000])
    .map(('question', 'doc', 'history'), 'prompt', ops.prompt.template(temp, ['question', 'context'], sys_message))
    .map('prompt', 'answer', ops.LLM.OpenAI())
    .output('answer')
)

an1 = p('What is your name?', [], []).get()[0]
print(an1)

an2 = p('Tell me something about Towhee', towhee_docs, []).get()[0]
print(an2)

an3 = p('How to use it', towhee_docs, [('Tell me something about Towhee', an2)]).get()[0]
print(an3)

Factory Constructor

Create the operator via the following factory method:

ops.prompt.template(temp, keys, sys_msg)

Parameters:

temp: str

​ A template to create a prompt as the last user message.

keys: list

​ A list of keys used in template.

sys_msg: str=None

​ A system message, defaults to None. If None, it will not pass any system message.


Returns: List[Dict]

More Resources

Jael Gu f3e3eb2424 Add more resources 14 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 2 years ago
file-icon README.md
2.4 KiB
download-icon
Add more resources 10 months ago
file-icon __init__.py
143 B
download-icon
Add system message 2 years ago
file-icon template_prompt.py
1.0 KiB
download-icon
Add system message 2 years ago