feat: refector prompt refresh (#7605)

This commit is contained in:
darkskygit
2024-07-26 04:51:07 +00:00
parent 54da85ec62
commit 3f0e4c04d7
29 changed files with 208 additions and 515 deletions

View File

@@ -9,10 +9,9 @@ import Sinon from 'sinon';
import { AuthService } from '../src/core/auth';
import { WorkspaceModule } from '../src/core/workspaces';
import { prompts } from '../src/data/migrations/utils/prompts';
import { ConfigModule } from '../src/fundamentals/config';
import { CopilotModule } from '../src/plugins/copilot';
import { PromptService } from '../src/plugins/copilot/prompt';
import { prompts, PromptService } from '../src/plugins/copilot/prompt';
import {
CopilotProviderService,
FalProvider,
@@ -95,10 +94,6 @@ test.beforeEach(async t => {
await prompt.set(promptName, 'test', [
{ role: 'system', content: 'hello {{word}}' },
]);
for (const p of prompts) {
await prompt.set(p.name, p.model, p.messages, p.config);
}
});
test.afterEach.always(async t => {

View File

@@ -7,10 +7,9 @@ import Sinon from 'sinon';
import { AuthService } from '../src/core/auth';
import { QuotaModule } from '../src/core/quota';
import { prompts } from '../src/data/migrations/utils/prompts';
import { ConfigModule } from '../src/fundamentals/config';
import { CopilotModule } from '../src/plugins/copilot';
import { PromptService } from '../src/plugins/copilot/prompt';
import { prompts, PromptService } from '../src/plugins/copilot/prompt';
import {
CopilotProviderService,
OpenAIProvider,
@@ -115,13 +114,18 @@ test.beforeEach(async t => {
test('should be able to manage prompt', async t => {
const { prompt } = t.context;
t.is((await prompt.listNames()).length, 0, 'should have no prompt');
const internalPromptCount = (await prompt.listNames()).length;
t.is(internalPromptCount, prompts.length, 'should list names');
await prompt.set('test', 'test', [
{ role: 'system', content: 'hello' },
{ role: 'user', content: 'hello' },
]);
t.is((await prompt.listNames()).length, 1, 'should have one prompt');
t.is(
(await prompt.listNames()).length,
internalPromptCount + 1,
'should have one prompt'
);
t.is(
(await prompt.get('test'))!.finish({}).length,
2,
@@ -136,7 +140,11 @@ test('should be able to manage prompt', async t => {
);
await prompt.delete('test');
t.is((await prompt.listNames()).length, 0, 'should have no prompt');
t.is(
(await prompt.listNames()).length,
internalPromptCount,
'should be delete prompt'
);
t.is(await prompt.get('test'), null, 'should not have the prompt');
});
@@ -795,7 +803,7 @@ test('should be able to run pre defined workflow', async t => {
});
test('should be able to run workflow', async t => {
const { prompt, workflow, executors } = t.context;
const { workflow, executors } = t.context;
executors.text.register();
unregisterCopilotProvider(OpenAIProvider.type);
@@ -803,10 +811,6 @@ test('should be able to run workflow', async t => {
const executor = Sinon.spy(executors.text, 'next');
for (const p of prompts) {
await prompt.set(p.name, p.model, p.messages, p.config);
}
const graphName = 'presentation';
const graph = WorkflowGraphList.find(g => g.name === graphName);
t.truthy(graph, `graph ${graphName} not defined`);