Skip to content

Commit

Permalink
#55 Adding feature toggles and place holders for the Documents tab
Browse files Browse the repository at this point in the history
  • Loading branch information
santthosh committed May 6, 2024
1 parent 768d32b commit 61f6e89
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Model" ADD COLUMN "features" JSONB;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ model Model {
providerId String
provider ModelProvider @relation(fields: [providerId], references: [id])
Assistant Assistant[]
features Json?
}

model Organization {
Expand Down
92 changes: 81 additions & 11 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClient } from '@prisma/client';
import { PrismaClient, Prisma } from '@prisma/client';

const prisma = new PrismaClient();
async function main() {
Expand Down Expand Up @@ -29,124 +29,194 @@ async function main() {

const gpt35turbo = await prisma.model.upsert({
where: { id: 'gpt-3.5-turbo' },
update: {},
update: {
features: {
retrieval: true,
} as Prisma.JsonObject
},
create: {
id: 'gpt-3.5-turbo',
name: 'GPT-3.5 Turbo',
description: 'Currently points to gpt-3.5-turbo-0125',
url: 'https://platform.openai.com/docs/models/gpt-3-5-turbo',
providerId: 'openai',
features: {
retrieval: true,
} as Prisma.JsonObject
},
});
const gpt35turbo0125 = await prisma.model.upsert({
where: { id: 'gpt-3.5-turbo-0125' },
update: {},
update: {
features: {
retrieval: true,
} as Prisma.JsonObject
},
create: {
id: 'gpt-3.5-turbo-0125',
name: 'GPT-3.5 Turbo 0125',
description:
'Updated The latest GPT-3.5 Turbo model with higher accuracy at responding in requested formats.',
url: 'https://platform.openai.com/docs/models/gpt-3-5-turbo',
providerId: 'openai',
features: {
retrieval: true,
} as Prisma.JsonObject
},
});
const gpt35turbo16k = await prisma.model.upsert({
where: { id: 'gpt-3.5-turbo-16k' },
update: {},
update: {
features: {
retrieval: true,
} as Prisma.JsonObject
},
create: {
id: 'gpt-3.5-turbo-16k',
name: 'GPT-3.5 Turbo 16K',
description: '[Legacy] Currently points to gpt-3.5-turbo-16k-0613',
url: 'https://platform.openai.com/docs/models/gpt-3-5-turbo',
providerId: 'openai',
features: {
retrieval: true,
} as Prisma.JsonObject
},
});
const gpt4 = await prisma.model.upsert({
where: { id: 'gpt-4' },
update: {},
update: {
features: {
retrieval: true,
} as Prisma.JsonObject
},
create: {
id: 'gpt-4',
name: 'GPT-4',
description:
'Currently points to gpt-4-0613. See continuous model upgrades.Snapshot of gpt-4 from June 13th 2023 with improved function calling support.',
url: 'https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4',
providerId: 'openai',
features: {
retrieval: true,
} as Prisma.JsonObject
},
});
const gpt4turbo = await prisma.model.upsert({
where: { id: 'gpt-4-turbo' },
update: {},
update: {
features: {
retrieval: true,
} as Prisma.JsonObject
},
create: {
id: 'gpt-4-turbo',
name: 'GPT-4 Turbo',
description:
'GPT-4 Turbo with Vision. The latest GPT-4 Turbo model with vision capabilities. Vision requests can now use JSON mode and function calling. Currently points to gpt-4-turbo-2024-04-09',
url: 'https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4',
providerId: 'openai',
features: {
retrieval: true,
} as Prisma.JsonObject
},
});

const geminipro = await prisma.model.upsert({
where: { id: 'gemini-1.5-pro-latest' },
update: {},
update: {
features: {
retrieval: false,
} as Prisma.JsonObject
},
create: {
id: 'gemini-1.5-pro-latest',
name: 'Gemini Pro 1.5',
description: 'The latest model from Google',
url: 'https://ai.google.dev/gemini-api/docs/api-overview',
providerId: 'google',
features: {
retrieval: false,
} as Prisma.JsonObject
},
});

const groq_llama3_8b = await prisma.model.upsert({
where: { id: 'llama3-8b-8192' },
update: {},
update: {
features: {
retrieval: false,
} as Prisma.JsonObject
},
create: {
id: 'llama3-8b-8192',
name: 'LLaMA3 8b',
description:
'The Llama 3 instruction tuned models are optimized for dialogue use cases and outperform many of the available open source chat models on common industry benchmarks.',
url: 'https://console.groq.com/docs/models#llama3-8b',
providerId: 'groq',
features: {
retrieval: false,
} as Prisma.JsonObject
},
});

const groq_llama3_70b = await prisma.model.upsert({
where: { id: 'llama3-70b-8192' },
update: {},
update: {
features: {
retrieval: false,
} as Prisma.JsonObject
},
create: {
id: 'llama3-70b-8192',
name: 'LLaMA3 70b',
description:
'The Llama 3 instruction tuned models are optimized for dialogue use cases and outperform many of the available open source chat models on common industry benchmarks. ',
url: 'https://console.groq.com/docs/models#llama3-70b',
providerId: 'groq',
features: {
retrieval: false,
} as Prisma.JsonObject
},
});

const groq_mixtral_7b = await prisma.model.upsert({
where: { id: 'mixtral-8x7b-32768' },
update: {},
update: {
features: {
retrieval: false,
} as Prisma.JsonObject
},
create: {
id: 'mixtral-8x7b-32768',
name: 'Mistral 8x7b',
description:
'The Mixtral-8x7B Large Language Model (LLM) is a pretrained generative Sparse Mixture of Experts. The Mixtral-8x7B outperforms Llama 2 70B on most benchmarks we tested.',
url: 'https://console.groq.com/docs/models#mixtral-8x7b',
providerId: 'groq',
features: {
retrieval: false,
} as Prisma.JsonObject
},
});

const groq_gemma_7b = await prisma.model.upsert({
where: { id: 'gemma-7b-it' },
update: {},
update: {
features: {
retrieval: false,
} as Prisma.JsonObject
},
create: {
id: 'gemma-7b-it',
name: 'Google Gemma 7B',
description:
'Gemma models are well-suited for a variety of text generation tasks, including question answering, summarization, and reasoning.',
url: 'https://console.groq.com/docs/models#gemma-7b',
providerId: 'groq',
features: {
retrieval: false,
} as Prisma.JsonObject
},
});
}
Expand Down
31 changes: 31 additions & 0 deletions src/app/api/models/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import OpenAI from 'openai';
import { PrismaClient } from '@prisma/client';
import { getToken } from 'next-auth/jwt';
import { NextRequest, NextResponse } from 'next/server';

const prisma = new PrismaClient();

const getId = (req: Request) => {
const url = new URL(req.url);
return url.pathname.split('/').splice(-1, 1)[0];
};

// Note: We should not cache the models list as it may change frequently for different organizations
export async function GET(req: NextRequest, res: NextResponse) {
const token = await getToken({ req });
if (token) {
let id = getId(req);
let model = await prisma.model.findFirst({
where: {
id: id,
},
include: {
provider: true,
},
});
return Response.json(model, { status: 200 });
} else {
// Not Signed in
return Response.json({ message: 'Unauthenticated' }, { status: 401 });
}
}
7 changes: 7 additions & 0 deletions src/app/assistants/[id]/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Avatar, Badge, Card, Sidebar } from 'flowbite-react';
import {
HiColorSwatch,
HiChatAlt2,
HiFolder,
HiCog,
HiChartBar,
HiPuzzle,
Expand Down Expand Up @@ -75,6 +76,12 @@ export default function SideNavigation() {
>
Conversations
</Sidebar.Item>
<Sidebar.Item
href={getAssistantComponentUrl(assistant, 'documents')}
icon={HiFolder}
>
Documents
</Sidebar.Item>
<Sidebar.Item
href={getAssistantComponentUrl(assistant, 'customize')}
icon={HiColorSwatch}
Expand Down
21 changes: 21 additions & 0 deletions src/app/assistants/[id]/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ export function useGetAssistant(id: string) {
);
}

export async function getModel(modelId: string) {
if (!modelId) {
return [400, { error: 'Model Id is required' }];
}

let response = await fetch(
'/api/models/' + modelId,
{
method: 'GET',
headers: {
accept: 'application.json',
'Content-Type': 'application/json',
},
}
);

console.log(response)

return [response.status, await response.json()];
}

export async function updateAssistant(assistant: Assistant) {
let response = await fetch('/api/assistants/' + assistant.id, {
method: 'PATCH',
Expand Down
51 changes: 51 additions & 0 deletions src/app/assistants/[id]/documents/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use client';

import React, { useContext, useEffect, useState } from 'react';
import AssistantContext from '@/app/assistants/[id]/AssistantContext';
import { getModel } from '@/app/assistants/[id]/client';
import { Spinner } from 'flowbite-react';
import { Model } from '@/app/types/model';
import { HiOutlineFolder } from "react-icons/hi";

export default function Documents() {
const { assistant } = useContext(AssistantContext);
const [loading, setLoading] = useState(true);
const [model, setModel] = useState<Model | null>(null);

useEffect(() => {
if (assistant.modelId) {
getModel(assistant.modelId).then(([status,response]) => {
console.log(response);
setModel(response);
setLoading(false);
});
}
}, []);

return (
<div className='stack items-center justify-center'>
<h3 className='pb-4 text-3xl font-bold dark:text-white'>Documents</h3>
{
loading ? (
<div className="bg-grey flex h-[calc(100vh-120px)] items-center justify-center ">
<Spinner />
</div>
) : (
<div>
{ model?.features?.retrieval ? (
<div>
This model supports document retrieval, we are working on it
</div>
) : (
<div className='bg-grey flex flex-col h-[calc(100vh-120px)] items-center justify-center'>
<HiOutlineFolder className='text-9xl text-gray-400 dark:text-gray-700' />
<p className='text-gray-400 dark:text-gray-400'>Support for documents is not available for <b>{model? model.id : 'this model'}</b> yet.</p>
</div>
)
}
</div>
)
}
</div>
);
}
3 changes: 3 additions & 0 deletions src/app/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ export interface Model {
description: string;
url: string;
provider: ModelProvider;
features?: {
retrieval: boolean;
}
}

0 comments on commit 61f6e89

Please sign in to comment.