Skip to content

Commit

Permalink
Merge pull request #100 from assistants-hub/93_store
Browse files Browse the repository at this point in the history
#93 - Organizations must be created on user login if it is missing
  • Loading branch information
santthosh authored Jun 28, 2024
2 parents be692e1 + 354cda8 commit ef4416a
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The gemini-1.5-pro-latest model is a large-scale language model developed by Goo
All models that support [Anthropic API](https://docs.anthropic.com/en/docs/models-overview) are supported by [Assistants Hub](https://assistantshub.ai).

| Model Name | Provider | Streaming <br/>Responses | Documents | Functions |
|-------------------| --------- | ------------------------ | ------------------------ | ------------------------ |
| ----------------- | --------- | ------------------------ | ------------------------ | ------------------------ |
| Claude 3 Opus | Anthropic | :white_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
| Claude 3.5 Sonnet | Anthropic | :white_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
| Claude 3 Sonnet | Anthropic | :white_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
Expand Down
1 change: 0 additions & 1 deletion src/app/api/assistants/[id]/files/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ulid } from 'ulidx';
import OpenAI from 'openai';
import fs from 'fs';
import os from 'os';
import path from 'path';
Expand Down
29 changes: 27 additions & 2 deletions src/app/api/auth/[auth0]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';
import { redirect } from 'next/navigation';
import {
getSession,
handleAuth,
handleLogin,
handleProfile,
} from '@auth0/nextjs-auth0';
import prisma from '@/app/api/utils/prisma';

export const GET = handleAuth({
login: handleLogin((req) => {
Expand All @@ -18,4 +23,24 @@ export const GET = handleAuth({
returnTo: returnUrl,
};
}),
// @ts-ignore
profile: handleProfile(async (req) => {
// @ts-ignore
let session = await getSession(req);

// Create organization if not yet created for this user
const organization = await prisma.organization.upsert({
where: {
owner_ownerType: {
owner: session?.user.sub,
ownerType: 'personal',
},
},
update: {},
create: {
owner: session?.user.sub,
ownerType: 'personal',
},
});
}),
});
6 changes: 3 additions & 3 deletions src/app/api/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getOpenAI(assistant: any): OpenAI {
});
}

export async function getOpenAIWithKey(modelProviderKeyId:string) {
export async function getOpenAIWithKey(modelProviderKeyId: string) {
let openAIAPIKey = process.env.OPENAI_API_KEY
? process.env.OPENAI_API_KEY
: null;
Expand All @@ -36,9 +36,9 @@ export async function getOpenAIWithKey(modelProviderKeyId:string) {
},
});

