Skip to content

Commit

Permalink
Merge pull request #1191 from synapsy-ai/vNext
Browse files Browse the repository at this point in the history
Version 3.2.4
  • Loading branch information
lpeyr authored Nov 23, 2024
2 parents 5dfe6c2 + a8ab627 commit 5a8c5fc
Show file tree
Hide file tree
Showing 8 changed files with 838 additions and 2,337 deletions.
45 changes: 8 additions & 37 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import OpenAI from "openai";
import { OpenAIStream, StreamingTextResponse } from "ai";

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";

export async function POST(req: Request) {
const json = await req.json();
Expand All @@ -14,41 +10,16 @@ export async function POST(req: Request) {
top_p,
frequency_penalty,
presence_penalty,
previewToken,
} = json;

const res = await openai.chat.completions.create({
model: model,
const res = streamText({
model: openai(model),
messages: messages,
temperature: temperature,
top_p: top_p,
frequency_penalty: frequency_penalty,
presence_penalty: presence_penalty,
stream: true,
});

const stream = OpenAIStream(res, {
// This function is called when the API returns a response
async onCompletion(completion) {
const title = json.messages[0].content.substring(0, 100);
const id = json.id;
const createdAt = Date.now();
const path = `/chat/${id}`;
const payload = {
id,
title,
createdAt,
path,
messages: [
...messages,
{
content: completion,
role: "assistant",
},
],
};
},
topP: top_p,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
});

return new StreamingTextResponse(stream);
return res.toDataStreamResponse();
}
6 changes: 4 additions & 2 deletions components/theme-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use client";

import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
import { type ThemeProviderProps } from "next-themes/dist/types";
import {
ThemeProvider as NextThemesProvider,
type ThemeProviderProps,
} from "next-themes";

export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
Expand Down
2 changes: 1 addition & 1 deletion lib/ai-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function sendChatToGpt(
system: string,
provider: AiProviders,
): Promise<any> {
const chatCompletion = await streamText({
const chatCompletion = streamText({
// @ts-ignore
model: provider === "openAI" ? openai(model) : mistral(model),
system: system,
Expand Down
4 changes: 2 additions & 2 deletions lib/ai-completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function sendToGpt(
): Promise<any> {
functions.setLoading(true);
let loading = true;
const chatCompletion = await streamText({
const chatCompletion = streamText({
// @ts-ignore
model: provider === "openAI" ? openai(model) : mistral(model),
system: getSystem(template, lng, tone),
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function sendToGptCustom(
let result = content;
let c = "";
console.log(result);
const chatCompletion = await streamText({
const chatCompletion = streamText({
// @ts-ignore
model: provider === "openAI" ? openai(model) : mistral(model),
system: system,
Expand Down
2 changes: 1 addition & 1 deletion lib/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "3.2.3";
export const version = "3.2.4";
Loading

0 comments on commit 5a8c5fc

Please sign in to comment.