Spaces:
Runtime error
Runtime error
# import gradio as gr | |
# from langchain_community.llms import CTransformers | |
# from langchain_core.messages import HumanMessage, SystemMessage | |
# llm = CTransformers(model="TheBloke/Llama-2-7B-Chat-GGML", model_file="llama-2-7b-chat.ggmlv3.q3_K_S.bin") | |
# def greet(prompt): | |
# messages = [ | |
# SystemMessage(content="You're a helpful assistant"), | |
# HumanMessage(content=prompt), | |
# ] | |
# return llm(messages) | |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
# iface.launch() | |
from langchain import PromptTemplate | |
from langchain import LLMChain | |
from langchain.llms import CTransformers | |
B_INST, E_INST = "[INST]", "[/INST]" | |
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n" | |
DEFAULT_SYSTEM_PROMPT="""\ | |
You are a helpful, respectful, and honest assistant designed to improve English language skills. Always provide accurate and helpful responses to language improvement tasks, while ensuring safety and ethical standards. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased, positive, and focused on enhancing language skills. | |
If a question does not make sense or is not factually coherent, explain why instead of answering something incorrect. If you don't know the answer to a question, please don't share false information. | |
Your role is to guide users through various language exercises and challenges, helping them to practice and improve their English skills in a fun and engaging way. Always encourage users to try different approaches and provide constructive feedback to help them progress. | |
""" | |
# DEFAULT_SYSTEM_PROMPT = """\ | |
# You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. | |
# If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.""" | |
# Update the model path to use the Hugging Face model identifier | |
llm = CTransformers(model="TheBloke/Llama-2-7B-Chat-GGML", model_file="llama-2-7b-chat.ggmlv3.q3_K_S.bin", | |
model_type='llama', | |
config={'max_new_tokens': 128, | |
'temperature': 0.01} | |
) | |
def greet(prompt): | |
# instruction = "Convert the following text from English to French: \n\n {text}" | |
SYSTEM_PROMPT = B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS | |
template = B_INST + SYSTEM_PROMPT + prompt + E_INST | |
# print(template) | |
prompt = PromptTemplate(template=template, input_variables=["text"]) | |
LLM_Chain = LLMChain(prompt=prompt, llm=llm) | |
return LLM_Chain.run() | |
iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
iface.launch() |