MCPcopy
hub / github.com/lm-sys/FastChat / add_text

Function add_text

fastchat/serve/gradio_web_server.py:270–298  ·  view source on GitHub ↗
(state, model_selector, text, image, request: gr.Request)

Source from the content-addressed store, hash-verified

268
269
270def add_text(state, model_selector, text, image, request: gr.Request):
271 ip = get_ip(request)
272 logger.info(f"add_text. ip: {ip}. len: {len(text)}")
273
274 if state is None:
275 state = State(model_selector)
276
277 if len(text) <= 0:
278 state.skip_next = True
279 return (state, state.to_gradio_chatbot(), "") + (no_change_btn,) * 5
280
281 flagged = moderation_filter(text, [state.model_name])
282 if flagged:
283 logger.info(f"violate moderation. ip: {ip}. text: {text}")
284 # overwrite the original text
285 text = MODERATION_MSG
286
287 if (len(state.conv.messages) - state.conv.offset) // 2 >= CONVERSATION_TURN_LIMIT:
288 logger.info(f"conversation turn limit. ip: {ip}. text: {text}")
289 state.skip_next = True
290 return (state, state.to_gradio_chatbot(), CONVERSATION_LIMIT_MSG) + (
291 no_change_btn,
292 ) * 5
293
294 text = text[:INPUT_CHAR_LEN_LIMIT] # Hard cut-off
295 text = _prepare_text_with_image(state, text, image)
296 state.conv.append_message(state.conv.roles[0], text)
297 state.conv.append_message(state.conv.roles[1], None)
298 return (state, state.to_gradio_chatbot(), "", None) + (disable_btn,) * 5
299
300
301def model_worker_stream_iter(

Callers

nothing calls this directly

Calls 6

to_gradio_chatbotMethod · 0.95
moderation_filterFunction · 0.90
get_ipFunction · 0.85
StateClass · 0.85
_prepare_text_with_imageFunction · 0.85
append_messageMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…