Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,8 @@ from llama_cpp_agent import MessagesFormatterType
|
|
12 |
from llama_cpp_agent.providers import LlamaCppPythonProvider
|
13 |
from llama_cpp_agent.chat_history import BasicChatHistory
|
14 |
from llama_cpp_agent.chat_history.messages import Roles
|
|
|
|
|
15 |
import gradio as gr
|
16 |
from huggingface_hub import hf_hub_download
|
17 |
from typing import List, Tuple
|
@@ -33,6 +35,27 @@ hf_hub_download(
|
|
33 |
local_dir="./models",
|
34 |
)
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# Set the title and description
|
37 |
title = "Gemma Llama.cpp"
|
38 |
description = """Gemma 3 is a family of lightweight, multimodal open models that offers advanced capabilities like large context windows and multilingual support, enabling diverse applications on various devices."""
|
@@ -92,7 +115,7 @@ def respond(
|
|
92 |
agent = LlamaCppAgent(
|
93 |
provider,
|
94 |
system_prompt=f"{system_message}",
|
95 |
-
predefined_messages_formatter_type=
|
96 |
debug_output=True,
|
97 |
)
|
98 |
|
@@ -141,7 +164,11 @@ def respond(
|
|
141 |
# Create a chat interface
|
142 |
demo = gr.ChatInterface(
|
143 |
respond,
|
144 |
-
examples=[
|
|
|
|
|
|
|
|
|
145 |
additional_inputs_accordion=gr.Accordion(
|
146 |
label="⚙️ Parameters", open=False, render=False
|
147 |
),
|
|
|
12 |
from llama_cpp_agent.providers import LlamaCppPythonProvider
|
13 |
from llama_cpp_agent.chat_history import BasicChatHistory
|
14 |
from llama_cpp_agent.chat_history.messages import Roles
|
15 |
+
from llama_cpp_agent.chat_history.messages import Roles
|
16 |
+
from llama_cpp_agent.messages_formatter import MessagesFormatter, PromptMarkers
|
17 |
import gradio as gr
|
18 |
from huggingface_hub import hf_hub_download
|
19 |
from typing import List, Tuple
|
|
|
35 |
local_dir="./models",
|
36 |
)
|
37 |
|
38 |
+
|
39 |
+
# Define the prompt markers for Gemma 3
|
40 |
+
gemma_3_prompt_markers = {
|
41 |
+
Roles.system: PromptMarkers("", "\n"), # System prompt should be included within user message
|
42 |
+
Roles.user: PromptMarkers("<start_of_turn>user\n", "<end_of_turn>\n"),
|
43 |
+
Roles.assistant: PromptMarkers("<start_of_turn>model\n", "<end_of_turn>\n"),
|
44 |
+
Roles.tool: PromptMarkers("", ""), # If you need tool support
|
45 |
+
}
|
46 |
+
|
47 |
+
# Create the formatter
|
48 |
+
gemma_3_formatter = MessagesFormatter(
|
49 |
+
pre_prompt="", # No pre-prompt
|
50 |
+
prompt_markers=gemma_3_prompt_markers,
|
51 |
+
include_sys_prompt_in_first_user_message=True, # Include system prompt in first user message
|
52 |
+
default_stop_sequences=["<end_of_turn>", "<start_of_turn>"],
|
53 |
+
strip_prompt=False, # Don't strip whitespace from the prompt
|
54 |
+
bos_token="<bos>", # Beginning of sequence token for Gemma 3
|
55 |
+
eos_token="<eos>", # End of sequence token for Gemma 3
|
56 |
+
)
|
57 |
+
|
58 |
+
|
59 |
# Set the title and description
|
60 |
title = "Gemma Llama.cpp"
|
61 |
description = """Gemma 3 is a family of lightweight, multimodal open models that offers advanced capabilities like large context windows and multilingual support, enabling diverse applications on various devices."""
|
|
|
115 |
agent = LlamaCppAgent(
|
116 |
provider,
|
117 |
system_prompt=f"{system_message}",
|
118 |
+
predefined_messages_formatter_type=gemma_3_formatter,
|
119 |
debug_output=True,
|
120 |
)
|
121 |
|
|
|
164 |
# Create a chat interface
|
165 |
demo = gr.ChatInterface(
|
166 |
respond,
|
167 |
+
examples=[
|
168 |
+
["What is the capital of France?"],
|
169 |
+
["Tell me something about artificial intelligence."],
|
170 |
+
["What is gravity?"],
|
171 |
+
],
|
172 |
additional_inputs_accordion=gr.Accordion(
|
173 |
label="⚙️ Parameters", open=False, render=False
|
174 |
),
|