Skip to content

Commit

Permalink
add default model + minor fixes (#2638)
Browse files Browse the repository at this point in the history
* add default model + minor fixes

* fix build

* minor additional fix

* build fix
  • Loading branch information
pablonyx authored Oct 1, 2024
1 parent 2f2fc08 commit 9a4e51a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _get_answer(new_message_request: DirectQARequest) -> OneShotQAResponse | Non
detail="Slack bot does not support persona config",
)

elif new_message_request.persona_id:
elif new_message_request.persona_id is not None:
persona = cast(
Persona,
fetch_persona_by_id(
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/admin/assistants/PersonaTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function PersonasTable({
id: persona.id.toString(),
cells: [
<div key="name" className="flex">
{!persona.is_default_persona && (
{!persona.builtin_persona && (
<FiEdit2
className="mr-1 my-auto cursor-pointer"
onClick={() =>
Expand Down
3 changes: 2 additions & 1 deletion web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export function ChatPage({
};

const llmOverrideManager = useLlmOverride(
user?.preferences.default_model,
user?.preferences.default_model ?? null,
selectedChatSession,
defaultTemperature
);
Expand Down Expand Up @@ -1779,6 +1779,7 @@ export function ChatPage({

{settingsToggled && (
<SetDefaultModelModal
setPopup={setPopup}
setLlmOverride={llmOverrideManager.setGlobalDefault}
defaultModel={user?.preferences.default_model!}
refreshUser={refreshUser}
Expand Down
6 changes: 3 additions & 3 deletions web/src/app/chat/modal/SetDefaultModelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import { LLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces"
import { destructureValue, structureValue } from "@/lib/llm/utils";
import { setUserDefaultModel } from "@/lib/users/UserSettings";
import { useRouter } from "next/navigation";
import { usePopup } from "@/components/admin/connectors/Popup";
import { PopupSpec } from "@/components/admin/connectors/Popup";

export function SetDefaultModelModal({
setPopup,
llmProviders,
onClose,
setLlmOverride,
defaultModel,
refreshUser,
}: {
setPopup: (popupSpec: PopupSpec | null) => void;
llmProviders: LLMProviderDescriptor[];
setLlmOverride: Dispatch<SetStateAction<LlmOverride>>;
onClose: () => void;
defaultModel: string | null;
refreshUser: () => void;
}) {
const { popup, setPopup } = usePopup();
const containerRef = useRef<HTMLDivElement>(null);
const messageRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -127,7 +128,6 @@ export function SetDefaultModelModal({
modalClassName="rounded-lg bg-white max-w-xl"
>
<>
{popup}
<div className="flex mb-4">
<h2 className="text-2xl text-emphasis font-bold flex my-auto">
Set Default Model
Expand Down
14 changes: 13 additions & 1 deletion web/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function useLlmOverride(
defaultTemperature?: number
): LlmOverrideManager {
const [globalDefault, setGlobalDefault] = useState<LlmOverride>(
globalModel
globalModel != null
? destructureValue(globalModel)
: {
name: "",
Expand Down Expand Up @@ -182,6 +182,18 @@ export function useLlmOverride(
defaultTemperature != undefined ? defaultTemperature : 0
);

useEffect(() => {
setGlobalDefault(
globalModel != null
? destructureValue(globalModel)
: {
name: "",
provider: "",
modelName: "",
}
);
}, [globalModel]);

useEffect(() => {
setTemperature(defaultTemperature !== undefined ? defaultTemperature : 0);
}, [defaultTemperature]);
Expand Down

0 comments on commit 9a4e51a

Please sign in to comment.