# add apps directory to path ../apps/
import sys
sys.path.append("../demo")
from sagemaker_chat import create_gradio_app
# Generation arguments
parameters = {
"do_sample": True,
"top_p": 0.6,
"temperature": 0.9,
"top_k": 50,
"max_new_tokens": 1024,
"repetition_penalty": 1.03,
"return_full_text": False,
"stop": [""]
}
# define format function for our input
def format_prompt(message, history, system_prompt):
prompt = ""
for user_prompt, bot_response in history:
prompt = f" [INST] {user_prompt} [/INST] {bot_response}"
prompt += f"### Instruction\n{user_prompt}\n\n"
prompt += f"### Answer\n{bot_response}\n\n" # Response already contains "Falcon: "
# add new user prompt if history is not empty
if len(history) > 0:
prompt += f" [INST] {message} [/INST] "
else:
prompt += f" [INST] {message} [/INST] "
return prompt
# create gradio app
create_gradio_app(
llm.endpoint_name, # Sagemaker endpoint name
session=sess.boto_session, # boto3 session used to send request
parameters=parameters, # Request parameters
system_prompt=None, # System prompt to use -> Mistral does not support system prompts
format_prompt=format_prompt, # Function to format prompt
concurrency_count=4, # Number of concurrent requests
share=True, # Share app publicly
)