MCPcopy Create free account
hub / github.com/SmartFlowAI/TheGodOfCookery / process_user_input

Function process_user_input

app.py:244–341  ·  view source on GitHub ↗

处理用户输入,根据用户输入内容调用相应的模型生成回复。 Args: prompt (str): 用户输入的内容。 model (str): 使用的模型名称。 tokenizer (object): 分词器对象。 llm: langchain包装的大模型 generation_config (dict): 生成配置参数。

(prompt,
                       model,
                       tokenizer,
                       llm,
                       generation_config)

Source from the content-addressed store, hash-verified

242
243
244def process_user_input(prompt,
245 model,
246 tokenizer,
247 llm,
248 generation_config):
249 """
250 处理用户输入,根据用户输入内容调用相应的模型生成回复。
251
252 Args:
253 prompt (str): 用户输入的内容。
254 model (str): 使用的模型名称。
255 tokenizer (object): 分词器对象。
256 llm: langchain包装的大模型
257 generation_config (dict): 生成配置参数。
258
259 """
260
261 # Check if the user input contains certain keywords
262 keywords = ["怎么做", "做法", "菜谱"]
263 contains_keywords = any(keyword in prompt for keyword in keywords)
264
265 # Display user message in chat message container
266 with st.chat_message("user", avatar=user_avatar):
267 st.markdown(prompt)
268 real_prompt = combine_history(prompt)
269
270 # Add user message to chat history
271 st.session_state.messages.append(
272 {"role": "user", "content": prompt, "avatar": user_avatar})
273
274 # If keywords are not present, display a prompt message immediately
275 if not contains_keywords:
276 with st.chat_message("robot", avatar=robot_avatar):
277 st.markdown(error_response)
278 # Add robot response to chat history
279 st.session_state.messages.append(
280 {"role": "robot", "content": error_response, "avatar": robot_avatar})
281 else:
282 # Generate robot response
283 with st.chat_message("robot", avatar=robot_avatar):
284 message_placeholder = st.empty()
285 # print("prompt:", prompt)
286 # print("real_prompt:", real_prompt)
287 if enable_rag:
288 cur_response = generate_interactive_rag(
289 llm=llm,
290 question=prompt,
291 verbose=verbose,
292 )
293
294 cur_response = cur_response.replace('\\n', '\n')
295
296 # print(cur_response)
297 if enable_markdown:
298 cur_response = return_final_md(cur_response)
299 # print('after markdown:', cur_response)
300 message_placeholder.markdown(cur_response + "▌")
301 else:

Callers 1

mainFunction · 0.85

Calls 5

generate_interactive_ragFunction · 0.90
return_final_mdFunction · 0.90
generate_interactiveFunction · 0.90
text_to_imageFunction · 0.85
combine_historyFunction · 0.70

Tested by

no test coverage detected