Skip to content

Commit

Permalink
(feature) basic function calling (#425)
Browse files Browse the repository at this point in the history
* function calling initial commit

* function calling works at a basic level

* refactor styles and base classes

* add missing file

* lint

* lint

* lint

* move interfaces

* 3.20.0
  • Loading branch information
rjmacarthy authored Dec 16, 2024
1 parent 68d3460 commit 8b8181c
Show file tree
Hide file tree
Showing 34 changed files with 1,674 additions and 650 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.19.25",
"version": "3.20.0",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down Expand Up @@ -159,10 +159,6 @@
"command": "twinny.stopGeneration",
"title": "Stop generation"
},
{
"command": "twinny.getGitCommitMessage",
"title": "Generate git commit message"
},
{
"command": "twinny.disable",
"title": "Disable twinny",
Expand Down
18 changes: 12 additions & 6 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const EVENT_NAME = {
twinnyNewDocument: "twinny-new-document",
twinnyNotification: "twinny-notification",
twinnyOnCompletion: "twinny-on-completion",
twinnyOnEnd: "twinny-on-end",
twinnyOnCompletionEnd: "twinny-on-end",
twinnyOnLoading: "twinny-on-loading",
twinnyOpenDiff: "twinny-open-diff",
twinnyRerankThresholdChanged: "twinny-rerank-threshold-changed",
Expand Down Expand Up @@ -104,7 +104,6 @@ export const TWINNY_COMMAND_NAME = {
openPanelChat: "twinny.openPanelChat",
openChat: "twinny.openChat",
refactor: "twinny.refactor",
sendTerminalText: "twinny.sendTerminalText",
settings: "twinny.settings",
stopGeneration: "twinny.stopGeneration",
templateCompletion: "twinny.templateCompletion",
Expand All @@ -122,6 +121,12 @@ export const CONVERSATION_EVENT_NAME = {
setActiveConversation: "twinny.set-active-conversation",
}

export const TOOL_EVENT_NAME = {
runAllTools: "run-all-tools",
runTool: "run-tool",
rejectTool: "run-on-tool",
}

export const PROVIDER_EVENT_NAME = {
addProvider: "twinny.add-provider",
copyProvider: "twinny.copy-provider",
Expand Down Expand Up @@ -171,18 +176,19 @@ export const EXTENSION_SETTING_KEY = {

export const EXTENSION_CONTEXT_NAME = {
twinnyConversationHistory: "twinnyConversationHistory",
twinnyEnableRag: "twinnyEnableRag",
twinnyEnableTools: "twinnyEnableTools",
twinnyGeneratingText: "twinnyGeneratingText",
twinnyManageProviders: "twinnyManageProviders",
twinnyManageTemplates: "twinnyManageTemplates",
twinnyReviewTab: "twinnyReviewTab",
twinnyRerankThreshold: "twinnyRerankThreshold",
twinnyMaxChunkSize: "twinnyMaxChunkSize",
twinnyMinChunkSize: "twinnyMinChunkSize",
twinnyOverlapSize: "twinnyOverlapSize",
twinnyRelevantFilePaths: "twinnyRelevantFilePaths",
twinnyRelevantCodeSnippets: "twinnyRelevantCodeSnippets",
twinnyRelevantFilePaths: "twinnyRelevantFilePaths",
twinnyRerankThreshold: "twinnyRerankThreshold",
twinnyReviewTab: "twinnyReviewTab",
twinnySymmetryTab: "twinnySymmetryTab",
twinnyEnableRag: "twinnyEnableRag",
}

export const EXTENSION_SESSION_NAME = {
Expand Down
151 changes: 151 additions & 0 deletions src/common/tool-definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { JSONSchema7 } from "json-schema"

import { FunctionTool } from "./types"

export const tools: FunctionTool[] = [
{
type: "function",
function: {
name: "openFile",
description: "Open a file in the editor",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "Path to the file relative to workspace root"
},
preview: {
type: "boolean",
description: "Open in preview mode"
},
viewColumn: {
type: "string",
enum: ["beside", "active", "new"],
description: "Where to open the file"
},
encoding: {
type: "string",
description: "File encoding (e.g. 'utf-8')"
},
revealIfOpen: {
type: "boolean",
description: "If true, reveal the tab if the file is already open"
}
},
required: ["path"]
} satisfies JSONSchema7
}
},

{
type: "function",
function: {
name: "editFile",
description: "Edit a file",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "Path to the file relative to workspace root"
},
edit: {
type: "string",
description: "Text edit to apply"
},
createIfNotExists: {
type: "boolean",
description: "Create file if it doesn't exist"
},
backupBeforeEdit: {
type: "boolean",
description: "Create a backup copy before editing"
}
},
required: ["path", "edit"]
} satisfies JSONSchema7
}
},

{
type: "function",
function: {
name: "createFile",
description: "Create a new file in the workspace",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "Relative path from workspace root"
},
content: {
type: "string",
description: "Content to write to file"
},
openAfterCreate: {
type: "boolean",
description: "Whether to open the file after creation"
},
createIntermediateDirs: {
type: "boolean",
description: "Create intermediate directories if they don't exist"
},
fileTemplate: {
type: "string",
description: "Template to use for file content"
},
permissions: {
type: "string",
description: "File permissions (e.g. '0644')"
}
},
required: ["path", "content"]
} satisfies JSONSchema7
}
},

{
type: "function",
function: {
name: "runCommand",
description: "Run a shell command in the integrated terminal",
parameters: {
type: "object",
properties: {
command: {
type: "string",
description: "Command to execute"
},
cwd: {
type: "string",
description: "Working directory relative to workspace root"
},
env: {
type: "object",
description: "Additional environment variables"
},
shell: {
type: "string",
description: "Specific shell to use"
},
timeout: {
type: "number",
description: "Command timeout in milliseconds"
},
captureOutput: {
type: "boolean",
description: "If true, capture command output and return it"
},
runInBackground: {
type: "boolean",
description:
"If true, run the command in background without blocking"
}
},
required: ["command"]
} satisfies JSONSchema7
}
}
]
Loading

0 comments on commit 8b8181c

Please sign in to comment.