Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
coderai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
coderai
Commits
0c504a0b
Commit
0c504a0b
authored
Mar 16, 2026
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure: Move parser to codai.models, add templates, update imports
parent
3fd46920
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
2 deletions
+118
-2
__init__.py
codai/__init__.py
+4
-1
__init__.py
codai/models/__init__.py
+33
-0
parser.py
codai/models/parser.py
+0
-0
templates.py
codai/models/templates.py
+80
-0
coderai
coderai
+1
-1
No files found.
codai/__init__.py
View file @
0c504a0b
# codai module - AI model parsing utilities
from
.model
_
parser
import
(
from
.model
s.
parser
import
(
ModelParserDispatcher
,
BaseParser
,
QwenParser
,
...
...
@@ -14,6 +14,8 @@ from .model_parser import (
ApexBig50Parser
,
)
from
.models.templates
import
AgenticTemplateManager
__all__
=
[
'ModelParserDispatcher'
,
'BaseParser'
,
...
...
@@ -27,4 +29,5 @@ __all__ = [
'GrokParser'
,
'PhiParser'
,
'ApexBig50Parser'
,
'AgenticTemplateManager'
,
]
codai/models/__init__.py
0 → 100644
View file @
0c504a0b
# codai.models - Model parsing and templates
from
.parser
import
(
ModelParserDispatcher
,
BaseParser
,
QwenParser
,
DeepSeekParser
,
LlamaParser
,
MistralParser
,
ClaudeParser
,
CommandRParser
,
GemmaParser
,
GrokParser
,
PhiParser
,
ApexBig50Parser
,
)
from
.templates
import
AgenticTemplateManager
__all__
=
[
'ModelParserDispatcher'
,
'BaseParser'
,
'QwenParser'
,
'DeepSeekParser'
,
'LlamaParser'
,
'MistralParser'
,
'ClaudeParser'
,
'CommandRParser'
,
'GemmaParser'
,
'GrokParser'
,
'PhiParser'
,
'ApexBig50Parser'
,
'AgenticTemplateManager'
,
]
codai/model
_
parser.py
→
codai/model
s/
parser.py
View file @
0c504a0b
File moved
codai/models/templates.py
0 → 100644
View file @
0c504a0b
"""
Agentic Template Manager - Automates prompt injection for agentic behavior.
Supports the 'Big 10' with specific triggers for tool-calling.
"""
import
re
class
AgenticTemplateManager
:
"""
Automates prompt injection to force models into an Agentic 'Thought-Action' loop.
Supports the 'Big 10' with specific triggers for tool-calling.
"""
FAMILIES
=
{
"qwen"
:
{
"name"
:
"Qwen"
,
"prefix"
:
"<|im_start|>"
,
"suffix"
:
"<|im_end|>
\n
"
,
"thought_tag"
:
"<|thought|>"
,
"call_tag"
:
"<tool_call>"
},
"llama3"
:
{
"name"
:
"Llama-3"
,
"prefix"
:
"<|start_header_id|>"
,
"suffix"
:
"<|end_header_id|>
\n\n
"
,
"thought_tag"
:
"<thought>"
,
"call_tag"
:
"<tool_call>"
},
"deepseek"
:
{
"name"
:
"DeepSeek"
,
"prefix"
:
"<|"
,
"suffix"
:
"|>
\n
"
,
"thought_tag"
:
"<think>"
,
"call_tag"
:
"<tool_call>"
},
"mistral"
:
{
"name"
:
"Mistral"
,
"user"
:
"[INST] "
,
"bot"
:
" [/INST]"
,
"thought_tag"
:
"Thought: "
,
"call_tag"
:
"Action: "
},
"anthropic"
:
{
"name"
:
"Claude"
,
"user"
:
"
\n\n
Human: "
,
"bot"
:
"
\n\n
Assistant: "
,
"thought_tag"
:
"<thinking>"
,
"call_tag"
:
"<tool_calls>"
},
"gemma"
:
{
"name"
:
"Gemma"
,
"user"
:
"<start_of_turn>user
\n
"
,
"bot"
:
"<start_of_turn>model
\n
"
,
"end"
:
"<end_of_turn>
\n
"
},
"phi3"
:
{
"name"
:
"Phi-3"
,
"prefix"
:
"<|"
,
"suffix"
:
"|>
\n
"
,
"end"
:
"<|end|>
\n
"
},
"cohere"
:
{
"name"
:
"Command-R"
,
"user"
:
"<|USER_TOKEN|>"
,
"bot"
:
"<|CHATBOT_TOKEN|>"
,
"thought_tag"
:
"<thought>"
},
"yi"
:
{
"name"
:
"Yi"
,
"prefix"
:
"<|im_start|>"
,
"suffix"
:
"<|im_end|>
\n
"
},
"openai"
:
{
"name"
:
"GPT"
}
}
def
__init__
(
self
,
model_name
:
str
):
self
.
model_name
=
model_name
.
lower
()
self
.
family_key
=
self
.
_detect_family
()
self
.
config
=
self
.
FAMILIES
.
get
(
self
.
family_key
,
self
.
FAMILIES
[
"qwen"
])
def
_detect_family
(
self
):
mapping
=
{
"qwen"
:
"qwen"
,
"llama-3"
:
"llama3"
,
"deepseek"
:
"deepseek"
,
"mistral"
:
"mistral"
,
"mixtral"
:
"mistral"
,
"claude"
:
"anthropic"
,
"gemma"
:
"gemma"
,
"phi-3"
:
"phi3"
,
"command"
:
"cohere"
,
"yi"
:
"yi"
}
for
k
,
v
in
mapping
.
items
():
if
k
in
self
.
model_name
:
return
v
return
"openai"
if
"gpt"
in
self
.
model_name
else
"qwen"
def
get_agent_system_prompt
(
self
,
base_prompt
:
str
)
->
str
:
"""Injects agentic instructions specific to the model's strengths."""
agent_addon
=
(
"
\n\n
CRITICAL: You are an agent with access to tools. "
f
"Use the {self.config.get('thought_tag', 'Thought:')} tag to reason step-by-step "
"before providing a tool call. If you have enough info, provide the final answer."
)
return
f
"{base_prompt}{agent_addon}"
def
format_for_inference
(
self
,
messages
:
list
)
->
str
:
"""Constructs the prompt string and forces the 'Thought' start."""
if
self
.
family_key
==
"openai"
:
return
messages
prompt
=
""
f
=
self
.
config
for
m
in
messages
:
role
,
content
=
m
[
'role'
],
m
[
'content'
]
# ChatML Style (Qwen, Llama3, Yi, DeepSeek)
if
"prefix"
in
f
:
prompt
+=
f
"{f['prefix']}{role}{f['suffix']}{content}"
if
"end"
in
f
:
prompt
+=
f
[
"end"
]
else
:
prompt
+=
f
.
get
(
"suffix"
,
"
\n
"
)
# Instruction Style (Mistral, Gemma)
elif
self
.
family_key
==
"mistral"
:
if
role
==
"user"
:
prompt
+=
f
"{f['user']}{content}{f['bot']}"
elif
role
==
"assistant"
:
prompt
+=
f
" {content} "
# THE AGENTIC PUSH: Force the assistant to start with a THOUGHT
thought_trigger
=
f
.
get
(
"thought_tag"
,
"Thought: "
)
if
"prefix"
in
f
:
prompt
+=
f
"{f['prefix']}assistant{f['suffix']}{thought_trigger}"
else
:
prompt
+=
f
"{f.get('bot', 'Assistant: ')}{thought_trigger}"
return
prompt
coderai
View file @
0c504a0b
...
...
@@ -29,7 +29,7 @@ from pydantic_core import PydanticCustomError
from
threading
import
Thread
#
Import
codai
module
for
enhanced
tool
call
parsing
from
codai
import
ModelParserDispatcher
from
codai
.
models
import
ModelParserDispatcher
#
Per
-
model
semaphores
for
request
concurrency
control
model_semaphores
:
dict
=
{}
load_mode
=
{
"mode"
:
"ondemand"
}
#
Track
load
mode
globally
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment