mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-06-14 02:09:22 -04:00
refactor: Finalize agent template
This commit is contained in:
9
sources/agents/partials/anthropic_image.jinja
Normal file
9
sources/agents/partials/anthropic_image.jinja
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "image",
|
||||
"source":
|
||||
{% if b.is_url %}
|
||||
{ "type": "url", "url": {{ tojson(b.data) }} }
|
||||
{% else %}
|
||||
{ "type": "base64", "media_type": {{ tojson(b.media_type) }}, "data": {{ tojson(b.data) }} }
|
||||
{% endif %}
|
||||
},
|
||||
12
sources/agents/partials/anthropic_messages.jinja
Normal file
12
sources/agents/partials/anthropic_messages.jinja
Normal file
@@ -0,0 +1,12 @@
|
||||
{% for msg in ctx.history %}
|
||||
{
|
||||
"role": {{ tojson(msg.role) }},
|
||||
"content": [
|
||||
{% for b in msg.content_blocks %}
|
||||
{% if b.type == "image" %}{% include "partials/anthropic_image.jinja" %}
|
||||
{% else %}{{ tojson(b) }},
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
},
|
||||
{% endfor %}
|
||||
6
sources/agents/partials/google_contents.jinja
Normal file
6
sources/agents/partials/google_contents.jinja
Normal file
@@ -0,0 +1,6 @@
|
||||
{% for msg in ctx.history %}
|
||||
{
|
||||
"role": {% if msg.role == "assistant" %}"model"{% else %}"user"{% endif %},
|
||||
"parts": [ {% for b in msg.content_blocks %}{% include "partials/google_part.jinja" %}{% endfor %} ]
|
||||
},
|
||||
{% endfor %}
|
||||
17
sources/agents/partials/google_part.jinja
Normal file
17
sources/agents/partials/google_part.jinja
Normal file
@@ -0,0 +1,17 @@
|
||||
{% if b.type == "text" %}
|
||||
{ "text": {{ tojson(b.text) }} },
|
||||
{% else if b.type == "thinking" %}
|
||||
{ "text": {{ tojson(b.thinking) }}, "thought": true, "thoughtSignature": {{ tojson(b.signature) }} },
|
||||
{% else if b.type == "tool_use" %}
|
||||
{ "functionCall": { "name": {{ tojson(b.name) }}, "args": {{ tojson(b.input) }} } },
|
||||
{% else if b.type == "tool_result" %}
|
||||
{ "functionResponse": { "name": {{ tojson(b.name) }}, "response": { "result": {{ tojson(b.content) }} } } },
|
||||
{% else if b.type == "image" %}
|
||||
{% if b.is_url %}
|
||||
{ "file_data": { "mime_type": {{ tojson(b.media_type) }}, "file_uri": {{ tojson(b.data) }} } },
|
||||
{% else %}
|
||||
{ "inline_data": { "mime_type": {{ tojson(b.media_type) }}, "data": {{ tojson(b.data) }} } },
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{ "text": "" },
|
||||
{% endif %}
|
||||
16
sources/agents/partials/ollama_messages.jinja
Normal file
16
sources/agents/partials/ollama_messages.jinja
Normal file
@@ -0,0 +1,16 @@
|
||||
{% if existsIn(ctx, "system_prompt") %}
|
||||
{ "role": "system", "content": {{ tojson(ctx.system_prompt) }} },
|
||||
{% endif %}
|
||||
{% for msg in ctx.history %}
|
||||
{
|
||||
"role": {{ tojson(msg.role) }},
|
||||
"content": {{ tojson(msg.content) }}
|
||||
{% if existsIn(msg, "images") %}
|
||||
, "images": [
|
||||
{% for img in msg.images %}
|
||||
{{ tojson(img.data) }},
|
||||
{% endfor %}
|
||||
]
|
||||
{% endif %}
|
||||
},
|
||||
{% endfor %}
|
||||
19
sources/agents/partials/openai_assistant.jinja
Normal file
19
sources/agents/partials/openai_assistant.jinja
Normal file
@@ -0,0 +1,19 @@
|
||||
{% set tcalls = filter_by_type(msg.content_blocks, "tool_use") %}
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": {{ tojson(msg.content) }}
|
||||
{% if length(tcalls) > 0 %}
|
||||
, "tool_calls": [
|
||||
{% for b in tcalls %}
|
||||
{
|
||||
"id": {{ tojson(b.id) }},
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": {{ tojson(b.name) }},
|
||||
"arguments": {{ tojson(tojson(b.input)) }}
|
||||
}
|
||||
},
|
||||
{% endfor %}
|
||||
]
|
||||
{% endif %}
|
||||
},
|
||||
11
sources/agents/partials/openai_image_content.jinja
Normal file
11
sources/agents/partials/openai_image_content.jinja
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
{ "type": "text", "text": {{ tojson(msg.content) }} }
|
||||
{% for img in msg.images %}
|
||||
,
|
||||
{% if img.is_url %}
|
||||
{ "type": "image_url", "image_url": { "url": {{ tojson(img.data) }} } }
|
||||
{% else %}
|
||||
{ "type": "image_url", "image_url": { "url": "data:{{ img.media_type }};base64,{{ img.data }}" } }
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
9
sources/agents/partials/openai_messages.jinja
Normal file
9
sources/agents/partials/openai_messages.jinja
Normal file
@@ -0,0 +1,9 @@
|
||||
{% if existsIn(ctx, "system_prompt") %}
|
||||
{ "role": "system", "content": {{ tojson(ctx.system_prompt) }} },
|
||||
{% endif %}
|
||||
{% for msg in ctx.history %}
|
||||
{% if msg.role == "assistant" %}{% include "partials/openai_assistant.jinja" %}
|
||||
{% else if length(filter_by_type(msg.content_blocks, "tool_result")) > 0 %}{% include "partials/openai_tool_results.jinja" %}
|
||||
{% else %}{% include "partials/openai_user.jinja" %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
30
sources/agents/partials/openai_responses_input.jinja
Normal file
30
sources/agents/partials/openai_responses_input.jinja
Normal file
@@ -0,0 +1,30 @@
|
||||
{% for msg in ctx.history %}
|
||||
{% if msg.role == "assistant" %}
|
||||
{% if msg.content != "" %}
|
||||
{ "role": "assistant", "content": {{ tojson(msg.content) }} },
|
||||
{% endif %}
|
||||
{% for b in filter_by_type(msg.content_blocks, "tool_use") %}
|
||||
{ "type": "function_call", "call_id": {{ tojson(b.id) }}, "name": {{ tojson(b.name) }}, "arguments": {{ tojson(tojson(b.input)) }} },
|
||||
{% endfor %}
|
||||
{% else if length(filter_by_type(msg.content_blocks, "tool_result")) > 0 %}
|
||||
{% for b in filter_by_type(msg.content_blocks, "tool_result") %}
|
||||
{ "type": "function_call_output", "call_id": {{ tojson(b.tool_use_id) }}, "output": {{ tojson(b.content) }} },
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% if existsIn(msg, "images") %}
|
||||
{ "role": "user", "content": [
|
||||
{ "type": "input_text", "text": {{ tojson(msg.content) }} }
|
||||
{% for img in msg.images %}
|
||||
,
|
||||
{% if img.is_url %}
|
||||
{ "type": "input_image", "detail": "auto", "image_url": {{ tojson(img.data) }} }
|
||||
{% else %}
|
||||
{ "type": "input_image", "detail": "auto", "image_url": "data:{{ img.media_type }};base64,{{ img.data }}" }
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
] },
|
||||
{% else %}
|
||||
{ "role": "user", "content": {{ tojson(msg.content) }} },
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
3
sources/agents/partials/openai_tool_results.jinja
Normal file
3
sources/agents/partials/openai_tool_results.jinja
Normal file
@@ -0,0 +1,3 @@
|
||||
{% for b in filter_by_type(msg.content_blocks, "tool_result") %}
|
||||
{ "role": "tool", "tool_call_id": {{ tojson(b.tool_use_id) }}, "content": {{ tojson(b.content) }} },
|
||||
{% endfor %}
|
||||
5
sources/agents/partials/openai_user.jinja
Normal file
5
sources/agents/partials/openai_user.jinja
Normal file
@@ -0,0 +1,5 @@
|
||||
{% if existsIn(msg, "images") %}
|
||||
{ "role": "user", "content": {% include "partials/openai_image_content.jinja" %} },
|
||||
{% else %}
|
||||
{ "role": "user", "content": {{ tojson(msg.content) }} },
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user