-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from BBai-Tips/staging
generate tools manifest file to facilitate loading from compiled binary
- Loading branch information
Showing
25 changed files
with
425 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env -S deno run --allow-read --allow-run --allow-write | ||
|
||
import { parseArgs } from '@std/cli'; | ||
import { walk } from '@std/fs'; | ||
import { join } from '@std/path'; | ||
|
||
const TOOLS_DIR = './src/llms/tools'; | ||
const MAIN_FILE = 'src/main.ts'; | ||
const OUTPUT_FILE = '../build/bbai-api'; | ||
|
||
const args = parseArgs(Deno.args, { | ||
string: ['target', 'output'], | ||
alias: { t: 'target', o: 'output' }, | ||
}); | ||
|
||
const target = args.target ? `--target ${args.target}` : ''; | ||
const output = args.output || OUTPUT_FILE; | ||
|
||
async function getIncludeFiles() { | ||
const includeFiles = []; | ||
for await ( | ||
const entry of walk(TOOLS_DIR, { | ||
exts: ['.ts', '.tsx', '.json'], | ||
followSymlinks: false, | ||
}) | ||
) { | ||
if (entry.isFile) { | ||
includeFiles.push(entry.path); | ||
} | ||
} | ||
return includeFiles; | ||
} | ||
|
||
// Run the generate-tools-manifest task | ||
const manifestProcess = new Deno.Command('deno', { | ||
args: ['task', 'generate-tools-manifest'], | ||
stdout: 'piped', | ||
stderr: 'piped', | ||
}); | ||
const { code: manifestCode, stdout: manifestStdout, stderr: manifestStderr } = await manifestProcess.output(); | ||
|
||
const manifestOutput = new TextDecoder().decode(manifestStdout); | ||
const manifestErrorOutput = new TextDecoder().decode(manifestStderr); | ||
|
||
if (manifestCode !== 0) { | ||
if (manifestErrorOutput !== '') console.error(manifestErrorOutput); | ||
console.error('Failed to generate tools manifest'); | ||
Deno.exit(manifestCode); | ||
} | ||
|
||
console.log(manifestOutput); | ||
if (manifestErrorOutput !== '') console.error(manifestErrorOutput); | ||
|
||
const includeFiles = await getIncludeFiles(); | ||
const includeArgs = includeFiles.map((file) => `--include ${file}`).join(' '); | ||
console.log(`Including files for core tools:\n${JSON.stringify(includeFiles, null, 2)}`); | ||
|
||
// Compile the API | ||
const compileProcess = new Deno.Command('deno', { | ||
args: [ | ||
'compile', | ||
'-A', | ||
'--unstable', | ||
target, | ||
'--output', | ||
output, | ||
...includeArgs.split(' '), | ||
MAIN_FILE, | ||
].filter(Boolean), | ||
stdout: 'piped', | ||
stderr: 'piped', | ||
}); | ||
|
||
const { code: compileCode, stdout: compileStdout, stderr: compileStderr } = await compileProcess.output(); | ||
|
||
const compileOutput = new TextDecoder().decode(compileStdout); | ||
const compileErrorOutput = new TextDecoder().decode(compileStderr); | ||
|
||
if (compileCode !== 0) { | ||
if (compileErrorOutput !== '') console.error(compileErrorOutput); | ||
console.error('Compilation failed'); | ||
Deno.exit(compileCode); | ||
} | ||
|
||
console.log(compileOutput); | ||
if (compileErrorOutput !== '') console.error(compileErrorOutput); | ||
|
||
console.log('Compilation successful'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//import { walk } from "@std/fs"; | ||
import { join } from '@std/path'; | ||
import { stripIndents } from 'common-tags'; | ||
|
||
// paths relative to api/deno.jsonc | ||
const TOOLS_DIR = './src/llms/tools'; | ||
const OUTPUT_FILE = './src/llms/tools_manifest.ts'; | ||
|
||
async function generateCoreTools() { | ||
const tools = []; | ||
|
||
//for await (const entry of walk(TOOLS_DIR, { maxDepth: 1 })) { | ||
for await (const entry of Deno.readDir(TOOLS_DIR)) { | ||
if (entry.isDirectory && entry.name.endsWith('.tool')) { | ||
const infoPath = join(TOOLS_DIR, entry.name, 'info.json'); | ||
try { | ||
const info = JSON.parse(await Deno.readTextFile(infoPath)); | ||
tools.push({ | ||
toolNamePath: entry.name, | ||
metadata: info, | ||
}); | ||
} catch (error) { | ||
console.error(`Error reading ${infoPath}:`, error); | ||
} | ||
} | ||
} | ||
|
||
const fileContent = `// This file is auto-generated. Do not edit manually. | ||
import type { ToolMetadata } from './llmToolManager.ts'; | ||
interface CoreTool { | ||
toolNamePath: string; | ||
metadata: ToolMetadata; | ||
} | ||
export const CORE_TOOLS: Array<CoreTool> = ${JSON.stringify(tools, null, '\t')}; | ||
`; | ||
|
||
await Deno.writeTextFile(OUTPUT_FILE, fileContent); | ||
console.log(`Generated ${OUTPUT_FILE} with ${tools.length} tools.`); | ||
} | ||
|
||
await generateCoreTools(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
api/src/llms/tools/searchAndReplaceMultilineCode.tool/formatter.browser.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** @jsxImportSource preact */ | ||
import type { JSX } from 'preact'; | ||
import type { LLMToolInputSchema, LLMToolRunResultContent } from 'api/llms/llmTool.ts'; | ||
|
||
export const formatToolUse = (toolInput: LLMToolInputSchema): JSX.Element => { | ||
return ( | ||
<div className='tool-use'> | ||
</div> | ||
); | ||
}; | ||
|
||
export const formatToolResult = (toolResult: LLMToolRunResultContent): JSX.Element => { | ||
return ( | ||
<div className='tool-result'> | ||
</div> | ||
); | ||
}; |
9 changes: 9 additions & 0 deletions
9
api/src/llms/tools/searchAndReplaceMultilineCode.tool/formatter.console.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { LLMToolInputSchema, LLMToolRunResultContent } from 'api/llms/llmTool.ts'; | ||
|
||
export const formatToolUse = (toolInput: LLMToolInputSchema): string => { | ||
return ''; | ||
}; | ||
|
||
export const formatToolResult = (toolResult: LLMToolRunResultContent): string => { | ||
return ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.