(state, model_selector, text, image, request: gr.Request)
| 268 | |
| 269 | |
| 270 | def 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 | |
| 301 | def model_worker_stream_iter( |
nothing calls this directly
no test coverage detected
searching dependent graphs…