Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 9, 2024
2 parents 9210dd2 + beb41b3 commit 1534103
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 186 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mkdir ./AppData && chmod 777 ./AppData && docker run --restart unless-stopped --
docker run --restart unless-stopped --name sdcb-chats -v ./AppData:/app/AppData -p 8080:8080 sdcb/chats:latest
```

- **数据库初始化**:容器启动后,如果数据库文件不存在,将自动创建并插入初始数据。初始管理员用户名为 `admin`,默认密码为 `please reset your password`。强烈建议您在首次登录后立即前往左下角的用户管理界面,设置一个新密码以确保安全。
- **数据库初始化**:容器启动后,如果数据库文件不存在,将自动创建并插入初始数据。初始管理员用户名为 `chats`,默认密码为 `RESET!!!`。强烈建议您在首次登录后立即前往左下角的用户管理界面,设置一个新密码以确保安全。

通过以上步骤,您将能顺利使用 Docker 部署和运行应用。如果在部署过程中遇到任何问题,可以联系我们。

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mkdir ./AppData && chmod 777 ./AppData && docker run --restart unless-stopped --
docker run --restart unless-stopped --name sdcb-chats -v ./AppData:/app/AppData -p 8080:8080 sdcb/chats:latest
```

- **Database initialization**: After the container starts, if the database file does not exist, it will be automatically created and initial data inserted. The initial admin username is `admin`, and the default password is `please reset your password`. It is strongly recommended that you immediately set a new password in the user management interface at the bottom left after logging in for the first time to ensure security.
- **Database initialization**: After the container starts, if the database file does not exist, it will be automatically created and initial data inserted. The initial admin username is `chats`, and the default password is `RESET!!!`. It is strongly recommended that you immediately set a new password in the user management interface at the bottom left after logging in for the first time to ensure security.

By following the above steps, you will be able to use Docker to successfully deploy and run the application. If you encounter any problems during deployment, feel free to contact us.

Expand Down
27 changes: 27 additions & 0 deletions src/BE/Controllers/Admin/GlobalConfigs/GlobalConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,31 @@ public async Task<ActionResult> UpdateGlobalConfig([FromBody] GlobalConfigDto re
}
return NoContent();
}

[HttpPost]
public async Task<ActionResult> CreateGlobalConfig([FromBody] GlobalConfigDto req, CancellationToken cancellationToken)
{
Config? config = await db.Configs.FindAsync([req.Key], cancellationToken);
if (config != null)
{
return this.BadRequestMessage("Key already exists");
}
// ensure value is valid json
try
{
JsonDocument.Parse(req.Value);
}
catch (JsonException)
{
return this.BadRequestMessage("Invalid JSON");
}
await db.Configs.AddAsync(new Config()
{
Key = req.Key,
Value = req.Value,
Description = req.Description,
}, cancellationToken);
await db.SaveChangesAsync(cancellationToken);
return NoContent();
}
}
4 changes: 2 additions & 2 deletions src/BE/DB/Init/BasicData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ private static void InsertTransactionTypes(ChatsDB db)

