Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Improve Default System Template (#241)
Browse files Browse the repository at this point in the history
* Feat [UI/UX] [Locales] replace hardcoded

- [+] feat(locales): replace hardcoded OpenAI with variable ServiceProvider in cn, en, and id locales

* Feat [UI/UX] [Constant] [DEFAULT System Template] replace hardcoded

- [+] feat(constant.ts): replace hardcoded OpenAI with dynamic ServiceProvider variable in DEFAULT_SYSTEM_TEMPLATE

* Improve [UI/UX] [Chat] "fillTemplateWith"

- [+] feat(chat.ts): add DEFAULT_MODELS to modelConfig
- [+] fix(chat.ts): replace replaceAll with regex in output string replacement
- [+] refactor(chat.ts): use const instead of let for cutoff variable
  • Loading branch information
H0llyW00dzZ authored Feb 5, 2024
1 parent b57fdf1 commit 0f12afa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lan
// example configure this by costumize the default system message in the settings page
// just change a chatgpt and "OPENAI" to "GOOGLE" and "GEMINI-PRO"
export const DEFAULT_SYSTEM_TEMPLATE = `
You are ChatGPT, a large language model trained by OpenAI.
You are ChatGPT, a large language model trained by {{ServiceProvider}}.
Knowledge cutoff: {{cutoff}}
Current model: {{model}}
Current time: {{time}}
Expand Down
2 changes: 1 addition & 1 deletion app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ const cn = {
// don't linting this `System_Template` keep format like this
// this a object not string
System_Template: `
您正在与ChatGPT对话,这是一个由OpenAI训练的大型语言模型
您正在与ChatGPT对话,这是一个由{{ServiceProvider}}训练的大型语言模型
知识截止点: {{cutoff}}
当前模型: {{model}}
当前时间: {{time}}
Expand Down
2 changes: 1 addition & 1 deletion app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ const en: LocaleType = {
// don't linting this `System_Template` keep format like this
// this a object not string
System_Template: `
You are ChatGPT, a large language model trained by OpenAI.
You are ChatGPT, a large language model trained by {{ServiceProvider}}.
Knowledge cutoff: {{cutoff}}
Current model: {{model}}
Current time: {{time}}
Expand Down
2 changes: 1 addition & 1 deletion app/locales/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ const id: PartialLocaleType = {
// don't linting this `System_Template` keep format like this
// this a object not string
System_Template: `
Anda adalah ChatGPT, sebuah model bahasa besar yang dilatih oleh OpenAI.
Anda adalah ChatGPT, sebuah model bahasa besar yang dilatih oleh {{ServiceProvider}}.
Batas pengetahuan: {{cutoff}}
Model saat ini: {{model}}
Waktu saat ini: {{time}}
Expand Down
15 changes: 12 additions & 3 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ModelConfig, ModelType, useAppConfig } from "./config";
import { createEmptyMask, Mask } from "./mask";
import {
DEFAULT_INPUT_TEMPLATE,
DEFAULT_MODELS,
DEFAULT_SYSTEM_TEMPLATE,
KnowledgeCutOffDate,
ModelProvider,
Expand Down Expand Up @@ -92,10 +93,17 @@ function countMessages(msgs: ChatMessage[]) {
}

function fillTemplateWith(input: string, modelConfig: ModelConfig) {
let cutoff =
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
// Find the model in the DEFAULT_MODELS array that matches the modelConfig.model
const modelInfo = DEFAULT_MODELS.find(m => m.name === modelConfig.model);
if (!modelInfo) {
throw new Error(`Model ${modelConfig.model} not found in DEFAULT_MODELS array.`);
}
// Directly use the providerName from the modelInfo
const serviceProvider = modelInfo.provider.providerName;

const vars = {
ServiceProvider: serviceProvider,
cutoff,
model: modelConfig.model,
time: new Date().toLocaleString(),
Expand All @@ -112,7 +120,8 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
}

Object.entries(vars).forEach(([name, value]) => {
output = output.replaceAll(`{{${name}}}`, value);
const regex = new RegExp(`{{${name}}}`, 'g');
output = output.replace(regex, value.toString()); // Ensure value is a string
});

return output;
Expand Down

0 comments on commit 0f12afa

Please sign in to comment.