Spaces:
Runtime error
Runtime error
File size: 882 Bytes
d25a8ec |
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 |
import gradio as gr
from llama_cpp import Llama
llm = Llama(
model_path="./mistral-7b-instruct-v0.1.Q2_K.gguf",
verbose=True
)
def predict(message, history):
messages = [{"role": "system", "content": "You are a helpful assistant."}]
for user_message, bot_message in history:
if user_message:
messages.append({"role": "user", "content": user_message})
if bot_message:
messages.append({"role": "assistant", "content": bot_message})
messages.append({"role": "user", "content": message})
response = ""
for chunk in llm.create_chat_completion(
stream=True,
messages=messages,
):
part = chunk["choices"][0]["delta"].get("content", None)
if part:
response += part
yield response
demo = gr.ChatInterface(predict)
if __name__ == "__main__":
demo.launch() |