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
2.4 KiB
2.4 KiB
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
- ChatGPT+ Vector database + prompt-as-code - The CVP Stack - Zilliz blog: Extend the capability of ChatGPT with a Vector database and prompts-as-code
- What is Prompt as Code (Prompt Engineering): Explores what prompt engineering is, how it works in NLP, and best practices for effective prompt engineering.
- An LLM Powered Text to Image Prompt Generation with Milvus - Zilliz blog: An interesting LLM project powered by the Milvus vector database for generating more efficient text-to-image prompts.
- Prompting in LangChain - Zilliz blog: Prompting is one of today's most popular and important tasks in AI app building. Learn how to use LangChain for more complex prompts.
- What is Prompt Chaining: Prompt chaining in NLP uses structured prompts to break a complex task into smaller subtasks. This sequential approach improves coherence and accuracy in LLM outputs.
2.4 KiB
2.4 KiB
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
- ChatGPT+ Vector database + prompt-as-code - The CVP Stack - Zilliz blog: Extend the capability of ChatGPT with a Vector database and prompts-as-code
- What is Prompt as Code (Prompt Engineering): Explores what prompt engineering is, how it works in NLP, and best practices for effective prompt engineering.
- An LLM Powered Text to Image Prompt Generation with Milvus - Zilliz blog: An interesting LLM project powered by the Milvus vector database for generating more efficient text-to-image prompts.
- Prompting in LangChain - Zilliz blog: Prompting is one of today's most popular and important tasks in AI app building. Learn how to use LangChain for more complex prompts.
- What is Prompt Chaining: Prompt chaining in NLP uses structured prompts to break a complex task into smaller subtasks. This sequential approach improves coherence and accuracy in LLM outputs.