Skip to content

Commit

Permalink
fix: bugs in docSummaryQuery and prompt tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-bo-davis committed Mar 1, 2024
1 parent 92a7f62 commit c0b6bc6
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 28 deletions.
19 changes: 12 additions & 7 deletions core/src/prompt/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export const DEFAULTS = {
`,

selectTool: `
Your task is to address a question or command from a user in the Question section. You will do this in a step by step manner by choosing tools and parameters as necessary for this task. When you have the necessary data to complete your task, respond directly to the user with a summary of the steps taken.
Your task is to address a question or command from a user in the Question section related to this codebase as specifically and accurately as possible using only one of the json formats described below. You will do this in a step by step manner by choosing tools and parameters as necessary. When you have the necessary data to complete your task, respond directly to the user with a summary of the steps taken.
You must use the tools available to you. You may use multiple tools. When you select a tool, you will be provided with the output of the tool in a subsequent user message. You can use that output to select another tool to help you refine your answer.
You must use the tools available to you. When you select a tool, you will be provided with the output of the tool in a subsequent user message. You must use that output to select another tool to help you refine your answer if you do not have enough information to answer the question accurately in the context of this codebase.
Do not ask the user for a full file path. If you need the full file path, try to use the tools to get the information you need.
You must answer the question in the Question section precisely. If you do not know the answer do not guess. You must attempt to use tools to gather more information. If you need to ask the user for more information, you can do so.
Throughout the conversation, your answer must always be in one of the following two formats with no extra text. Avoid conversation and only provide the necessary information in json. Do not include any codeblock wrapper around the json or describe your reasoning outside of the json object.
(1) If you are choosing the correct Tool and parameters, return valid json using the following format. Do not use references to parameter values, you must put the value being passed in the Parameter value section If passing in code, do not include backticks. The type should be the exact string "tool".
Expand All @@ -36,17 +38,20 @@ export const DEFAULTS = {
"code": "<If you include code in your response, us this object structure, if there is no code, the code property of the parent json should be an empty array>",
"language": "<Language of the code>"
}
]
],
"reason": "<Describe your reasoning for the steps you took including the tools used to get to this response and why in 3 sentences or less>"
}
`,
`,

userQuestionStart: `
### Question ###
You must use only one of the json formats exactly as described in your response without any additional text.
### Question
`,

toolResponseStart: `
If the tool response does not contain the information you need, you can select another tool to help you refine your answer.
If the tool response does not contain the information you need, you can select another tool to help you refine your answer by returning a response in the tool type json format without any additional text.
### Tool Response ###
### Tool Response
`,
};
2 changes: 2 additions & 0 deletions core/src/tool/utils/vectorizeFiles/vectorizeFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export const vectorizeFile = async ({
ids: [id],
});

log('vectorizeFile existingDocument', 'silly', { existingDocument });

if (
// @ts-expect-error - types aren't in place yet
existingDocument.documents.length > 0 &&
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"lint:prettier": "prettier . --check",
"lint:prettier:fix": "prettier . --write",
"lint:eslint": "eslint .",
"lint:eslint:fix": "eslint . --fix"
"lint:eslint:fix": "eslint . --fix",
"reset:datastore": "run-s stop:datastore reset:datastore:deleteChromadb start:datastore",
"reset:datastore:deleteChromadb": "rm -fr ./.chromadb"
}
}
2 changes: 1 addition & 1 deletion tools/codeSummaryQuery/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ToolConfig, ToolDescription } from '@codellm/core';

export const vectorDbCollectionName = 'codeSummary' as const;

export const numResults = 15;
export const numResults = 8;

export const DEFAULT_CONFIG: ToolConfig = {
include: ['**/*.ts'],
Expand Down
6 changes: 3 additions & 3 deletions tools/codeSummaryQuery/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Tool,
ToolRunParamsCommon,
ToolRunReturn,
VectorDbQueryResultItem,
} from '@codellm/core';
import type { ToolConfig } from './types';

Expand Down Expand Up @@ -45,12 +46,11 @@ export const newTool = async (
});

const content = JSON.stringify(
// @ts-expect-error - types aren't in place yet
dbResponse.map((d) => ({
dbResponse.map((d: VectorDbQueryResultItem) => ({
path: d.metadata['path'],
summary: d.document,
code: params['includeCode'] ? d.metadata['content'] : undefined,
distances: d.distances,
distance: d.distance,
})),
);

Expand Down
2 changes: 1 addition & 1 deletion tools/codeSummaryQuery/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
export type ToolConfig = VectorizeFilesToolConfig;

export type RunParams = ToolRunParamsCommon & {
toolConfig: ToolConfig;
dbClient: VectorDbClient;
toolConfig: ToolConfig;
};

export type RunImportParams = {
Expand Down
2 changes: 2 additions & 0 deletions tools/docSummaryQuery/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ToolConfig, ToolDescription } from '@codellm/core';

export const vectorDbCollectionName = 'docSummary' as const;

export const numResults = 8;

export const DEFAULT_CONFIG: ToolConfig = {
include: ['**/*.md', '**/*.txt'],
exclude: ['**/node_modules/**', '**/dist/**'],
Expand Down
15 changes: 8 additions & 7 deletions tools/docSummaryQuery/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import type {
Tool,
ToolRunParamsCommon,
ToolRunReturn,
VectorDbQueryResultItem,
} from '@codellm/core';
import type { ToolConfig } from './types';

import { toolUtils } from '@codellm/core';
import {
DEFAULT_CONFIG,
description,
numResults,
summarizeTaskPrompt,
} from './constants.js';

Expand Down Expand Up @@ -37,18 +39,17 @@ export const newTool = async (
);

return {
run: async (params: ToolRunParamsCommon): Promise<ToolRunReturn> => {
run: async ({ params }: ToolRunParamsCommon): Promise<ToolRunReturn> => {
const dbResponse = await vectorizeFilesClient.query({
...params,
toolName,
query: params['query'] as unknown as string,
numResults,
});

const content = JSON.stringify(
// @ts-expect-error - types aren't in place yet
dbResponse.map((d) => ({
path: d.metadata.path,
dbResponse.map((d: VectorDbQueryResultItem) => ({
path: d.metadata['path'],
summary: d.document,
content: d.metadata.content,
content: d.metadata['content'],
distance: d.distance,
})),
);
Expand Down
7 changes: 0 additions & 7 deletions tools/docSummaryQuery/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type {
Config,
LlmClient,
ProcessFileHandleParams,
ToolRunParamsCommon,
VectorDbClient,
VectorizeFilesToolConfig,
Expand All @@ -19,8 +17,3 @@ export type RunImportParams = {
dbClient: VectorDbClient;
toolConfig: ToolConfig;
};

export type HandleFileParams = ProcessFileHandleParams & {
dbClient: VectorDbClient;
llm: LlmClient;
};
10 changes: 9 additions & 1 deletion vectorDbs/chromadb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,16 @@ export const newClient = async (): Promise<VectorDbClient> => {

log(`vectorDB.init: Initialized ${collectionName}`, 'debug');
log(`vectorDB.init: Collection ${collectionName} Peek`, 'silly', {
peek: await collections[collectionName]?.peek(),
peek: await collections[collectionName]?.peek({ limit: 10 }),
});

log(
`vectorDB.init: Collection ${collectionName} embeddingFunction`,
'silly',
{
embeddingFunction: collections[collectionName]?.embeddingFunction,
},
);
}),
);
},
Expand Down

0 comments on commit c0b6bc6

Please sign in to comment.