Skip to content

Commit

Permalink
fix (chat): Force dynamic for vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Dec 26, 2024
1 parent 3c77d67 commit 032d54b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
15 changes: 9 additions & 6 deletions www/app/actions/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createClient } from '@/utils/supabase/server';
import { honcho, getHonchoApp, getHonchoUser } from '@/utils/honcho';
import * as Sentry from "@sentry/nextjs";
import * as Sentry from '@sentry/nextjs';

// TODO add proper authorization check

Expand All @@ -12,9 +12,9 @@ type Conversation = {
};

export async function getConversations() {
return Sentry.startSpan({ name: 'server-action.getConversations', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.getConversations', op: 'server.action' },
async () => {

const supabase = createClient();

const {
Expand Down Expand Up @@ -47,7 +47,8 @@ export async function getConversations() {
}

export async function createConversation() {
return Sentry.startSpan({ name: 'server-action.createConversation', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.createConversation', op: 'server.action' },
async () => {
const supabase = createClient();

Expand All @@ -74,7 +75,8 @@ export async function createConversation() {
}

export async function deleteConversation(conversationId: string) {
return Sentry.startSpan({ name: 'server-action.deleteConversation', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.deleteConversation', op: 'server.action' },
async () => {
const supabase = createClient();

Expand All @@ -101,7 +103,8 @@ export async function deleteConversation(conversationId: string) {
}

export async function updateConversation(conversationId: string, name: string) {
return Sentry.startSpan({ name: 'server-action.updateConversation', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.updateConversation', op: 'server.action' },
async () => {
const supabase = createClient();

Expand Down
11 changes: 7 additions & 4 deletions www/app/actions/messages.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use server';
import { createClient } from '@/utils/supabase/server';
import { honcho, getHonchoApp, getHonchoUser } from '@/utils/honcho';
import * as Sentry from "@sentry/nextjs";
import * as Sentry from '@sentry/nextjs';

export async function getMessages(conversationId: string) {
return Sentry.startSpan({ name: 'server-action.getMessages', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.getMessages', op: 'server.action' },
async () => {
const supabase = createClient();

Expand Down Expand Up @@ -39,7 +40,8 @@ export async function getMessages(conversationId: string) {
}

export async function getThought(conversationId: string, messageId: string) {
return Sentry.startSpan({ name: 'server-action.getThought', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.getThought', op: 'server.action' },
async () => {
const supabase = createClient();

Expand Down Expand Up @@ -81,7 +83,8 @@ export async function addOrRemoveReaction(
messageId: string,
reaction: 'thumbs_up' | 'thumbs_down' | null
) {
return Sentry.startSpan({ name: 'server-action.addOrRemoveReaction', op: 'server.action' },
return Sentry.startSpan(
{ name: 'server-action.addOrRemoveReaction', op: 'server.action' },
async () => {
const supabase = createClient();

Expand Down
4 changes: 4 additions & 0 deletions www/app/api/chat/honcho/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { getUserData } from '@/utils/ai';
import { honcho } from '@/utils/honcho';
import { NextRequest, NextResponse } from 'next/server';

export const runtime = 'nodejs';
export const maxDuration = 100;
export const dynamic = 'force-dynamic'; // always run dynamically

export async function POST(req: NextRequest) {
const { message, conversationId } = await req.json();

Expand Down
4 changes: 4 additions & 0 deletions www/app/api/chat/response/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { honcho } from '@/utils/honcho';
import { responsePrompt } from '@/utils/prompts/response';
import { NextRequest, NextResponse } from 'next/server';

export const runtime = 'nodejs';
export const maxDuration = 100;
export const dynamic = 'force-dynamic'; // always run dynamically

export async function POST(req: NextRequest) {
const { message, conversationId, honchoThought } = await req.json();

Expand Down
4 changes: 4 additions & 0 deletions www/app/api/chat/thought/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { honcho } from '@/utils/honcho';
import { thoughtPrompt } from '@/utils/prompts/thought';
import { NextRequest, NextResponse } from 'next/server';

export const runtime = 'nodejs';
export const maxDuration = 100;
export const dynamic = 'force-dynamic'; // always run dynamically

const CONTEXT_LIMIT = 10;

interface Metadata {
Expand Down
7 changes: 3 additions & 4 deletions www/utils/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export async function createStream(
payload: HistoryWithoutResponse
) {
try {

const result = streamText({
model: openrouter(MODEL),
messages,
Expand All @@ -190,9 +189,9 @@ export async function createStream(
userId: payload.userId,
release: SENTRY_RELEASE,
environment: SENTRY_ENVIRONMENT,
tags: [type]
}
}
tags: [type],
},
},
});
return result.toTextStreamResponse();
} catch (error) {
Expand Down

0 comments on commit 032d54b

Please sign in to comment.