if(modelProviderKey && modelProviderKey.key) {
if (modelProviderKey && modelProviderKey.key) {
// @ts-ignore
openAIAPIKey = modelProviderKey.key['apiKey']
openAIAPIKey = modelProviderKey.key['apiKey'];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/assistants/[id]/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function SideNavigation() {
<Button
size={'sm'}
gradientDuoTone='greenToBlue'
className={'float-right mt-3 mr-2 w-[150px]'}
className={'float-right mr-2 mt-3 w-[150px]'}
>
<HiChatAlt2 className={'h-5 w-5'} />
Try Assistant
Expand Down
53 changes: 31 additions & 22 deletions src/app/assistants/[id]/chat/ChatConversationStarters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@ import AssistantContext from '@/app/assistants/[id]/AssistantContext';
import { Button } from 'flowbite-react';

export interface ChatConversationStartersProps {
onClick?: (text:string)=> void
onClick?: (text: string) => void;
}

export default function ChatConversationStarters(props: ChatConversationStartersProps) {
export default function ChatConversationStarters(
props: ChatConversationStartersProps
) {
const { assistant } = useContext(AssistantContext);

return (
<div className={'grid grid-flow-row-dense xs:grid-cols-1 sm:grid-cols-2 gap-4 pt-5 items-center justify-center'}>
{
assistant && assistant.theme && assistant.theme.conversationStarters ?
assistant.theme.conversationStarters.map(
(conversationStarter) => {
return (
<Button color="light"
size={'md'}
key={conversationStarter.id}
className={'p-2 bg-gray-100 text-gray-500'}
onClick={(e) => {
props.onClick ? props.onClick(conversationStarter.prompt) : undefined
e.stopPropagation();
}}>
{conversationStarter.prompt}
</Button>
);
}
) :<></>
<div
className={
'grid grid-flow-row-dense items-center justify-center gap-4 pt-5 xs:grid-cols-1 sm:grid-cols-2'
}
>
{assistant && assistant.theme && assistant.theme.conversationStarters ? (
assistant.theme.conversationStarters.map((conversationStarter) => {
return (
<Button
color='light'
size={'md'}
key={conversationStarter.id}
className={'bg-gray-100 p-2 text-gray-500'}
onClick={(e) => {
props.onClick
? props.onClick(conversationStarter.prompt)
: undefined;
e.stopPropagation();
}}
>
{conversationStarter.prompt}
</Button>
);
})
) : (
<></>
)}
</div>
);
}
}
7 changes: 5 additions & 2 deletions src/app/assistants/[id]/chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default function ChatHeader(props: ChatHeaderProps) {
>
<div className='grid grid-cols-5'>
<div className='col-span-4'>
<p className='flex justify-start ml-5 max-w-md text-xl leading-relaxed'>{assistant.name}</p>
<p className='ml-5 flex max-w-md justify-start text-xl leading-relaxed'>
{assistant.name}
</p>
</div>
<div className='col-span-1'>
{!props.minimize && props.setMinimize ? (
Expand All @@ -54,7 +56,8 @@ export default function ChatHeader(props: ChatHeaderProps) {
</div>
<div
className={
'flex justify-start ml-5 text-xs ' + `text-[${getSecondaryTextColor(assistant)}]`
'ml-5 flex justify-start text-xs ' +
`text-[${getSecondaryTextColor(assistant)}]`
}
>
{assistant.description}
Expand Down
8 changes: 4 additions & 4 deletions src/app/assistants/[id]/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function ChatPage(props: ChatPageProps) {
messages,
sendMessage,
createNewThread,
sendConversationStarter
sendConversationStarter,
} = useChatContext();

useEffect(() => {
Expand Down Expand Up @@ -67,9 +67,9 @@ export default function ChatPage(props: ChatPageProps) {
{messages.map((message: Message, index) => {
return <ChatMessage key={index} message={message} />;
})}
{
messages.length === 1 ? <ChatConversationStarters onClick={sendConversationStarter}/> : null
}
{messages.length === 1 ? (
<ChatConversationStarters onClick={sendConversationStarter} />
) : null}
{streamText ? (
<>
<ChatMessageStreaming
Expand Down
10 changes: 6 additions & 4 deletions src/app/assistants/[id]/chat/ChatPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function ChatPopup(props: ChatPopupProps) {
setMessages,
sendMessage,
createNewThread,
sendConversationStarter
sendConversationStarter,
} = useChatContext();

useEffect(() => {
Expand Down Expand Up @@ -80,9 +80,11 @@ export default function ChatPopup(props: ChatPopupProps) {
{messages.map((message: Message, index) => {
return <ChatMessage key={index} message={message} />;
})}
{
messages.length === 1 ? <ChatConversationStarters onClick={sendConversationStarter}/> : null
}
{messages.length === 1 ? (
<ChatConversationStarters
onClick={sendConversationStarter}
/>
) : null}
{streamText ? (
<>
<ChatMessageStreaming
Expand Down
4 changes: 2 additions & 2 deletions src/app/assistants/[id]/chat/useChatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const useChatContext = () => {
setMessageStatus('in_progress' as string);
};

const sendConversationStarter = async (prompt:string) => {
const sendConversationStarter = async (prompt: string) => {
let message: Message = {
created_at: Date.now() / 1000,
role: 'user',
Expand Down Expand Up @@ -234,6 +234,6 @@ export const useChatContext = () => {
setFingerprint,
sendMessage,
createNewThread,
sendConversationStarter
sendConversationStarter,
};
};
4 changes: 3 additions & 1 deletion src/app/assistants/[id]/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default function Settings() {
);

const [authenticationRequired, setAuthenticationRequired] = useState(
assistant.authenticatedUsersOnly !== undefined ? assistant.authenticatedUsersOnly : true
assistant.authenticatedUsersOnly !== undefined
? assistant.authenticatedUsersOnly
: true
);

const { push } = useRouter();
Expand Down

0 comments on commit ef4416a

Please sign in to comment.