@@ -56,6 +56,7 @@ local M = {
56
56
config = {}, -- config variables
57
57
hooks = {}, -- user defined command functions
58
58
spinner = require (" gp.spinner" ), -- spinner module
59
+ defaults = require (" gp.defaults" ), -- some useful defaults
59
60
}
60
61
61
62
---- ----------------------------------------------------------------------------
@@ -1612,20 +1613,6 @@ end
1612
1613
-- Chat logic
1613
1614
---- ----------------
1614
1615
1615
- M .chat_template = [[
1616
- # topic: ?
1617
-
1618
- - file: %s
1619
- %s
1620
- Write your queries after %s. Use `%s` or :%sChatRespond to generate a response.
1621
- Response generation can be terminated by using `%s` or :%sChatStop command.
1622
- Chats are saved automatically. To delete this chat, use `%s` or :%sChatDelete.
1623
- Be cautious of very long chats. Start a fresh chat by using `%s` or :%sChatNew.
1624
-
1625
- ---
1626
-
1627
- %s]]
1628
-
1629
1616
M ._toggle = {}
1630
1617
1631
1618
M ._toggle_kind = {
@@ -1708,7 +1695,7 @@ M.not_chat = function(buf, file_name)
1708
1695
end
1709
1696
1710
1697
local lines = vim .api .nvim_buf_get_lines (buf , 0 , - 1 , false )
1711
- if # lines < 7 then
1698
+ if # lines < 5 then
1712
1699
return " file too short"
1713
1700
end
1714
1701
@@ -1717,8 +1704,8 @@ M.not_chat = function(buf, file_name)
1717
1704
end
1718
1705
1719
1706
local header_found = nil
1720
- for i = 1 , 6 do
1721
- if lines [i ]:match (" ^- file: " ) then
1707
+ for i = 1 , 10 do
1708
+ if i < # lines and lines [i ]:match (" ^- file: " ) then
1722
1709
header_found = true
1723
1710
break
1724
1711
end
@@ -2051,21 +2038,32 @@ M.new_chat = function(params, toggle, system_prompt, agent)
2051
2038
system_prompt = " "
2052
2039
end
2053
2040
2054
- local template = string.format (
2055
- M .config .chat_template or M .chat_template ,
2056
- string.match (filename , " ([^/]+)$" ),
2057
- model .. provider .. system_prompt ,
2058
- M .config .chat_user_prefix ,
2059
- M .config .chat_shortcut_respond .shortcut ,
2060
- M .config .cmd_prefix ,
2061
- M .config .chat_shortcut_stop .shortcut ,
2062
- M .config .cmd_prefix ,
2063
- M .config .chat_shortcut_delete .shortcut ,
2064
- M .config .cmd_prefix ,
2065
- M .config .chat_shortcut_new .shortcut ,
2066
- M .config .cmd_prefix ,
2067
- M .config .chat_user_prefix
2068
- )
2041
+ local template = M ._H .template_render (M .config .chat_template or require (" gp.defaults" ).chat_template , {
2042
+ [" {{filename}}" ] = string.match (filename , " ([^/]+)$" ),
2043
+ [" {{optional_headers}}" ] = model .. provider .. system_prompt ,
2044
+ [" {{user_prefix}}" ] = M .config .chat_user_prefix ,
2045
+ [" {{respond_shortcut}}" ] = M .config .chat_shortcut_respond .shortcut ,
2046
+ [" {{cmd_prefix}}" ] = M .config .cmd_prefix ,
2047
+ [" {{stop_shortcut}}" ] = M .config .chat_shortcut_stop .shortcut ,
2048
+ [" {{delete_shortcut}}" ] = M .config .chat_shortcut_delete .shortcut ,
2049
+ [" {{new_shortcut}}" ] = M .config .chat_shortcut_new .shortcut ,
2050
+ })
2051
+
2052
+ -- local template = string.format(
2053
+ -- M.config.chat_template or require("gp.defaults").chat_template,
2054
+ -- string.match(filename, "([^/]+)$"),
2055
+ -- model .. provider .. system_prompt,
2056
+ -- M.config.chat_user_prefix,
2057
+ -- M.config.chat_shortcut_respond.shortcut,
2058
+ -- M.config.cmd_prefix,
2059
+ -- M.config.chat_shortcut_stop.shortcut,
2060
+ -- M.config.cmd_prefix,
2061
+ -- M.config.chat_shortcut_delete.shortcut,
2062
+ -- M.config.cmd_prefix,
2063
+ -- M.config.chat_shortcut_new.shortcut,
2064
+ -- M.config.cmd_prefix,
2065
+ -- M.config.chat_user_prefix
2066
+ -- )
2069
2067
2070
2068
-- escape underscores (for markdown)
2071
2069
template = template :gsub (" _" , " \\ _" )
0 commit comments