Skip to content

Commit a64dcd2

Browse files
committed
Standardize context embedding format
Introduce raw filetype for somethign that should just be embedded directly (like prompts). Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent d1f6ef1 commit a64dcd2

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

lua/CopilotChat/context.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,22 @@ function M.filter_embeddings(copilot, prompt, embeddings)
289289
end
290290

291291
table.insert(embeddings, 1, {
292-
prompt = prompt,
292+
content = prompt,
293293
filename = 'prompt',
294+
filetype = 'raw',
294295
})
295296

296297
-- Get embeddings from outlines
297298
local embedded_data = copilot:embed(vim.tbl_map(function(embed)
298-
if embed.content then
299+
if embed.filetype ~= 'raw' then
299300
return M.outline(embed.content, embed.filename, embed.filetype)
300301
end
301302

302303
return embed
303304
end, embeddings))
304305

305306
-- Rate embeddings by relatedness to the query
306-
local ranked_data = data_ranked_by_relatedness(table.remove(embedded_data, 1), out, 20)
307+
local ranked_data = data_ranked_by_relatedness(table.remove(embedded_data, 1), embedded_data, 20)
307308
log.debug('Ranked data:', #ranked_data)
308309
for i, item in ipairs(ranked_data) do
309310
log.debug(string.format('%s: %s - %s', i, item.score, item.filename))

lua/CopilotChat/copilot.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---@class CopilotChat.copilot.embed
2+
---@field content string
23
---@field filename string
34
---@field filetype string
4-
---@field prompt string?
5-
---@field content string?
65

76
---@class CopilotChat.copilot.ask.opts
87
---@field selection CopilotChat.config.selection?
@@ -304,10 +303,9 @@ local function generate_embedding_request(inputs, model)
304303
dimensions = 512,
305304
input = vim.tbl_map(function(input)
306305
local out = ''
307-
if input.prompt then
308-
out = input.prompt .. '\n'
309-
end
310-
if input.content then
306+
if input.filetype == 'raw' then
307+
out = input.content .. '\n'
308+
else
311309
out = out
312310
.. string.format(
313311
'File: `%s`\n```%s\n%s\n```',

0 commit comments

Comments
 (0)