Archived
deploy: ignore LibreChat's image placeholder in the OCR template
LibreChat sends the picture followed by U+FFFC (an object replacement character) as the text part, so the turn looked non-empty and the parser instruction was not supplied; the model then emitted a one-word preamble before the layout. Treat U+FFFC like whitespace and drop it from the rendered prompt, and default the instruction for any picture count.
This commit is contained in:
1 parent
34f2bf26e2
commit
1f661bf2e0
1 file changed
+18
-10
@@ -2,24 +2,32 @@
|
|||||||
the reference instruction, e.g. "<__media__>document parsing." (the server replaces each
|
the reference instruction, e.g. "<__media__>document parsing." (the server replaces each
|
||||||
marker with a picture's token run). Chat clients send the picture plus arbitrary text, often
|
marker with a picture's token run). Chat clients send the picture plus arbitrary text, often
|
||||||
nothing, and resend earlier turns including their pictures. A parser without its start
|
nothing, and resend earlier turns including their pictures. A parser without its start
|
||||||
instruction free-runs like a language model and first emits prose (the Chinese preamble seen
|
instruction free-runs like a language model and first emits prose (the Chinese/Russian
|
||||||
from LibreChat), and text from earlier turns or a system message would be concatenated into
|
preamble seen from LibreChat), and text from earlier turns or a system message would be
|
||||||
the prompt. This template keeps every picture marker (the server requires the rendered prompt
|
concatenated into the prompt. This template keeps every picture marker (the server requires
|
||||||
to account for every picture in the request) and the final user turn's text, drops other
|
the rendered prompt to account for every picture in the request) and the final user turn's
|
||||||
text, and supplies the reference instruction when the final turn carries none. -#}
|
text, drops other text, and supplies the reference instruction when the final turn carries
|
||||||
{%- set ns = namespace(last=none, at=-1) -%}
|
none, for any number of pictures: one is "document parsing.", several are "Multi page
|
||||||
|
parsing." -#}
|
||||||
|
{%- set ns = namespace(last=none, at=-1, media=0, text=false) -%}
|
||||||
{%- for message in messages -%}
|
{%- for message in messages -%}
|
||||||
{%- if message['role'] == 'user' -%}
|
{%- if message['role'] == 'user' -%}
|
||||||
{%- set ns.last = message -%}
|
{%- set ns.last = message -%}
|
||||||
{%- set ns.at = loop.index0 -%}
|
{%- set ns.at = loop.index0 -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
|
{%- if ns.last is not none and ns.last['content'] is string -%}
|
||||||
|
{%- for piece in ns.last['content'].split('<__media__>') -%}
|
||||||
|
{%- if not loop.last -%}{%- set ns.media = ns.media + 1 -%}{%- endif -%}
|
||||||
|
{%- if ((piece | replace('', '')) | trim) != '' -%}{%- set ns.text = true -%}{%- endif -%}
|
||||||
|
{%- endfor -%}
|
||||||
|
{%- endif -%}
|
||||||
{%- for message in messages -%}
|
{%- for message in messages -%}
|
||||||
{%- set mi = loop.index0 -%}
|
{%- set mi = loop.index0 -%}
|
||||||
{%- if message['content'] is string -%}
|
{%- if message['content'] is string -%}
|
||||||
{%- set c = message['content'] -%}
|
{%- set c = message['content'] -%}
|
||||||
{%- if mi == ns.at -%}
|
{%- if mi == ns.at -%}
|
||||||
{{- c -}}
|
{{- c | replace('', '') -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{%- for piece in c.split('<__media__>') -%}
|
{%- for piece in c.split('<__media__>') -%}
|
||||||
{%- if not loop.last -%}<__media__>{%- endif -%}
|
{%- if not loop.last -%}<__media__>{%- endif -%}
|
||||||
@@ -33,8 +41,8 @@
|
|||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{%- if ns.last is not none and ns.last['content'] is string -%}
|
{%- if ns.last is not none and ns.last['content'] is string and not ns.text -%}
|
||||||
{%- if ns.last['content'] == '<__media__>' -%}document parsing.
|
{%- if ns.media > 1 -%}Multi page parsing.
|
||||||
{%- elif ns.last['content'] == '<__media__><__media__>' -%}Multi page parsing.
|
{%- elif ns.media == 1 -%}document parsing.
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
Reference in new issue
Block a user