diff --git a/app/src/api/v1.ts b/app/src/api/v1.ts index 17148c0..f603be0 100644 --- a/app/src/api/v1.ts +++ b/app/src/api/v1.ts @@ -2,6 +2,8 @@ import axios from "axios"; import { Model, Plan } from "@/api/types.tsx"; import { ChargeProps, nonBilling } from "@/admin/charge.ts"; import { getErrorMessage } from "@/utils/base.ts"; +import { getModelName } from "@/routes/admin/Market.tsx"; +import { modelImages } from "@/admin/market.ts"; type v1Options = { endpoint?: string; @@ -88,8 +90,38 @@ export async function getApiMarket(options?: v1Options): Promise { } } +export async function getFilledApiMarket( + secret?: string, + options?: v1Options, +): Promise { + const data = await getApiMarket(options); + if (data.length > 0) return data; + + const resp = await getApiModels(secret, options); + if (!resp.status) return []; + + return resp.data.map((id) => ({ + id, + default: true, + name: getModelName(id), + tag: [], + avatar: modelImages[0], + description: id, + free: false, + auth: true, + high_context: false, + price: { + type: nonBilling, + anonymous: false, + models: [id], + input: 0, + output: 0, + }, + })); +} + export async function bindMarket(options?: v1Options): Promise { - const market = await getApiMarket(options); + const market = await getFilledApiMarket(undefined, options); const charge = await getApiCharge(options); market.forEach((item: Model) => { diff --git a/app/src/components/Markdown.tsx b/app/src/components/Markdown.tsx index ef5e918..ca7bce6 100644 --- a/app/src/components/Markdown.tsx +++ b/app/src/components/Markdown.tsx @@ -192,11 +192,11 @@ function MarkdownContent({ rehypePlugins={rehypePlugins} className={cn("markdown-body", className)} children={children} - skipHtml={!acceptHtml} + skipHtml={acceptHtml} components={{ p({ children }) { // if the format is `user quota is not enough error (model: gpt-3.5-turbo-1106, minimum quota: 0.01, your quota: -77.77)`, return special component - const match = children + const match = (children ?? "") .toString() .match( /user quota is not enough error \(model: (.*), minimum quota: (.*), your quota: (.*)\)/, diff --git a/app/src/components/Message.tsx b/app/src/components/Message.tsx index 33c208d..ed211be 100644 --- a/app/src/components/Message.tsx +++ b/app/src/components/Message.tsx @@ -271,7 +271,7 @@ function MessageContent({
{message.content.length ? ( - + ) : message.end === true ? ( ) : ( diff --git a/app/src/routes/admin/Market.tsx b/app/src/routes/admin/Market.tsx index 51a6907..500fadd 100644 --- a/app/src/routes/admin/Market.tsx +++ b/app/src/routes/admin/Market.tsx @@ -855,7 +855,7 @@ function MarketAlert({ ); } -function getModelName(id: string): string { +export function getModelName(id: string): string { // replace all `-` to ` ` except first `-` keep it let begin = true;