Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ import { streamText, convertToModelMessages, type UIMessage } from "ai";
const doubao = createOpenAI({
baseURL: "https://ark.cn-beijing.volces.com/api/v3",
apiKey: process.env.DOUBAO_API_KEY || "",
fetch: async (url, options) => {
// 拦截请求,将 developer 角色转换为 system 角色
// 这个 sdk 会自动把 system 等角色转换成 developer...
if (options?.body) {
const body = JSON.parse(options.body as string);
if (body.messages) {
body.messages = body.messages.map((msg: any) => ({
...msg,
role: msg.role === "developer" ? "system" : msg.role,
}));
}
options.body = JSON.stringify(body);
}
return fetch(url, options);
},
}).chat;

export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();

const result = streamText({
model: doubao("doubao-seed-1-6-flash-250828"),
system: "你是源语奇思(AtomInfinite)开发的人工智能助手 WisModel。",
messages: convertToModelMessages(messages),
});

Expand Down
5 changes: 5 additions & 0 deletions app/assistant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const Assistant = () => {
<div className="flex-1 overflow-hidden">
<Thread />
</div>
<div className="flex w-full justify-center">
<a href="https://beian.miit.gov.cn/" target="_blank">
沪ICP备2025110110号-2
</a>
</div>
</SidebarInset>
</div>
</SidebarProvider>
Expand Down
2 changes: 1 addition & 1 deletion components/assistant-ui/thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const ThreadSuggestions: FC = () => {

const Composer: FC = () => {
return (
<div className="aui-composer-wrapper sticky bottom-0 mx-auto flex w-full max-w-[var(--thread-max-width)] flex-col gap-4 overflow-visible rounded-t-3xl bg-background pb-4 md:pb-6">
<div className="aui-composer-wrapper sticky bottom-0 mx-auto flex w-full max-w-[var(--thread-max-width)] flex-col gap-4 overflow-visible rounded-t-3xl bg-background md:pb-2">
<ThreadScrollToBottom />
<ComposerPrimitive.Root className="aui-composer-root relative flex w-full flex-col">
<ComposerPrimitive.AttachmentDropzone className="aui-composer-attachment-dropzone group/input-group flex w-full flex-col rounded-3xl border border-input bg-background px-1 pt-2 shadow-xs transition-[color,box-shadow] outline-none has-[textarea:focus-visible]:border-ring has-[textarea:focus-visible]:ring-[3px] has-[textarea:focus-visible]:ring-ring/50 data-[dragging=true]:border-dashed data-[dragging=true]:border-ring data-[dragging=true]:bg-accent/50 dark:bg-background">
Expand Down
3 changes: 1 addition & 2 deletions components/assistant-ui/threadlist-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as React from "react";
import { Github, MessagesSquare } from "lucide-react";
import { MessagesSquare } from "lucide-react";
import Link from "next/link";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
Expand Down