Skip to content

Commit

Permalink
feat: 🎸 upgrade openai models
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpetrov committed Nov 7, 2023
1 parent 90dce7b commit afb0ac2
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 43 deletions.
14 changes: 9 additions & 5 deletions apps/dashboard/components/AgentInputs/ModelInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useSession } from 'next-auth/react';
import React, { useState } from 'react';
import { useFormContext } from 'react-hook-form';

import { ModelConfig } from '@chaindesk/lib/config';
import { CUSTOMER_SUPPORT } from '@chaindesk/lib/prompt-templates';
import { PromptTypesLabels, RouteNames } from '@chaindesk/lib/types';
import { CreateAgentSchema } from '@chaindesk/lib/types/dtos';
Expand Down Expand Up @@ -106,19 +107,22 @@ export default function ModelInput({}: Props) {
}}
>
<Option value={AgentModelName.gpt_3_5_turbo}>
OpenAI gpt-3.5-turbo
gpt-3.5-turbo - 16K -{' '}
{ModelConfig[AgentModelName.gpt_3_5_turbo].cost} credit/query
</Option>
<Option
value={AgentModelName.gpt_3_5_turbo_16k}
value={AgentModelName.gpt_4}
disabled={!session?.data?.organization?.isPremium}
>
OpenAI gpt-3.5-turbo 16k (premium)
gpt-4 - 8K - {ModelConfig[AgentModelName.gpt_4].cost} credits/query
(premium)
</Option>
<Option
value={AgentModelName.gpt_4}
value={AgentModelName.gpt_4_turbo}
disabled={!session?.data?.organization?.isPremium}
>
OpenAI gpt-4 (premium)
gpt-4-turbo - 128k - {ModelConfig[AgentModelName.gpt_4_turbo].cost}{' '}
credits/query (premium)
</Option>
</Select>
</FormControl>
Expand Down
36 changes: 13 additions & 23 deletions apps/dashboard/components/AgentSettingsTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ function AgentSettingsTab(props: Props) {

useEffect(() => {
if (router.query.settingTab) {
delete router.query.settingTab;
router.replace(router, undefined, { shallow: true });
setState({
currentTab: router.query.settingTab as string,
});
}
}, []);
}, [router.query.settingTab]);

const handleChangeTab = (tab: string) => {
router.query.settingTab = tab;
router.replace(router, undefined, { shallow: true });
};

