Skip to content

Commit

Permalink
feat: provide username param in buy link (#132) and fix anthropic m…
Browse files Browse the repository at this point in the history
…essage format error
  • Loading branch information
zmh-program committed Mar 16, 2024
1 parent 642fc46 commit f0b4629
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
22 changes: 22 additions & 0 deletions adapter/claude/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,29 @@ func (c *ChatInstance) GetTokens(props *adaptercommon.ChatProps) int {
}

func (c *ChatInstance) GetMessages(props *adaptercommon.ChatProps) []Message {
start := false

return utils.Each(props.Message, func(message globals.Message) Message {
// anthropic api: top message must be user message, system message is not allowed
if !start {
start = true
// set first message to user message
if message.Role != globals.User {
return Message{
Role: globals.User,
Content: message.Content,
}
}
}

if message.Role == globals.System {
// set system message to user message
return Message{
Role: message.Role,
Content: message.Content,
}
}

if !globals.IsVisionModel(props.Model) || message.Role != globals.User {
return Message{
Role: message.Role,
Expand Down
10 changes: 8 additions & 2 deletions app/src/dialogs/QuotaDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { AlertDialogTitle } from "@radix-ui/react-alert-dialog";
import { buyQuota } from "@/api/addition.ts";
import { useToast } from "@/components/ui/use-toast.ts";
import { useEffectAsync } from "@/utils/hook.ts";
import { selectAuthenticated } from "@/store/auth.ts";
import { selectAuthenticated, selectUsername } from "@/store/auth.ts";
import { ToastAction } from "@/components/ui/toast.tsx";
import {
buyLink,
Expand Down Expand Up @@ -88,6 +88,7 @@ function QuotaDialog() {
const [amount, setAmount] = useState(10);
const open = useSelector(dialogSelector);
const auth = useSelector(selectAuthenticated);
const username = useSelector(selectUsername);

const sub = useSelector(subDialogSelector);
const subscriptionData = useSelector(subscriptionDataSelector);
Expand Down Expand Up @@ -241,8 +242,13 @@ function QuotaDialog() {
<AlertDialogAction
onClick={async () => {
if (!useDeeptrain) {
if (buyLink.trim().length === 0)
return toast({
title: t("buy.not-config-link"),
});

openWindow(
`${buyLink}?quota=${amount}`,
`${buyLink}?quota=${amount}&username=${username}`,
"_blank",
);
return;
Expand Down
1 change: 1 addition & 0 deletions app/src/resources/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
},
"quota-description": "消息的点数支出",
"buy": {
"not-config-link": "后台未配置购买链接",
"choose": "选择一个金额",
"other": "其他",
"other-desc": "多少点数?",
Expand Down
3 changes: 2 additions & 1 deletion app/src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"exchange-failed": "Failed",
"exchange-failed-prompt": "Redemption failed for {{reason}}",
"buy-link": "Go to the deal",
"deeptrain-tip": "Tip: Once Deeptrain has reloaded to your wallet, come back here and click to buy the appropriate credits"
"deeptrain-tip": "Tip: Once Deeptrain has reloaded to your wallet, come back here and click to buy the appropriate credits",
"not-config-link": "Purchase link is not configured in the background"
},
"pkg": {
"title": "Packages",
Expand Down
3 changes: 2 additions & 1 deletion app/src/resources/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"exchange-failed": "引き換えに失敗しました",
"exchange-failed-prompt": "{{reason}}のため、引き換えに失敗しました",
"buy-link": "購入しに行く",
"deeptrain-tip": "ヒント: Deeptrainがウォレットにリロードされたら、ここに戻ってクリックして適切なクレジットを購入してください"
"deeptrain-tip": "ヒント: Deeptrainがウォレットにリロードされたら、ここに戻ってクリックして適切なクレジットを購入してください",
"not-config-link": "購入リンクがバックグラウンドで設定されていません"
},
"pkg": {
"title": "パック",
Expand Down
3 changes: 2 additions & 1 deletion app/src/resources/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"exchange-failed": "Сбой обмена",
"exchange-failed-prompt": "Не удалось погасить по {{reason}}",
"buy-link": "Перейти к покупке",
"deeptrain-tip": "Совет: как только Deeptrain перезагрузится на ваш кошелек, вернитесь сюда и нажмите, чтобы купить соответствующие кредиты"
"deeptrain-tip": "Совет: как только Deeptrain перезагрузится на ваш кошелек, вернитесь сюда и нажмите, чтобы купить соответствующие кредиты",
"not-config-link": "Ссылка на покупку не настроена в фоновом режиме"
},
"pkg": {
"title": "Пакеты",
Expand Down

0 comments on commit f0b4629

Please sign in to comment.