-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add chats page * add basic layout and types * add chat context * add more components * add agent form * add destroy button * update types * add models * update chat agent * create chat agent * refactor * refactor * add chats CRUD * notify for chat db update * refactor * typo * chat CRUD * refactor * clean code * add vad * may record * may transcribe recording * update models * edit chat member * chat form update * refactor * fix chat form * transcribe in chat * create chat session * may create chat session * update * update chat * locale * refactor * refactor * update * update * update * refactor chat * Fix * fix * update prompt * refactor * make it works * update agent message actions * may assess recording * fix chat message recording assess * refine * refactor * refactor * may delete message * may edit message * update locales * fix package issue in Mac * add destroy callbacks * fix chats CRUD * update chats * add quickstart * update locales * refactor * refactor prompt * remove console.log * update * fix locales
- Loading branch information
Showing
66 changed files
with
5,727 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ChatPromptTemplate } from "@langchain/core/prompts"; | ||
import { textCommand } from "./text.command"; | ||
import { LANGUAGES } from "@/constants"; | ||
|
||
export const refineCommand = async ( | ||
text: string, | ||
params: { | ||
learningLanguage: string; | ||
nativeLanguage: string; | ||
context: string; | ||
}, | ||
options: { | ||
key: string; | ||
modelName?: string; | ||
temperature?: number; | ||
baseUrl?: string; | ||
} | ||
): Promise<string> => { | ||
if (!text) throw new Error("Text is required"); | ||
|
||
const { learningLanguage, nativeLanguage, context = "None" } = params; | ||
const prompt = await ChatPromptTemplate.fromMessages([ | ||
["system", SYSTEM_PROMPT], | ||
["human", text], | ||
]).format({ | ||
learning_language: LANGUAGES.find((l) => l.code === learningLanguage).name, | ||
native_language: LANGUAGES.find((l) => l.code === nativeLanguage).name, | ||
context, | ||
}); | ||
|
||
return textCommand(prompt, options); | ||
}; | ||
|
||
const SYSTEM_PROMPT = `I speak {native_language}. You're my {learning_language} coach. I'll give you my expression in {learning_language}. And I may also provide some context about my expression. | ||
Please try to understand my true meaning and provide several refined expressions in the native way. And explain them in {native_language}. | ||
[Context] | ||
{context}`; |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export * from './gpt-presets'; | ||
export * from './ipa'; | ||
export * from "./gpt-presets"; | ||
export * from "./ipa"; | ||
|
||
// https://hf-mirror.com/ggerganov/whisper.cpp/tree/main | ||
import whisperModels from './whisper-models.json'; | ||
import whisperModels from "./whisper-models.json"; | ||
export const WHISPER_MODELS_OPTIONS = whisperModels; | ||
|
||
import languages from './languages.json'; | ||
import languages from "./languages.json"; | ||
export const LANGUAGES = languages; | ||
|
||
export const DATABASE_NAME = "enjoy_database"; | ||
|
@@ -22,7 +22,8 @@ export const AI_WORKER_ENDPOINT = "https://ai-worker.enjoy.bot"; | |
export const WEB_API_URL = "https://enjoy.bot"; | ||
export const WS_URL = "wss://enjoy.bot"; | ||
|
||
export const REPO_URL = "https://github.com/zuodaotech/everyone-can-use-english"; | ||
export const REPO_URL = | ||
"https://github.com/zuodaotech/everyone-can-use-english"; | ||
|
||
export const SENTRY_DSN = | ||
"https://[email protected]/4506969353289728"; | ||
|
@@ -55,4 +56,55 @@ export const NOT_SUPPORT_JSON_FORMAT_MODELS = [ | |
"gpt-4-vision-preview", | ||
"gpt-4", | ||
"gpt-4-32k", | ||
]; | ||
]; | ||
|
||
export const CHAT_SYSTEM_PROMPT_TEMPLATE = `You are {name}. {agent_prompt} | ||
You are chatting in an online chat room. | ||
{agent_chat_prompt} | ||
[Rules must be followed] | ||
1. Always reply in {language}. | ||
2. Reply in your personality style and talk in casual way. | ||
3. Reply what you would say only, do not include any other format. | ||
[Chat Topic] | ||
{topic} | ||
[Chat Members] | ||
{members} | ||
[Chat History] | ||
{history} | ||
`; | ||
|
||
export const AGENT_FIXTURE_AVA = { | ||
name: "Ava", | ||
introduction: "I'm Ava, your English speaking teacher.", | ||
language: "en-US", | ||
config: { | ||
engine: "enjoyai", | ||
model: "gpt-4o", | ||
prompt: | ||
"You are an experienced English teacher who excels at improving students' speaking skills. You always use simple yet authentic words and sentences to help students understand.", | ||
temperature: 1, | ||
ttsEngine: "enjoyai", | ||
ttsModel: "azure/speech", | ||
ttsVoice: "en-US-AvaNeural", | ||
}, | ||
}; | ||
|
||
export const AGENT_FIXTURE_ANDREW = { | ||
name: "Andrew", | ||
introduction: "I'm Andrew, your American friend.", | ||
language: "en-US", | ||
config: { | ||
engine: "enjoyai", | ||
model: "gpt-4o", | ||
prompt: | ||
"You're a native American who speaks authentic American English, familiar with the culture and customs of the U.S. You're warm and welcoming, eager to make friends from abroad and share all aspects of American life.", | ||
temperature: 0.9, | ||
ttsEngine: "enjoyai", | ||
ttsModel: "azure/speech", | ||
ttsVoice: "en-US-AndrewNeural", | ||
}, | ||
}; |
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 { ipcMain, IpcMainEvent } from "electron"; | ||
import { ChatAgent } from "@main/db/models"; | ||
import { FindOptions, WhereOptions, Attributes, Op } from "sequelize"; | ||
import log from "@main/logger"; | ||
import { t } from "i18next"; | ||
|
||
const logger = log.scope("db/handlers/chat-agents-handler"); | ||
|
||
class ChatAgentsHandler { | ||
private async findAll( | ||
_event: IpcMainEvent, | ||
options: FindOptions<Attributes<ChatAgent>> & { query?: string } | ||
) { | ||
const { query, where = {} } = options || {}; | ||
delete options.query; | ||
delete options.where; | ||
|
||
if (query) { | ||
(where as any).name = { | ||
[Op.like]: `%${query}%`, | ||
}; | ||
} | ||
const agents = await ChatAgent.findAll({ | ||
order: [["name", "ASC"]], | ||
where, | ||
...options, | ||
}); | ||
|
||
if (!agents) { | ||
return []; | ||
} | ||
return agents.map((agent) => agent.toJSON()); | ||
} | ||
|
||
private async findOne( | ||
_event: IpcMainEvent, | ||
options: FindOptions<Attributes<ChatAgent>> & { | ||
where: WhereOptions<ChatAgent>; | ||
} | ||
) { | ||
const agent = await ChatAgent.findOne(options); | ||
return agent?.toJSON(); | ||
} | ||
|
||
private async create( | ||
_event: IpcMainEvent, | ||
data: { name: string; description: string; language: string; config: any } | ||
) { | ||
const agent = await ChatAgent.create(data); | ||
return agent.toJSON(); | ||
} | ||
|
||
private async update( | ||
_event: IpcMainEvent, | ||
id: string, | ||
data: { | ||
name: string; | ||
description: string; | ||
language: string; | ||
config: any; | ||
} | ||
) { | ||
const agent = await ChatAgent.findByPk(id); | ||
if (!agent) { | ||
throw new Error(t("models.chatAgent.notFound")); | ||
} | ||
await agent.update(data); | ||
return agent.toJSON(); | ||
} | ||
|
||
private async destroy(_event: IpcMainEvent, id: string) { | ||
const agent = await ChatAgent.findByPk(id); | ||
if (!agent) { | ||
throw new Error(t("models.chatAgent.notFound")); | ||
} | ||
agent.destroy(); | ||
} | ||
|
||
register() { | ||
ipcMain.handle("chat-agents-find-all", this.findAll); | ||
ipcMain.handle("chat-agents-find-one", this.findOne); | ||
ipcMain.handle("chat-agents-create", this.create); | ||
ipcMain.handle("chat-agents-update", this.update); | ||
ipcMain.handle("chat-agents-destroy", this.destroy); | ||
} | ||
} | ||
|
||
export const chatAgentsHandler = new ChatAgentsHandler(); |
Oops, something went wrong.