private static void InsertModelReferences(ChatsDB db)
{
// Generated from data, hash: c5fc80eafe0435e9a03ed9df3b46fe5755d391047b0f8460d17228b4a10fd886
// Generated from data, hash: ebf7fc3a8c4f38d7efc44b0e1b38633c2af4fea6ec8a42ad73d72299dfdbf6d4
db.ModelReferences.AddRange(
[
new(){ Id=0, ProviderId=0, Name="Test", ShortName=null, IsLegacy=false, MinTemperature=0.00M, MaxTemperature=2.00M, AllowSearch=false, AllowVision=false, AllowSystemPrompt=true, AllowStreaming=true, ContextWindow=2048, MaxResponseTokens=2048, TokenizerId=1, InputTokenPrice1M=0.00000M, OutputTokenPrice1M=0.00000M, CurrencyCode="RMB", },
new(){ Id=0, ProviderId=0, Name="Test", ShortName=null, IsLegacy=false, MinTemperature=0.00M, MaxTemperature=2.00M, AllowSearch=false, AllowVision=true, AllowSystemPrompt=true, AllowStreaming=true, ContextWindow=2048, MaxResponseTokens=2048, TokenizerId=1, InputTokenPrice1M=0.00000M, OutputTokenPrice1M=0.00000M, CurrencyCode="RMB", },
new(){ Id=100, ProviderId=1, Name="gpt-35-turbo-0301", ShortName="gpt-35-turbo", IsLegacy=true, MinTemperature=0.00M, MaxTemperature=2.00M, AllowSearch=false, AllowVision=false, AllowSystemPrompt=true, AllowStreaming=true, ContextWindow=4096, MaxResponseTokens=4096, TokenizerId=1, InputTokenPrice1M=1.50000M, OutputTokenPrice1M=2.00000M, CurrencyCode="USD", },
new(){ Id=101, ProviderId=1, Name="gpt-35-turbo-16k-0613", ShortName="gpt-35-turbo", IsLegacy=true, MinTemperature=0.00M, MaxTemperature=2.00M, AllowSearch=false, AllowVision=false, AllowSystemPrompt=true, AllowStreaming=true, ContextWindow=16385, MaxResponseTokens=16385, TokenizerId=1, InputTokenPrice1M=3.00000M, OutputTokenPrice1M=4.00000M, CurrencyCode="USD", },
new(){ Id=102, ProviderId=1, Name="gpt-35-turbo-0613", ShortName="gpt-35-turbo", IsLegacy=true, MinTemperature=0.00M, MaxTemperature=2.00M, AllowSearch=false, AllowVision=false, AllowSystemPrompt=true, AllowStreaming=true, ContextWindow=4096, MaxResponseTokens=4096, TokenizerId=1, InputTokenPrice1M=1.50000M, OutputTokenPrice1M=2.00000M, CurrencyCode="USD", },
Expand Down
17 changes: 14 additions & 3 deletions src/BE/DB/Init/InitService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Chats.BE.DB.Enums;
using Chats.BE.Services;
using Chats.BE.Services.Configs;
using Chats.BE.Services.Sessions;
using System.Text.Json;

namespace Chats.BE.DB.Init;

Expand Down Expand Up @@ -47,10 +49,10 @@ private static async Task InsertInitialData(IServiceScope scope, ChatsDB db, Can

User adminUser = new()
{
Account = "admin",
Username = "admin",
Account = "chats",
Username = "chats",
CreatedAt = DateTime.UtcNow,
Password = scope.ServiceProvider.GetRequiredService<PasswordHasher>().HashPassword("please reset your password"),
Password = scope.ServiceProvider.GetRequiredService<PasswordHasher>().HashPassword("RESET!!!"),
Enabled = true,
Role = "admin",
UpdatedAt = DateTime.UtcNow,
Expand Down Expand Up @@ -100,6 +102,15 @@ private static async Task InsertInitialData(IServiceScope scope, ChatsDB db, Can
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow,
});
db.Configs.Add(new()
{
Key = DBConfigKey.SiteInfo,
Value = JsonSerializer.Serialize(new SiteInfo()
{
WebsiteRegistrationNumber = null,
CompanyName = "Customized Text(Company name, etc)",
})
});
await db.SaveChangesAsync(cancellationToken);
}
}
13 changes: 3 additions & 10 deletions src/BE/Services/ChatServices/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ public abstract partial class ChatService : IDisposable
public ChatService(Model model)
{
Model = model;
try
if (model.ModelReference.Tokenizer is not null)
{
if (model.ModelReference.Tokenizer is not null)
{
Tokenizer = TiktokenTokenizer.CreateForEncoding(model.ModelReference.Tokenizer.Name);
}
else
{
Tokenizer = TiktokenTokenizer.CreateForModel(Model.ModelReference.Name);
}
Tokenizer = TiktokenTokenizer.CreateForEncoding(model.ModelReference.Tokenizer.Name);
}
catch (NotSupportedException)
else
{
Tokenizer = TiktokenTokenizer.CreateForEncoding("cl100k_base");
}
Expand Down
4 changes: 2 additions & 2 deletions src/BE/Services/Configs/DBConfigKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class DBConfigKey
{
public const string JwtSecretKey = "JwtSecretKey";

public const string TencentSms = "TencentSms";
public const string TencentSms = "tencentSms";

public const string SiteInfo = "SiteInfo";
public const string SiteInfo = "siteInfo";
}
15 changes: 3 additions & 12 deletions src/BE/Services/Configs/SiteInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

namespace Chats.BE.Services.Configs;

public record Contact
{
[JsonPropertyName("qqGroupNumber")]
public required string QQGroupNumber { get; init; }

[JsonPropertyName("qqGroupQrCodeLink")]
public required string QQGroupQrCodeLink { get; init; }
}

public record SiteInfo
{
[JsonPropertyName("filingNumber")]
public required string WebsiteRegistrationNumber { get; init; }
public string? WebsiteRegistrationNumber { get; init; }

[JsonPropertyName("contact")]
public required Contact Contact { get; init; }
[JsonPropertyName("companyName")]
public string? CompanyName { get; init; }
}
10 changes: 4 additions & 6 deletions src/FE/apis/clientApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ export const changeUserPassword = (params: PostUserPassword) => {

export const getUserMessages = (chatId: string): Promise<ChatMessage[]> => {
const fetchService = useFetch();
return fetchService
.get(`/api/messages/${chatId}`)
.then((data: any) => {
return calculateMessages(data) as any;
});
return fetchService.get(`/api/messages/${chatId}`).then((data: any) => {
return calculateMessages(data) as any;
});
};

export const getChatsByPaging = (
Expand Down Expand Up @@ -227,4 +225,4 @@ export const deleteUserApiKey = (id: number) => {
export const getModelUsage = (modelId: number) => {
const fetchServer = useFetch();
return fetchServer.get<ModelUsageDto>('/api/models/' + modelId + '/usage');
}
};
2 changes: 1 addition & 1 deletion src/FE/components/Admin/ModelKeys/ModelKeysModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const ModelKeysModal = (props: IProps) => {
field={field}
items={feModelProviders.map((p) => ({
value: p.id.toString(),
name: p.name,
name: t(p.name),
}))}
/>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/FE/components/Admin/Users/UserInitialConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const UserInitialConfigModal = (props: IProps) => {
name: '',
price: 0,
loginType: '-',
invitationCodeId: '-',
},
});

Expand Down Expand Up @@ -243,7 +244,7 @@ export const UserInitialConfigModal = (props: IProps) => {
{ name: '-', value: '-' },
...invitationCodes.map((x) => ({
name: x.value,
value: x.id,
value: x.id.toString(),
})),
]}
/>
Expand Down
1 change: 1 addition & 0 deletions src/FE/components/Admin/Users/UserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const UserModal = (props: IProps) => {
{
name: 'enabled',
label: t('Is it enabled'),
defaultValue: true,
render: (options: IFormFieldOption, field: FormFieldType) => (
<FormSwitch options={options} field={field} />
),
Expand Down
2 changes: 1 addition & 1 deletion src/FE/components/Chat/PromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const PromptList = ({
return (
<ul
ref={promptListRef}
className="z-10 max-h-52 w-full overflow-y-auto rounded border border-black/10 shadow-[0_0_10px_rgba(0,0,0,0.10)] dark:border-neutral-500 dark:text-white dark:shadow-[0_0_15px_rgba(0,0,0,0.10)]"
className="z-10 max-h-52 w-full overflow-y-auto bg-background rounded-md border border-black/10 shadow-[0_0_10px_rgba(0,0,0,0.10)] dark:border-neutral-500 dark:text-white dark:shadow-[0_0_15px_rgba(0,0,0,0.10)]"
>
{prompts.map((prompt, index) => (
<li
Expand Down
2 changes: 1 addition & 1 deletion src/FE/components/Chatbar/ChatbarSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ export const ChatBarSettings = () => {
setSettingSheetOpen(true);
}}
/>
<Separator className="my-2" />
<SidebarButton
text={t('Change Password')}
icon={<IconPasswordUser />}
onClick={() => {
setChangePwdModalOpen(true);
}}
/>
<Separator className="my-2" />
<SidebarButton
text={t('Log out')}
icon={<IconLogout />}
Expand Down
32 changes: 10 additions & 22 deletions src/FE/components/Login/PhoneRegisterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import useTranslation from '@/hooks/useTranslation';
import { PhoneRegExp, SmsExpirationSeconds } from '@/utils/common';
import { saveUserInfo, setUserSession } from '@/utils/user';

import ContactModal from '@/components/Modal/ContactModal';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import {
Expand All @@ -24,21 +23,20 @@ import { Input } from '@/components/ui/input';
import { registerByPhone, sendRegisterSmsCode } from '@/apis/clientApis';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { redirectToGithub } from '@/utils/website';

const PhoneRegisterCard = (props: {
loginLoading: boolean;
openLoading: Function;
closeLoading: Function;
showContact: boolean;
}) => {
const { loginLoading, openLoading, closeLoading, showContact } = props;
const { loginLoading, openLoading, closeLoading } = props;
const { t } = useTranslation();
const router = useRouter();
const [seconds, setSeconds] = useState(SmsExpirationSeconds - 1);
const [isSendCode, setIsSendCode] = useState(false);
const [smsCode, setSmsCode] = useState('');
const [sending, setSending] = useState(false);
const [isContactModalOpen, setIsContactModal] = useState<boolean>(false);

const formSchema = z.object({
invitationCode: z
Expand Down Expand Up @@ -139,18 +137,14 @@ const PhoneRegisterCard = (props: {
className="w-full m-0 border-none outline-none bg-transparent rounded-md"
{...field}
/>
{showContact && (
<Button
type="button"
className="absolute right-10 text-center px-0"
variant="link"
onClick={() => {
setIsContactModal(true);
}}
>
{t('No Invitation Code?')}
</Button>
)}
<Button
type="button"
className="absolute right-10 text-center px-0"
variant="link"
onClick={redirectToGithub}
>
{t('No Invitation Code?')}
</Button>
</div>
</div>
</FormControl>
Expand Down Expand Up @@ -222,12 +216,6 @@ const PhoneRegisterCard = (props: {
</Button>
</div>
</CardContent>
<ContactModal
isOpen={isContactModalOpen}
onClose={() => {
setIsContactModal(false);
}}
/>
</Card>
);
};
Expand Down
52 changes: 0 additions & 52 deletions src/FE/components/Modal/ContactModal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/FE/components/Sidebar/SidebarButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SidebarButton: FC<Props> = ({
}) => {
return (
<div
className="flex w-full justify-between select-none items-center gap-2 hover:bg-muted rounded-md py-3 px-3 pl-[10px] text-[14px] leading-2 text-white transition-colors duration-200"
className="flex w-full justify-between cursor-pointer select-none items-center gap-2 hover:bg-muted rounded-md py-3 px-3 pl-[10px] text-[14px] leading-2 text-white transition-colors duration-200"
onClick={onClick}
>
<div className="flex text-black dark:text-white w-[80%] items-center">
Expand Down
Loading

0 comments on commit 1534103

Please sign in to comment.