Skip to content

Commit 2235129

Browse files
committed
Add optional date templating in model system prompt
1 parent 414a364 commit 2235129

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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)