@@ -62,23 +62,26 @@ class PossibleSystemPromptException(Exception):
6262 streaming = True ,
6363)
6464
65+
6566def inference (latest_message , history ):
6667 # Allow mutating global variable
6768 global BACKEND_INITIALISED
6869 log .debug ("Inference request received with history: %s" , history )
6970
7071 try :
7172 context = []
72- model_instruction = settings .model_instruction .replace ("{date}" , f"{ date .today ()} " )
73+ model_instruction = settings .model_instruction .replace (
74+ "{date}" , f"{ date .today ()} "
75+ )
7376 if INCLUDE_SYSTEM_PROMPT :
7477 context .append (SystemMessage (content = model_instruction ))
7578 elif history and len (history ) > 0 :
7679 # Mimic system prompt by prepending it to first human message
77- history [0 ][' content' ] = f"{ model_instruction } \n \n { history [0 ]['content' ]} "
80+ history [0 ][" content" ] = f"{ model_instruction } \n \n { history [0 ]['content' ]} "
7881
7982 for message in history :
80- role = message [' role' ]
81- content = message [' content' ]
83+ role = message [" role" ]
84+ content = message [" content" ]
8285 if role == "user" :
8386 context .append (HumanMessage (content = content ))
8487 else :
@@ -102,10 +105,10 @@ def inference(latest_message, history):
102105 # The "think" tags mark the chatbot's reasoning. Remove the content
103106 # and replace with "Thinking..." until the closing tag is found.
104107 content = chunk .content
105- if ' <think>' in content or thinking :
108+ if " <think>" in content or thinking :
106109 thinking = True
107110 response = "Thinking..."
108- if ' </think>' in content :
111+ if " </think>" in content :
109112 thinking = False
110113 response = ""
111114 else :
@@ -175,7 +178,7 @@ def inference_wrapper(*args):
175178 js = settings .custom_javascript ,
176179 title = settings .page_title ,
177180) as demo :
178- gr .Markdown ('# ' + settings .page_title )
181+ gr .Markdown ("# " + settings .page_title )
179182 gr .ChatInterface (
180183 inference_wrapper ,
181184 type = "messages" ,
@@ -187,10 +190,10 @@ def inference_wrapper(*args):
187190 sanitize_html = True ,
188191 autoscroll = False ,
189192 latex_delimiters = [
190- {"left" : "$$" , "right" : "$$" , "display" : True },
191- {"left" : "$" , "right" : "$" , "display" : False }
192- ],
193- ),
193+ {"left" : "$$" , "right" : "$$" , "display" : True },
194+ {"left" : "$" , "right" : "$" , "display" : False },
195+ ],
196+ ),
194197 )
195198
196199
0 commit comments