Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lambda.tf and index.py files #65

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lambdas/inference/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ module "lambda_function_container_image" {
TOP_P = 0.99
RELEVANCE_THRESHOLD = 0.67
MODEL_ID = "anthropic.claude-instant-v1"
EMBEDDING_COLLECTION_NAME = var.embedding_collection_name
SYSTEM_PROMPT = "Answer in french."
CHAT_INTENT_NAME = "global"

SYSTEM_PROMPT = "Answer in french."
EMAIL_PROMPT = "You are currently answering an email so your answer can be more detailed. After you finish answering the initial query generate follow-up questions and answer it too up to 4 questions.\n"
CALL_PROMPT = "Make your answer short and concise.\n"
CHAT_PROMPT = "You are currently answering a message.\n"
DOCUMENT_PROMPT = "Here is a set of quotes between <quotes></quotes> XML tags to help you answer: <quotes>{docs_context}</quotes>.\n"
NO_DOCUMENT_FOUND_PROMPT = "You could not find any relevant quotes to help answer the user's query. Therefore just say that you cannot help furthermore with the user's query, whatever his request is.\n"
HISTORY_PROMPT = "Here is the history of the previous messages history between <history></history> XML tags: <history>{}</history>."
}
policy_statements = {
log_group = {
Expand Down
29 changes: 20 additions & 9 deletions lambdas/inference/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def prepare_prompt(query: str, docs: list, history: list, source: str):
final_prompt = f"""{source_prompt}
{document_prompt}
{history_prompt}
{ENV_VARS['system_prompt']}\n
{os.environ.get("SYSTEM_PROMPT", "Answer in french.")}\n
\n\nHuman:{query}
\n\nAssistant:"""

Expand All @@ -42,20 +42,29 @@ def prepare_prompt(query: str, docs: list, history: list, source: str):

def prepare_source_prompt(source: str):
if source == "email":
return """You are currently answering an email so your answer can be more detailed.
After you finish answering the initial query generate follow-up questions and answer it too up to 4 questions.\n"""
return os.environ.get(
"EMAIL_PROMPT", "FALLBACK - You are currently answering an email\n"
)
elif source == "call":
return "Make your answer short and concise.\n"
return os.environ.get(
"CALL_PROMPT", "FALLBACK - Make your answer short and concise.\n"
)
else:
return "You are currently answering a message.\n"
return os.environ.get(
"CHAT_PROMPT", "FALLBACK - Make your answer short and concise.\n"
)


def prepare_document_prompt(docs):
if len(docs) > 0:
docs_context = ".\n".join(doc[0].page_content for doc in docs)
return f"Here is a set of quotes between <quotes></quotes> XML tags to help you answer: <quotes>{docs_context}</quotes>.\n"
return """You could not find any relevant quotes to help answer the user's query.
Therefore just say that you cannot help furthermore with the user's query, whatever his request is.\n"""
return os.environ.get(
"DOCUMENT_PROMPT", "Here are some relevant quotes:\n{}\n"
).format(docs_context)
return os.environ.get(
"NO_DOCUMENT_FOUND_PROMPT",
"You could not find any relevant quotes to help answer the user's query.",
)


def prepare_history_prompt(history):
Expand All @@ -64,7 +73,9 @@ def prepare_history_prompt(history):
f"Human:{x['HumanMessage']}\nAssistant:{x['AssistantMessage']}"
for x in history
)
return f"Here is the history of the previous messages history between <history></history> XML tags: <history>{history_context}</history>."
return os.environ.get(
"HISTORY_PROMPT", "Here is the conversation history:\n{}\n"
).format(history_context)
return ""


Expand Down
Loading