-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
236 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
import { anyDict } from '../types/index.d' | ||
import BrowsePlugin from '../plugins/browse' | ||
import TavilyPlugin from '../plugins/tavily' | ||
import PythonPlugin from '../plugins/python' | ||
|
||
export const availablePlugins: anyDict = { | ||
browse: BrowsePlugin, | ||
python: PythonPlugin, | ||
tavily: TavilyPlugin, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
|
||
import Plugin from '../../src/plugins/plugin' | ||
|
||
export class Plugin1 extends Plugin { | ||
|
||
isEnabled(): boolean { | ||
return true | ||
} | ||
|
||
getName(): string { | ||
return 'plugin1' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Plugin 1' | ||
} | ||
|
||
getRunningDescription(): string { | ||
return 'run1' | ||
} | ||
|
||
getParameters(): any[] { | ||
return [] | ||
} | ||
|
||
async execute(parameters: any): Promise<any> { | ||
return 'result1' | ||
} | ||
} | ||
|
||
export class Plugin2 extends Plugin { | ||
|
||
isEnabled(): boolean { | ||
return true | ||
} | ||
|
||
getName(): string { | ||
return 'plugin2' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Plugin 2' | ||
} | ||
|
||
getPreparationDescription(): string { | ||
return 'prep2' | ||
} | ||
|
||
getRunningDescription(): string { | ||
return 'run2' | ||
} | ||
|
||
getParameters(): any[] { | ||
return [ | ||
{ | ||
name: 'param1', | ||
type: 'string', | ||
description: 'Parameter 1', | ||
required: true | ||
}, | ||
{ | ||
name: 'param2', | ||
type: 'number', | ||
description: 'Parameter 2', | ||
required: false | ||
} | ||
] | ||
} | ||
|
||
async execute(parameters: any): Promise<any> { | ||
return parameters | ||
} | ||
} | ||
|
||
export class Plugin3 extends Plugin { | ||
|
||
getName(): string { | ||
return 'plugin3' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Plugin 3' | ||
} | ||
|
||
getParameters(): any[] { | ||
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
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,76 @@ | ||
|
||
import { vi, beforeEach, expect, test } from 'vitest' | ||
import { Plugin1, Plugin2, Plugin3 } from '../mocks/plugins' | ||
import OpenAI from '../../src/services/openai' | ||
import { store } from '../../src/services/store' | ||
import defaults from '../../defaults/settings.json' | ||
|
||
vi.mock('../../src/plugins/plugins', async () => { | ||
return { | ||
availablePlugins: { | ||
plugin1: Plugin1, | ||
plugin2: Plugin2, | ||
plugin3: Plugin3, | ||
} | ||
} | ||
}) | ||
|
||
beforeEach(() => { | ||
store.config = defaults | ||
store.config.llm.engine = 'mock' | ||
}) | ||
|
||
test('Engine plugin descriptions', () => { | ||
const llm = new OpenAI(store.config) | ||
expect(llm.getToolPreparationDescription('plugin1')).toBeNull() | ||
expect(llm.getToolRunningDescription('plugin1')).toBe('run1') | ||
expect(llm.getToolPreparationDescription('plugin2')).toBe('prep2') | ||
expect(llm.getToolRunningDescription('plugin2')).toBe('run2') | ||
}) | ||
|
||
test('Engine plugin execution', async () => { | ||
const llm = new OpenAI(store.config) | ||
expect(await llm.callTool('plugin1', {})).toStrictEqual('result1') | ||
expect(await llm.callTool('plugin2', { param1: 'a', param2: 1 })).toStrictEqual({ param1: 'a', param2: 1 }) | ||
}) | ||
|
||
test('OpenAI Functions', () => { | ||
const llm = new OpenAI(store.config) | ||
expect(llm.getAvailableTools()).toStrictEqual([ | ||
{ | ||
type: 'function', | ||
function: { | ||
name: 'plugin1', | ||
description: 'Plugin 1', | ||
parameters: { | ||
type: 'object', | ||
properties: { }, | ||
required: [], | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'function', | ||
function: { | ||
name: 'plugin2', | ||
description: 'Plugin 2', | ||
parameters: { | ||
type: 'object', | ||
properties: { | ||
'param1': { | ||
type: 'string', | ||
'enum': undefined, | ||
description: 'Parameter 1', | ||
}, | ||
'param2': { | ||
type: 'number', | ||
'enum': undefined, | ||
description: 'Parameter 2', | ||
}, | ||
}, | ||
required: ['param1'], | ||
}, | ||
}, | ||
}, | ||
]) | ||
}) |