ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
|
||||
{%- for message in messages %}
|
||||
{#-- Validate role is a stringified integer --#}
|
||||
{%- if not message['role'] is string or not message['role'].isdigit() %}
|
||||
{{- raise_exception("The role must be an integer or a stringified integer (e.g. '0') designating the speaker id") }}
|
||||
{%- endif %}
|
||||
|
||||
{#-- Validate content is a list --#}
|
||||
{%- set content = message['content'] %}
|
||||
{%- if content is not iterable or content is string %}
|
||||
{{- raise_exception("The content must be a list") }}
|
||||
{%- endif %}
|
||||
|
||||
{#-- Collect content types --#}
|
||||
{%- set content_types = content | map(attribute='type') | list %}
|
||||
{%- set is_last = loop.last %}
|
||||
|
||||
{#-- Last message validation --#}
|
||||
{%- if is_last %}
|
||||
{%- if 'text' not in content_types %}
|
||||
{{- raise_exception("The last message must include one item of type 'text'") }}
|
||||
{%- elif (content_types | select('equalto', 'text') | list | length > 1) or (content_types | select('equalto', 'audio') | list | length > 1) %}
|
||||
{{- raise_exception("At most two items are allowed in the last message: one 'text' and one 'audio'") }}
|
||||
{%- endif %}
|
||||
|
||||
{#-- All other messages validation --#}
|
||||
{%- else %}
|
||||
{%- if content_types | select('equalto', 'text') | list | length != 1
|
||||
or content_types | select('equalto', 'audio') | list | length != 1 %}
|
||||
{{- raise_exception("Each message (except the last) must contain exactly one 'text' and one 'audio' item") }}
|
||||
{%- elif content_types | reject('in', ['text', 'audio']) | list | length > 0 %}
|
||||
{{- raise_exception("Only 'text' and 'audio' types are allowed in content") }}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
{%- for message in messages %}
|
||||
{{- bos_token }}
|
||||
{{- '[' + message['role'] + ']' }}
|
||||
{{- message['content'][0]['text'] }}
|
||||
{{- eos_token }}
|
||||
{%- if message['content']|length > 1 %}
|
||||
{{- '<|AUDIO|><|audio_eos|>' }}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
Reference in New Issue
Block a user