Skip to content

Commit

Permalink
chore: remove console logs #283
Browse files Browse the repository at this point in the history
  • Loading branch information
srizvi committed Apr 28, 2024
1 parent 637de7f commit 0d79d4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
20 changes: 6 additions & 14 deletions apps/mai-sc/src/lib/chat/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { z } from 'zod';
import { SpinnerIcon } from '@yocxo/ui/icons';

import { saveChat } from '#/app/actions';
import { env } from '#/env';
import {
formatNumber,
nanoid,
Expand All @@ -41,7 +40,7 @@ import { Stocks } from '#/ui/stocks/stocks';
import { StocksSkeleton } from '#/ui/stocks/stocks-skeleton';

const openai = new OpenAI({
apiKey: env.OPENAI_API_KEY ?? '',
apiKey: process.env.OPENAI_API_KEY ?? '',
});

async function confirmPurchase(symbol: string, price: number, amount: number) {
Expand Down Expand Up @@ -172,9 +171,7 @@ Your goal is to inspire our creative team and help them generate engaging, JTBD-
You may discuss anything related to professional topics to help our agency and team members such as digital marketing, social media, content creation, customer engagement, product management, jobs-to-be-done, and more.
If the user requests an unsupported action, respond with: "I'm sorry, I'm unable to help with that. I have notified the Smarcomms Chat Police though. 😅"
`,
If the user requests an unsupported action, respond with: "I'm sorry, I'm unable to help with that. I have notified the Smarcomms Chat Police though. 😅"`,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...aiState.get().messages.map((message: any) => ({
Expand Down Expand Up @@ -401,7 +398,7 @@ If the user requests an unsupported action, respond with: "I'm sorry, I'm unable
);
},
},
showFacebookPostWithImage: {
showFacebookPost: {
description: 'Display a Facebook post with an image.',
parameters: z.object({
userName: z.string(),
Expand Down Expand Up @@ -448,7 +445,7 @@ If the user requests an unsupported action, respond with: "I'm sorry, I'm unable
{
id: nanoid(),
role: 'function',
name: 'showFacebookPostWithImage',
name: 'showFacebookPost',
content: JSON.stringify(facebookPost),
},
],
Expand Down Expand Up @@ -514,14 +511,11 @@ export const AI = createAI<AIState, UIState>({
},
unstable_onSetAIState: async ({ state }) => {
'use server';
console.log('unstable_onSetAIState called with state:', state);

const session = await auth();
console.log('Session fetched:', session);

if (session?.user) {
const { chatId, messages } = state;
console.log('Processing chat with ID:', chatId);

const createdAt = new Date();
const userId = session.user.id!;
Expand All @@ -537,11 +531,9 @@ export const AI = createAI<AIState, UIState>({
path,
};

console.log('Saving chat:', chat);
await saveChat(chat);
console.log('Chat saved successfully:', chatId);
} else {
console.log('No user session found, not saving chat.');
return;
}
},
});
Expand Down Expand Up @@ -577,7 +569,7 @@ export const getUIStateFromAIState = (aiState: Chat) => {
@typescript-eslint/no-unsafe-assignment */}
<Events props={JSON.parse(message.content)} />
</BotCard>
) : message.name === 'showFacebookPostWithImage' ? (
) : message.name === 'showFacebookPost' ? (
<BotCard>
{/* eslint-disable-next-line
@typescript-eslint/no-unsafe-assignment */}
Expand Down
12 changes: 5 additions & 7 deletions apps/mai-sc/src/ui/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ export function Chat({ id, className, session, missingKeys }: ChatProps) {

const [_, setNewChatId] = useLocalStorage('newChatId', id);

useEffect(() => {
console.log('Setting newChatId:', id);
setNewChatId(id);
console.log('newChatId set:', id);
}, [id, setNewChatId]);

useEffect(() => {
if (session?.user) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (path === '/chat' && messages.length === 1) {
window.history.replaceState({}, '', `/chat/${id}`);
window.history.replaceState({}, '/chat', `/chat/${id}`);
}
}
}, [id, path, session?.user, messages]);
Expand All @@ -59,6 +53,10 @@ export function Chat({ id, className, session, missingKeys }: ChatProps) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
}, [aiState.messages, router]);

useEffect(() => {
setNewChatId(id);
});

useEffect(() => {
missingKeys.map((key) => {
toast.error('Missing environment variable', {
Expand Down

0 comments on commit 0d79d4b

Please sign in to comment.