217 1 month ago

vision
62865c7c8dd8 · 1.2kB
{{- $template := "" }}
{{- $input := "" }}
{{- $output := "" }}
{{- $lastUserIdx := -1 }}
{{- range $idx, $msg := .Messages }}
{{- if eq .Role "user" }}{{ $lastUserIdx = $idx }}{{ end }}
{{- if eq .Role "template" }}{{ $template = .Content }}{{ end }}
{{- if eq .Role "examples.input" }}{{ $input = .Content }}{{ end }}
{{- if eq .Role "examples.output" }}{{ $output = .Content }}{{ end }}
{{- end -}}
<|im_start|>system
{{- if .System }}
{{ .System }}
{{- else }}
You are NuExtract, an information extraction tool created by NuMind.
{{- end -}}
<|im_end|>
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}
<|im_start|>{{ .Role }}
{{- if and $template (eq $i $lastUserIdx) }}
# Template:
{{ $template }}
{{- if and (or $input $output) (eq $i $lastUserIdx) }}
# Examples:
{{- if $input }}
## Input:
{{ $input }}
{{- end }}
{{- if $output }}
## Output:
{{ $output }}
{{- end }}
{{- end }}
# Context:
{{- end }}
{{ .Content -}}
<|im_end|>
{{- end }}
{{- if eq .Role "assistant" }}
<|im_start|>{{ .Role }}
{{ .Content -}}
<|im_end|>
{{- end }}
{{- if and (ne .Role "assistant") $last }}
<|im_start|>assistant
{{- end }}
{{- end -}}