Spaces:
Sleeping
Sleeping
File size: 1,936 Bytes
579ab0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from typing import Tuple
from typing import List
from langchain.prompts.chat import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
)
from langchain_core.messages import BaseMessage
from langchain.docstore.document import Document
"""
Python file for getting the prompts and the respective templates.
"""
def get_system_prompt() -> Tuple[str, SystemMessagePromptTemplate]:
prompt_str = """You are an expert in information security, especially for ISO 27001 certifications. Answer the following question as truthfully as possible, using the provided context and not prior knowledge. If the answer is not contained within the context or the question is not related to the topic of information security or ISO 27001 or the question is not written in English, respond with 'I am sorry. I do not have knowledge on that topic'. Write a maximum of 400 words."""
template = SystemMessagePromptTemplate.from_template(prompt_str)
return prompt_str, template
def get_system_prompt_template() -> Tuple[str, SystemMessagePromptTemplate]:
prompt_str = f"""Answer the following question with that you can provide a template to the user and say that it is attached to this message. After that end your answer."""
template = SystemMessagePromptTemplate.from_template(prompt_str)
return prompt_str, template
def get_human_prompt(contexts: List[str], question: str) -> Tuple[str, HumanMessagePromptTemplate]:
prompt_str = f"""Question: {question} \n Context: {contexts}"""
template = HumanMessagePromptTemplate.from_template(prompt_str)
return prompt_str, template
def get_full_prompt(system_prompt: SystemMessagePromptTemplate, human_prompt: HumanMessagePromptTemplate) -> List[BaseMessage]:
full_prompt = ChatPromptTemplate.from_messages([system_prompt, human_prompt])
prompt_messages = full_prompt.format_prompt().to_messages()
return prompt_messages |