Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Nextjs Examples #15

Merged
merged 2 commits into from
Jul 1, 2024
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
2 changes: 1 addition & 1 deletion examples/nextjs/server-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@upstash/rag-chat": "../../",
"@upstash/rag-chat": "^1.0.1",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18"
Expand Down
18 changes: 9 additions & 9 deletions examples/nextjs/server-actions/src/app/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use server";

import { UpstashMessage } from "@upstash/rag-chat";
import { createServerActionStream } from "@upstash/rag-chat/rsc";
import type { UpstashMessage } from "@upstash/rag-chat";
import { createServerActionStream } from "@upstash/rag-chat/nextjs";
import { ragChat } from "./rag-chat";

export const server_chat = async ({ userMessage }: { userMessage: UpstashMessage }) => {
export const serverChat = async ({ userMessage }: { userMessage: UpstashMessage }) => {
const { output } = await ragChat.chat(userMessage.content, { streaming: true });

// 👇 adapter to convert standard readable stream into rsc-compatible stream
Expand All @@ -13,26 +13,26 @@ export const server_chat = async ({ userMessage }: { userMessage: UpstashMessage
return stream;
};

export const server_add_data = async () => {
export const serverAddData = async () => {
await Promise.all([
ragChat.context.add({
dataType: "text",
type: "text",
data: "Paris, the capital of France, is renowned for its iconic landmark, the Eiffel Tower, which was completed in 1889 and stands at 330 meters tall.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "The city is home to numerous world-class museums, including the Louvre Museum, housing famous works such as the Mona Lisa and Venus de Milo.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "Paris is often called the City of Light due to its significant role during the Age of Enlightenment and its early adoption of street lighting.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "The Seine River gracefully flows through Paris, dividing the city into the Left Bank and the Right Bank, each offering its own distinct atmosphere.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "Paris boasts a rich culinary scene, with a plethora of bistros, cafés, and Michelin-starred restaurants serving exquisite French cuisine.",
}),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { UpstashMessage } from "@upstash/rag-chat";
import { readServerActionStream } from "@upstash/rag-chat/rsc";
import type { UpstashMessage } from "@upstash/rag-chat";
import { readServerActionStream } from "@upstash/rag-chat/nextjs";
import { useState } from "react";
import { server_add_data, server_chat } from "../actions";
import { serverAddData, serverChat } from "../actions";

export const Chat = ({ initialMessages }: { initialMessages?: UpstashMessage[] }) => {
const [messages, setMessages] = useState<UpstashMessage[]>(initialMessages ?? []);
Expand All @@ -20,7 +20,7 @@ export const Chat = ({ initialMessages }: { initialMessages?: UpstashMessage[] }
setIsLoading(true);

try {
const stream = await server_chat({ userMessage });
const stream = await serverChat({ userMessage });
let aiMessage: UpstashMessage = {
content: "",
role: "assistant",
Expand All @@ -46,7 +46,7 @@ export const Chat = ({ initialMessages }: { initialMessages?: UpstashMessage[] }
const handleAddData = async () => {
setIsLoading(true);
try {
await server_add_data();
await serverAddData();
} catch (error) {
console.error("Error adding data:", error);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/server-actions/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chat } from "./components/Chat";
import { Chat } from "./components/chat";
import { ragChat } from "./rag-chat";

export default async function Page() {
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/vercel-ai-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@upstash/rag-chat": "0.0.5-1.alpha",
"@upstash/rag-chat": "^1.0.1",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18"
Expand Down
10 changes: 5 additions & 5 deletions examples/nextjs/vercel-ai-sdk/src/app/api/add-data/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ export async function POST() {
const ragChat = new RAGChat({});
await Promise.all([
ragChat.context.add({
dataType: "text",
type: "text",
data: "Paris, the capital of France, is renowned for its iconic landmark, the Eiffel Tower, which was completed in 1889 and stands at 330 meters tall.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "The city is home to numerous world-class museums, including the Louvre Museum, housing famous works such as the Mona Lisa and Venus de Milo.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "Paris is often called the City of Light due to its significant role during the Age of Enlightenment and its early adoption of street lighting.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "The Seine River gracefully flows through Paris, dividing the city into the Left Bank and the Right Bank, each offering its own distinct atmosphere.",
}),
ragChat.context.add({
dataType: "text",
type: "text",
data: "Paris boasts a rich culinary scene, with a plethora of bistros, cafés, and Michelin-starred restaurants serving exquisite French cuisine.",
}),
]);
Expand Down