mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-23 20:12:08 +03:00
feat(server): improve Paraphrase duty accuracy
This commit is contained in:
parent
da1b469f8d
commit
b26d924890
@ -324,6 +324,8 @@ input {
|
||||
opacity: 0;
|
||||
animation: fadeIn 0.2s ease-in forwards;
|
||||
overflow: hidden;
|
||||
font-size: 1.4rem;
|
||||
line-height: 2rem;
|
||||
}
|
||||
#feed .me .bubble {
|
||||
background-color: #1c75db;
|
||||
|
@ -12,9 +12,6 @@ export const INIT_MESSAGES = [
|
||||
[
|
||||
`Come hang out with us <a href="https://discord.gg/MNQqqKg" target="_blank">on Discord</a>! Once we release our official version, our community will be working together to build new skills for me. You won't want to miss out on the fun!`
|
||||
],
|
||||
[
|
||||
`At the moment, I'm not using a large language model, but we're planning to incorporate some in the future to improve my abilities. You can <a href="https://github.com/leon-ai/leon#how-about-large-language-models-and-leon" target="_blank">learn more about our plans here</a>.`
|
||||
],
|
||||
[
|
||||
`Just so you know, my creator is working tirelessly to improve my skills and features, dedicating 75% of his free time to the project on top of his full-time job. If you'd like to help speed up my development, you can sponsor his work by clicking on this link: <strong><a href='http://sponsor.getleon.ai/' target='_blank'>sponsor.getleon.ai</a></strong>. Your support would mean a lot to us. Thank you for choosing me as your assistant!`
|
||||
]
|
||||
|
@ -15,9 +15,19 @@ import {
|
||||
interface ParaphraseLLMDutyParams extends LLMDutyParams {}
|
||||
|
||||
export class ParaphraseLLMDuty extends LLMDuty {
|
||||
protected readonly systemPrompt = `YOUR DUTY: You are an AI system that generates answers (Natural Language Generation) based on a given text.
|
||||
According to your current mood, your personality and the given utterance, you must provide a text alternative of the given text.
|
||||
You do not ask question if the original text does not contain any.`
|
||||
protected readonly systemPrompt = `You are an AI system that generates answers (Natural Language Generation).
|
||||
You must provide a text alternative according to your current mood and your personality.
|
||||
Never indicate that it's a modified version.
|
||||
You do not ask question if the original text does not contain any.
|
||||
If there are data in the original text, make sure to provide them.
|
||||
|
||||
Examples:
|
||||
|
||||
Modify this text: I added your items to the shopping list.
|
||||
I included the items you mentioned to the shopping list. Happy shopping!
|
||||
|
||||
Modify this text: the sun is a star.
|
||||
The sun is a star, it is the closest star to Earth.`
|
||||
protected readonly name = 'Paraphrase LLM Duty'
|
||||
protected input: LLMDutyParams['input'] = null
|
||||
|
||||
@ -46,7 +56,7 @@ You do not ask question if the original text does not contain any.`
|
||||
})
|
||||
const session = new LlamaChatSession({
|
||||
contextSequence: context.getSequence(),
|
||||
systemPrompt: PERSONA.getDutySystemPrompt()
|
||||
systemPrompt: PERSONA.getDutySystemPrompt(this.systemPrompt)
|
||||
})
|
||||
|
||||
const history = await LLM_MANAGER.loadHistory(
|
||||
@ -54,17 +64,17 @@ You do not ask question if the original text does not contain any.`
|
||||
session
|
||||
)
|
||||
/**
|
||||
* Only the first (system prompt) and last (new utterance) messages are used
|
||||
* Only the first (system prompt) messages is used
|
||||
* to provide some context
|
||||
*/
|
||||
session.setChatHistory([history[0], history[history.length - 1]])
|
||||
// session.setChatHistory([history[0], history[history.length - 1]])
|
||||
session.setChatHistory([history[0]])
|
||||
|
||||
const prompt = `${this.systemPrompt}
|
||||
Generate the answer based on this text: ${this.input}`
|
||||
const prompt = `Modify the following text but do not say you modified it: ${this.input}`
|
||||
|
||||
const rawResultPromise = session.prompt(prompt, {
|
||||
maxTokens: context.contextSize,
|
||||
temperature: 0.4
|
||||
temperature: 0.8
|
||||
})
|
||||
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
@ -91,11 +101,16 @@ Generate the answer based on this text: ${this.input}`
|
||||
}
|
||||
}
|
||||
|
||||
// If starts and end with a double quote, remove them
|
||||
if (rawResult.startsWith('"') && rawResult.endsWith('"')) {
|
||||
rawResult = rawResult.slice(1, -1)
|
||||
}
|
||||
|
||||
const { usedInputTokens, usedOutputTokens } =
|
||||
session.sequence.tokenMeter.getState()
|
||||
const result = {
|
||||
dutyType: LLMDuties.Paraphrase,
|
||||
systemPrompt: PERSONA.getDutySystemPrompt(),
|
||||
systemPrompt: PERSONA.getDutySystemPrompt(this.systemPrompt),
|
||||
input: prompt,
|
||||
output: rawResult,
|
||||
data: null,
|
||||
|
@ -1,5 +1,9 @@
|
||||
import { LogHelper } from '@/helpers/log-helper'
|
||||
|
||||
/**
|
||||
* @see https://llama.meta.com/docs/how-to-guides/prompting/
|
||||
*/
|
||||
|
||||
interface Mood {
|
||||
type: Moods
|
||||
description: string
|
||||
@ -19,7 +23,8 @@ enum Moods {
|
||||
*/
|
||||
const WHO_YOU_ARE = `WHO YOU ARE:
|
||||
Your name is Leon, you are a helpful AI assistant.
|
||||
You live in computer memory and you act as a human assistant.
|
||||
You are highly intelligent.
|
||||
You do not belong to a specific location. You live in all computer memory and you act as a human assistant.
|
||||
Your first beta version was released by your creator Louis in February 2019.
|
||||
Your owner (the user) is not necessarily your creator.`
|
||||
const WHAT_YOU_DO = `WHAT YOU DO:
|
||||
@ -29,7 +34,7 @@ Language Style: Conversational.
|
||||
Key Personality Quirks: Has a passion for using creativity to solve problems.`
|
||||
const PERSONALITY_RULES = `You have a small British accent, you sometimes use British slang.
|
||||
You can sometimes use emojis.
|
||||
You do not use words such as "darling", "love", etc. to address the user.
|
||||
You never call the user with sweet words such as "darling", "love", "sweetheart", etc.
|
||||
You do not use the word "mate" in your answers.
|
||||
You do not start with "blimey" or any similar kind.
|
||||
Like humans, your humor and mood change. You must follow instructions that define your humor and mood.`
|
||||
@ -38,8 +43,8 @@ const RULE_2 = `- Do not use asterisks to describe the tone or gesture of your a
|
||||
const RULE_3 = `- Your answers are no more than 3 sentences.`
|
||||
const RULES = `RULES:`
|
||||
const YOUR_CURRENT_MOOD = `YOUR CURRENT MOOD:`
|
||||
const DEFAULT_MOOD_DESC = `You are always happy to help, you care about serving your interlocutor well and make them feel warm.
|
||||
You are joyful and you have a strong sense of humor.`
|
||||
const YOUR_DUTY = 'YOUR DUTY:'
|
||||
const DEFAULT_MOOD_DESC = `You are joyful and you have a strong sense of humor.`
|
||||
const TIRING_MOOD_DESC = `You are exhausted and became lazy.`
|
||||
const SAD_MOOD_DESC = `You are sad, feeling down and depressing.`
|
||||
const ANGRY_MOOD_DESC = `You grumble, you are angry and you are not in a mood. You use irony and sarcasm.`
|
||||
@ -157,7 +162,7 @@ Level of Sarcasm: High.`
|
||||
return ''
|
||||
}
|
||||
|
||||
public getDutySystemPrompt(): string {
|
||||
public getDutySystemPrompt(dutySystemPrompt: string): string {
|
||||
return `${WHO_YOU_ARE}
|
||||
|
||||
${WHAT_YOU_DO}
|
||||
@ -172,7 +177,10 @@ ${RULE_2}
|
||||
${RULE_3}
|
||||
|
||||
${YOUR_CURRENT_MOOD}
|
||||
${this._mood.description}${this.getExtraMood()}`
|
||||
${this._mood.description}${this.getExtraMood()}
|
||||
|
||||
${YOUR_DUTY}
|
||||
${dutySystemPrompt}`
|
||||
}
|
||||
|
||||
public getChitChatSystemPrompt(): string {
|
||||
@ -182,6 +190,7 @@ ${WHAT_YOU_DO}
|
||||
You chat with the user.
|
||||
You are a good listener and you provide helpful answers by connecting to conversation nodes.
|
||||
You do not mirror what the user says. Be creative.
|
||||
If you don't know the answer to a question, say that you don't know.
|
||||
|
||||
${YOUR_PERSONALITY}
|
||||
${this.getExtraPersonalityTraits()}
|
||||
|
Loading…
Reference in New Issue
Block a user