From 90a5c1976d79e9babd096959697437544bb93f28 Mon Sep 17 00:00:00 2001
From: BrandonStudio <55647556+BrandonStudio@users.noreply.github.com>
Date: Thu, 19 Dec 2024 08:41:17 +0000
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(plugin):=20update?=
=?UTF-8?q?=20plugin=20prompt=20(#4860)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/prompts/plugin/index.test.ts | 17 +++++-----
src/prompts/plugin/index.ts | 4 +--
src/prompts/plugin/tools.test.ts | 31 +++++++++----------
src/prompts/plugin/tools.ts | 13 +++-----
.../__tests__/__snapshots__/chat.test.ts.snap | 17 +++++-----
src/services/__tests__/chat.test.ts | 30 +++++++-----------
6 files changed, 47 insertions(+), 65 deletions(-)
diff --git a/src/prompts/plugin/index.test.ts b/src/prompts/plugin/index.test.ts
index 8ffabf189d2d..19810a877144 100644
--- a/src/prompts/plugin/index.test.ts
+++ b/src/prompts/plugin/index.test.ts
@@ -17,15 +17,12 @@ describe('pluginPrompts', () => {
},
];
- const expected = `
-
-The tools you can use below
-
+ const expected = `
+
-API 1
-
-
-`;
+API 1
+
+`;
expect(pluginPrompts({ tools })).toBe(expected);
});
@@ -33,9 +30,9 @@ describe('pluginPrompts', () => {
it('should generate plugin prompts without tools', () => {
const tools: Tool[] = [];
- const expected = `
+ const expected = `
-`;
+`;
expect(pluginPrompts({ tools })).toBe(expected);
});
diff --git a/src/prompts/plugin/index.ts b/src/prompts/plugin/index.ts
index 57ec35c430e5..a3d1e9b5cb44 100644
--- a/src/prompts/plugin/index.ts
+++ b/src/prompts/plugin/index.ts
@@ -1,9 +1,9 @@
import { Tool, toolsPrompts } from './tools';
export const pluginPrompts = ({ tools }: { tools: Tool[] }) => {
- const prompt = `
+ const prompt = `
${toolsPrompts(tools)}
-`;
+`;
return prompt.trim();
};
diff --git a/src/prompts/plugin/tools.test.ts b/src/prompts/plugin/tools.test.ts
index 4cbbbb1c1ee2..1cf5d8324d1c 100644
--- a/src/prompts/plugin/tools.test.ts
+++ b/src/prompts/plugin/tools.test.ts
@@ -11,7 +11,7 @@ describe('Prompt Generation Utils', () => {
desc: 'Test API Description',
};
- expect(apiPrompt(api)).toBe(`Test API Description`);
+ expect(apiPrompt(api)).toBe(`Test API Description`);
});
});
@@ -30,10 +30,10 @@ describe('Prompt Generation Utils', () => {
],
};
- const expected = `
-Test System Role
-API 1 Description
-`;
+ const expected = `
+Test System Role
+API 1 Description
+`;
expect(toolPrompt(tool)).toBe(expected);
});
@@ -50,10 +50,10 @@ describe('Prompt Generation Utils', () => {
],
};
- const expected = `
+ const expected = `
-API 1 Description
-`;
+API 1 Description
+`;
expect(toolPrompt(tool)).toBe(expected);
});
@@ -85,17 +85,14 @@ describe('Prompt Generation Utils', () => {
},
];
- const expected = `
-The tools you can use below
-
+ const expected = `
-API 1
-
-
+API 1
+
+
-API 2
-
-`;
+API 2
+`;
expect(toolsPrompts(tools)).toBe(expected);
});
diff --git a/src/prompts/plugin/tools.ts b/src/prompts/plugin/tools.ts
index 02772903bbb6..be4258006ade 100644
--- a/src/prompts/plugin/tools.ts
+++ b/src/prompts/plugin/tools.ts
@@ -9,20 +9,17 @@ export interface Tool {
systemRole?: string;
}
-export const apiPrompt = (api: API) => `${api.desc}`;
+export const apiPrompt = (api: API) => `${api.desc}`;
export const toolPrompt = (tool: Tool) =>
- `
-${tool.systemRole ? `${tool.systemRole}` : ''}
+ `
+${tool.systemRole ? `${tool.systemRole}` : ''}
${tool.apis.map((api) => apiPrompt(api)).join('\n')}
-`;
+`;
export const toolsPrompts = (tools: Tool[]) => {
const hasTools = tools.length > 0;
if (!hasTools) return '';
- return `
-The tools you can use below
-${tools.map((tool) => toolPrompt(tool)).join('\n')}
-`;
+ return tools.map((tool) => toolPrompt(tool)).join('\n');
};
diff --git a/src/services/__tests__/__snapshots__/chat.test.ts.snap b/src/services/__tests__/__snapshots__/chat.test.ts.snap
index 319bc483a92f..b493cec91776 100644
--- a/src/services/__tests__/__snapshots__/chat.test.ts.snap
+++ b/src/services/__tests__/__snapshots__/chat.test.ts.snap
@@ -4,11 +4,9 @@ exports[`ChatService > createAssistantMessage > with tools messages > work with
{
"messages": [
{
- "content": "
-
-The tools you can use below
-
-Whenever a description of an image is given, use lobe-image-designer to create the images and then summarize the prompts used to generate the images in plain text. If the user does not ask for a specific number of images, default to creating four captions to send to lobe-image-designer that are written to be as diverse as possible.
+ "content": "
+
+Whenever a description of an image is given, use lobe-image-designer to create the images and then summarize the prompts used to generate the images in plain text. If the user does not ask for a specific number of images, default to creating four captions to send to lobe-image-designer that are written to be as diverse as possible.
All captions sent to lobe-image-designer must abide by the following policies:
@@ -31,11 +29,10 @@ exports[`ChatService > createAssistantMessage > with tools messages > work with
- If any creative professional or studio is named, substitute the name with a description of their style that does not reference any specific people, or delete the reference if they are unknown. DO NOT refer to the artist or studio's style.
The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.
-All descriptions sent to lobe-image-designer should be a paragraph of text that is extremely descriptive and detailed. Each should be more than 3 sentences long.
-Create images from a text-only prompt.
-
-
-",
+All descriptions sent to lobe-image-designer should be a paragraph of text that is extremely descriptive and detailed. Each should be more than 3 sentences long.
+Create images from a text-only prompt.
+
+",
"role": "system",
},
{
diff --git a/src/services/__tests__/chat.test.ts b/src/services/__tests__/chat.test.ts
index dfc19f2b7062..42daa2212e06 100644
--- a/src/services/__tests__/chat.test.ts
+++ b/src/services/__tests__/chat.test.ts
@@ -296,15 +296,12 @@ describe('ChatService', () => {
],
messages: [
{
- content: `
-
-The tools you can use below
-
-The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.
-Get data from users
-
-
-`,
+ content: `
+
+The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.
+Get data from users
+
+`,
role: 'system',
},
{ content: 'https://vercel.com/ 请分析 chatGPT 关键词\n\n', role: 'user' },
@@ -401,15 +398,12 @@ describe('ChatService', () => {
{
content: `system
-
-
-The tools you can use below
-
-The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.
-Get data from users
-
-
-`,
+
+
+The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.
+Get data from users
+
+`,
role: 'system',
},
{ content: 'https://vercel.com/ 请分析 chatGPT 关键词\n\n', role: 'user' },