Skip to content

Commit

Permalink
feat: gpt4 is not available for brains if there is no given openAiKey (
Browse files Browse the repository at this point in the history
…#850)

* rename defineMaxToken

* use gpt-3.5-turbo instead of gpt-3.5-turbo-0613

* gpt4 not available if no open ai key
  • Loading branch information
ChloeMouret committed Aug 7, 2023
1 parent 61cd0a6 commit e9ebeef
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion backend/core/models/brains.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Brain(BaseModel):
name: Optional[str] = "Default brain"
description: Optional[str] = "This is a description"
status: Optional[str] = "private"
model: Optional[str] = "gpt-3.5-turbo-0613"
model: Optional[str] = "gpt-3.5-turbo"
temperature: Optional[float] = 0.0
max_tokens: Optional[int] = 256
openai_api_key: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion backend/core/models/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChatMessage(BaseModel):


class ChatQuestion(BaseModel):
model: str = "gpt-3.5-turbo-0613"
model: str = "gpt-3.5-turbo"
question: str
temperature: float = 0.0
max_tokens: int = 256
2 changes: 1 addition & 1 deletion backend/core/models/databases/supabase/brains.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateBrainProperties(BaseModel):
name: Optional[str] = "Default brain"
description: Optional[str] = "This is a description"
status: Optional[str] = "private"
model: Optional[str] = "gpt-3.5-turbo-0613"
model: Optional[str] = "gpt-3.5-turbo"
temperature: Optional[float] = 0.0
max_tokens: Optional[int] = 256
openai_api_key: Optional[str] = None
Expand Down
4 changes: 2 additions & 2 deletions backend/core/routes/chat_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def create_question_handler(
or not chat_question.max_tokens
):
# TODO: create ChatConfig class (pick config from brain or user or chat) and use it here
chat_question.model = chat_question.model or brain.model or "gpt-3.5-turbo-0613"
chat_question.model = chat_question.model or brain.model or "gpt-3.5-turbo"
chat_question.temperature = chat_question.temperature or brain.temperature or 0
chat_question.max_tokens = chat_question.max_tokens or brain.max_tokens or 256

Expand Down Expand Up @@ -254,7 +254,7 @@ async def create_stream_question_handler(
or not chat_question.max_tokens
):
# TODO: create ChatConfig class (pick config from brain or user or chat) and use it here
chat_question.model = chat_question.model or brain.model or "gpt-3.5-turbo-0613"
chat_question.model = chat_question.model or brain.model or "gpt-3.5-turbo"
chat_question.temperature = chat_question.temperature or brain.temperature or 0
chat_question.max_tokens = chat_question.max_tokens or brain.max_tokens or 256

Expand Down
4 changes: 2 additions & 2 deletions backend/core/tests/test_brains.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_create_brain(client, api_key):
payload = {
"name": random_brain_name,
"status": "public",
"model": "gpt-3.5-turbo-0613",
"model": "gpt-3.5-turbo",
"temperature": 0,
"max_tokens": 256,
"file_sha1": "",
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_set_as_default_brain_endpoint(client, api_key):
payload = {
"name": random_brain_name,
"status": "public",
"model": "gpt-3.5-turbo-0613",
"model": "gpt-3.5-turbo",
"temperature": 0,
"max_tokens": 256,
}
Expand Down
4 changes: 2 additions & 2 deletions backend/core/tests/test_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_create_chat_and_talk(client, api_key):
response = client.post(
f"/chat/{chat_id}/question?brain_id={default_brain_id}",
json={
"model": "gpt-3.5-turbo-0613",
"model": "gpt-3.5-turbo",
"question": "Hello, how are you?",
"temperature": "0",
"max_tokens": "256",
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_create_chat_and_talk_with_no_brain(client, api_key):
response = client.post(
f"/chat/{chat_id}/question?brain_id=",
json={
"model": "gpt-3.5-turbo-0613",
"model": "gpt-3.5-turbo",
"question": "Hello, how are you?",
"temperature": "0",
"max_tokens": "256",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import Button from "@/lib/components/ui/Button";
import { Divider } from "@/lib/components/ui/Divider";
import Field from "@/lib/components/ui/Field";
import { TextArea } from "@/lib/components/ui/TextArea";
import { models, paidModels } from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";
import {
freeModels,
paidModels,
} from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens";

import { PublicPrompts } from "./components/PublicPrompts/PublicPrompts";
import { useSettingsTab } from "./hooks/useSettingsTab";
Expand Down Expand Up @@ -99,7 +102,7 @@ export const SettingsTab = ({ brainId }: SettingsTabProps): JSX.Element => {
{...register("model")}
className="px-5 py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
>
{(openAiKey !== undefined ? paidModels : models).map(
{(openAiKey !== undefined ? paidModels : freeModels).map(
(availableModel) => (
<option value={availableModel} key={availableModel}>
{availableModel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { usePromptApi } from "@/lib/api/prompt/usePromptApi";
import { useBrainConfig } from "@/lib/context/BrainConfigProvider";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
import { Brain } from "@/lib/context/BrainProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";
import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens";
import { useToast } from "@/lib/hooks";

type UseSettingsTabProps = {
Expand Down Expand Up @@ -317,7 +317,7 @@ export const useSettingsTab = ({ brainId }: UseSettingsTabProps) => {
return {
handleSubmit,
register,
openAiKey,
openAiKey: openAiKey === "" ? undefined : openAiKey,
model,
temperature,
maxTokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { MdCheck, MdSettings } from "react-icons/md";

import Button from "@/lib/components/ui/Button";
import { Modal } from "@/lib/components/ui/Modal";
import { models } from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";
import { freeModels } from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens";

import { useConfigModal } from "./hooks/useConfigModal";

Expand Down Expand Up @@ -56,7 +56,7 @@ export const ConfigModal = ({ chatId }: { chatId?: string }): JSX.Element => {
{...register("model")}
className="px-5 py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
>
{models.map((availableModel) => (
{freeModels.map((availableModel) => (
<option value={availableModel} key={availableModel}>
{availableModel}
</option>
Expand Down Expand Up @@ -85,7 +85,7 @@ export const ConfigModal = ({ chatId }: { chatId?: string }): JSX.Element => {
<input
type="range"
min="10"
max={defineMaxTokens(model ?? "gpt-3.5-turbo-0613")}
max={defineMaxTokens(model ?? "gpt-3.5-turbo")}
value={maxTokens}
{...register("maxTokens")}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { useBrainConfig } from "@/lib/context/BrainConfigProvider";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
import { ChatConfig } from "@/lib/context/ChatProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";
import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens";
import { useToast } from "@/lib/hooks";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/api/brain/__tests__/useBrainApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("useBrainApi", () => {
name: "Test Brain",
description: "This is a description",
status: "public",
model: "gpt-3.5-turbo-0613",
model: "gpt-3.5-turbo",
temperature: 0.0,
max_tokens: 256,
openai_api_key: "123",
Expand Down Expand Up @@ -217,7 +217,7 @@ describe("useBrainApi", () => {
name: "Test Brain",
description: "This is a description",
status: "public",
model: "gpt-3.5-turbo-0613",
model: "gpt-3.5-turbo",
temperature: 0.0,
max_tokens: 256,
openai_api_key: "123",
Expand Down
9 changes: 6 additions & 3 deletions frontend/lib/components/AddBrainModal/AddBrainModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { PublicPrompts } from "@/app/brains-management/[brainId]/components/Brai
import Button from "@/lib/components/ui/Button";
import Field from "@/lib/components/ui/Field";
import { Modal } from "@/lib/components/ui/Modal";
import { models, paidModels } from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";
import {
freeModels,
paidModels,
} from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens";

import { useAddBrainModal } from "./hooks/useAddBrainModal";
import { Divider } from "../ui/Divider";
Expand Down Expand Up @@ -84,7 +87,7 @@ export const AddBrainModal = (): JSX.Element => {
{...register("model")}
className="px-5 py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
>
{(openAiKey !== undefined ? paidModels : models).map(
{(openAiKey !== undefined ? paidModels : freeModels).map(
(availableModel) => (
<option value={availableModel} key={availableModel}>
{availableModel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useBrainApi } from "@/lib/api/brain/useBrainApi";
import { usePromptApi } from "@/lib/api/prompt/usePromptApi";
import { useBrainConfig } from "@/lib/context/BrainConfigProvider";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";
import { defineMaxTokens } from "@/lib/helpers/defineMaxTokens";
import { useToast } from "@/lib/hooks";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand Down Expand Up @@ -145,7 +145,7 @@ export const useAddBrainModal = () => {
setIsShareModalOpen,
handleSubmit,
register,
openAiKey,
openAiKey: openAiKey === "" ? undefined : openAiKey,
model,
temperature,
maxTokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const BrainConfigContext = createContext<
>(undefined);

const defaultBrainConfig: BrainConfig = {
model: "gpt-3.5-turbo-0613",
model: "gpt-3.5-turbo",
temperature: 0,
maxTokens: 256,
keepLocal: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const BrainConfigProviderMock = ({
<BrainConfigContextMock.Provider
value={{
config: {
model: "gpt-3.5-turbo-0613",
model: "gpt-3.5-turbo",
temperature: 0,
maxTokens: 256,
keepLocal: true,
Expand Down
24 changes: 7 additions & 17 deletions frontend/lib/context/BrainConfigProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,9 @@ export type BrainConfigContextType = {
resetConfig: () => void;
};

// export const openAiModels = ["gpt-3.5-turbo", "gpt-4"] as const; ## TODO activate GPT4 when not in demo mode
export const openAiFreeModels = ["gpt-3.5-turbo", "gpt-3.5-turbo-16k"] as const;

export const openAiModels = [
"gpt-3.5-turbo",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k",
] as const;
export const openAiPaidModels = [
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k",
"gpt-4",
"gpt-4-0613",
] as const;
export const openAiPaidModels = [...openAiFreeModels, "gpt-4"] as const;

export const anthropicModels = [
// "claude-v1",
Expand All @@ -47,14 +37,14 @@ export const googleModels = [
] as const; // TODO activate when not in demo mode

// export const googleModels = [] as const;
export const models = [
...openAiModels,
...anthropicModels,
...googleModels,
export const freeModels = [
...openAiFreeModels,
// ...anthropicModels,
// ...googleModels,
] as const;

export const paidModels = [...openAiPaidModels] as const;

export type PaidModels = (typeof paidModels)[number];

export type Model = (typeof models)[number];
export type Model = (typeof freeModels)[number];
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { Model, PaidModels } from "../context/BrainConfigProvider/types";
export const defineMaxTokens = (model: Model | PaidModels): number => {
//At the moment is evaluating only models from OpenAI
switch (model) {
case "gpt-3.5-turbo-0613":
case "gpt-3.5-turbo":
return 500;
case "gpt-3.5-turbo-16k":
return 2000;
case "gpt-4":
return 1000;
case "gpt-4-0613":
return 100;
default:
return 250;
}
Expand Down

0 comments on commit e9ebeef

Please sign in to comment.