Skip to content

Commit 8eba191

Browse files
authored
Merge pull request #127 from stackhpc/feat/date-template
Add optional date templating in model system prompt
2 parents 414a364 + f3edfce commit 8eba191

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

charts/azimuth-chat/values.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"type": "string",
6262
"title": "Instruction",
6363
"description": "The initial system prompt (i.e. the hidden instruction) to use when generating responses.",
64-
"default": "You are a helpful AI assistant. Please respond appropriately."
64+
"default": "You are a helpful AI assistant. Please respond appropriately. Today's date is {date}."
6565
},
6666
"page_title": {
6767
"type": "string",

web-apps/chat/app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import utils
33
import gradio as gr
44

5+
from datetime import date
56
from urllib.parse import urljoin
67
from langchain.schema import HumanMessage, AIMessage, SystemMessage
78
from langchain_openai import ChatOpenAI
@@ -68,11 +69,12 @@ def inference(latest_message, history):
6869

6970
try:
7071
context = []
72+
model_instruction = settings.model_instruction.replace("{date}", f"{date.today()}")
7173
if INCLUDE_SYSTEM_PROMPT:
72-
context.append(SystemMessage(content=settings.model_instruction))
74+
context.append(SystemMessage(content=model_instruction))
7375
elif history and len(history) > 0:
7476
# Mimic system prompt by prepending it to first human message
75-
history[0]['content'] = f"{settings.model_instruction}\n\n{history[0]['content']}"
77+
history[0]['content'] = f"{model_instruction}\n\n{history[0]['content']}"
7678

7779
for message in history:
7880
role = message['role']

web-apps/chat/defaults.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ backend_url: http://localhost:11434
55

66
host_address: 0.0.0.0
77

8-
model_instruction: "You are a helpful and cheerful AI assistant. Please respond appropriately."
8+
# Model instruction allows substituting in current date
9+
model_instruction: "You are a helpful and cheerful AI assistant. Please respond appropriately. Today's date is {date}."
910

1011
page_title: Large Language Model
1112

0 commit comments

Comments
 (0)