if (!agent) {
return null;
Expand All @@ -72,11 +78,7 @@ function AgentSettingsTab(props: Props) {
<ListItem>
<ListItemButton
selected={state.currentTab === 'general'}
onClick={() =>
setState({
currentTab: 'general',
})
}
onClick={() => handleChangeTab('general')}
>
<ListItemDecorator>
<SettingsRoundedIcon />
Expand All @@ -87,11 +89,7 @@ function AgentSettingsTab(props: Props) {
<ListItem>
<ListItemButton
selected={state.currentTab === 'model'}
onClick={() =>
setState({
currentTab: 'model',
})
}
onClick={() => handleChangeTab('model')}
>
<ListItemDecorator>
<SmartToyRoundedIcon />
Expand All @@ -102,11 +100,7 @@ function AgentSettingsTab(props: Props) {
<ListItem>
<ListItemButton
selected={state.currentTab === 'tools'}
onClick={() =>
setState({
currentTab: 'tools',
})
}
onClick={() => handleChangeTab('tools')}
>
<ListItemDecorator>
<SpokeRoundedIcon />
Expand All @@ -117,11 +111,7 @@ function AgentSettingsTab(props: Props) {
<ListItem>
<ListItemButton
selected={state.currentTab === 'security'}
onClick={() =>
setState({
currentTab: 'security',
})
}
onClick={() => handleChangeTab('security')}
>
<ListItemDecorator>
<SecurityRoundedIcon />
Expand Down
9 changes: 7 additions & 2 deletions apps/dashboard/components/AgentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Link from 'next/link';
import * as React from 'react';

import { RouteNames } from '@chaindesk/lib/types';
import { Agent, Datastore } from '@chaindesk/prisma';
import { Agent } from '@chaindesk/prisma';

export default function AgentTable({ items }: { items: Agent[] }) {
return (
Expand Down Expand Up @@ -46,8 +46,8 @@ export default function AgentTable({ items }: { items: Agent[] }) {
<tr>
<th style={{ width: 120, padding: 12 }}>Name</th>
<th style={{ width: 120, padding: 12 }}>Description</th>
<th style={{ width: 120, padding: 12 }}>Model</th>
<th style={{ width: 220, padding: 12 }}>Visibility</th>
{/* <th style={{ width: 120, padding: 12 }}>Subscription</th> */}
<th style={{ width: 160, padding: 12 }}> </th>
</tr>
</thead>
Expand Down Expand Up @@ -85,6 +85,11 @@ export default function AgentTable({ items }: { items: Agent[] }) {
</Typography>
</td>

<td>
<Chip variant="soft" size="sm" color={'neutral'}>
{agent.modelName}
</Chip>
</td>
<td>
<Chip
variant="soft"
Expand Down
17 changes: 17 additions & 0 deletions apps/dashboard/pages/agents/[agentId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ export default function AgentPage() {
<Typography level="h1" fontSize="xl4">
{query?.data?.name}
</Typography>
<Chip
size="sm"
variant="soft"
color={'primary'}
onClick={() => {
router.query.tab = 'settings';
router.query.settingTab = 'model';
router.push(router);
}}
>
{query?.data?.modelName}
</Chip>
<Chip
size="sm"
variant="soft"
Expand All @@ -191,6 +203,11 @@ export default function AgentPage() {
private: 'neutral',
}[query?.data?.visibility!] as ColorPaletteProp
}
onClick={() => {
router.query.tab = 'settings';
router.query.settingTab = 'security';
router.push(router);
}}
>
{query?.data?.visibility}
</Chip>
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/pages/api/agents/[id]/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import cuid from 'cuid';
import { NextApiRequest, NextApiResponse } from 'next';

import { NewConversation, render } from '@chaindesk/emails';
import { queryCountConfig } from '@chaindesk/lib/account-config';
import AgentManager from '@chaindesk/lib/agent';
import { ApiError, ApiErrorType } from '@chaindesk/lib/api-error';
import {
formatOrganizationSession,
sessionOrganizationInclude,
} from '@chaindesk/lib/auth';
import { ModelConfig } from '@chaindesk/lib/config';
import ConversationManager from '@chaindesk/lib/conversation';
import {
createLazyAuthHandler,
Expand Down Expand Up @@ -177,7 +177,7 @@ export const chatAgentRequest = async (
data: {
nbAgentQueries:
(agent?.organization?.usage?.nbAgentQueries || 0) +
(queryCountConfig?.[agent?.modelName] || 1),
(ModelConfig?.[agent?.modelName].cost || 1),
},
}),
]);
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/pages/api/chains/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const runChainRequest = async (
},
include: {
messages: {
take: -4,
take: -24,
orderBy: {
createdAt: 'asc',
},
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/tests/test-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const customerSupportDataset = [
(async () => {
const agent = await prisma.agent.findUnique({
where: {
id: 'cloiefapb000q0ut1pamawveh',
id: 'cloisatop00080u2u5cuzwphg',
},
include: {
tools: {
Expand Down
7 changes: 0 additions & 7 deletions packages/lib/account-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ type Plan = {
};
};

export const queryCountConfig = {
[AgentModelName.gpt_3_5_turbo]: 1,
[AgentModelName.gpt_3_5_turbo_16k]: 15,
[AgentModelName.gpt_4]: 20,
[AgentModelName.gpt_4_32k]: 30,
};

const config: {
[key in SubscriptionPlan]: Plan;
} = {
Expand Down
18 changes: 16 additions & 2 deletions packages/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,34 @@ export const XPBNPLabels = {

export const ModelConfig = {
[AgentModelName.gpt_3_5_turbo]: {
name: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo-1106',
maxTokens: 4096,
cost: 1,
},
[AgentModelName.gpt_3_5_turbo_16k]: {
name: 'gpt-3.5-turbo-16k',
name: 'gpt-3.5-turbo-1106',
maxTokens: 16384,
cost: 1,
},
[AgentModelName.gpt_4]: {
name: 'gpt-4',
maxTokens: 8192,
cost: 30,
},
[AgentModelName.gpt_4_32k]: {
name: 'gpt-4-32k',
maxTokens: 32768,
cost: 60,
},
[AgentModelName.gpt_4_turbo]: {
name: 'gpt-4-1106-preview',
maxTokens: 128000,
cost: 13,
},
[AgentModelName.gpt_4_turbo_vision]: {
name: 'gpt-4-vision-preview',
maxTokens: 128000,
cost: 13,
},
};

Expand Down
10 changes: 10 additions & 0 deletions packages/prisma/migrations/20231106203619_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.


ALTER TYPE "AgentModelName" ADD VALUE 'gpt_4_turbo';
ALTER TYPE "AgentModelName" ADD VALUE 'gpt_4_turbo_vision';
2 changes: 2 additions & 0 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ enum AgentModelName {
gpt_3_5_turbo_16k
gpt_4
gpt_4_32k
gpt_4_turbo
gpt_4_turbo_vision
}

enum MessageEval {
Expand Down

1 comment on commit afb0ac2

@vercel
Copy link

@vercel vercel bot commented on afb0ac2 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.