Skip to content

Commit

Permalink
post cherry-pick validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Jan 21, 2025
1 parent 259a293 commit 578bdca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
9 changes: 6 additions & 3 deletions backend/danswer/llm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ def litellm_exception_to_error_msg(

def translate_danswer_msg_to_langchain(
msg: Union[ChatMessage, "PreviousMessage"],
exclude_images: bool = False,
) -> BaseMessage:
files: list[InMemoryChatFile] = []

# If the message is a `ChatMessage`, it doesn't have the downloaded files
# attached. Just ignore them for now.
if not isinstance(msg, ChatMessage):
files = msg.files
content = build_content_with_imgs(msg.message, files, message_type=msg.message_type)
content = build_content_with_imgs(
msg.message, files, message_type=msg.message_type, exclude_images=exclude_images
)

if msg.message_type == MessageType.SYSTEM:
raise ValueError("System messages are not currently part of history")
Expand All @@ -126,10 +129,10 @@ def translate_danswer_msg_to_langchain(


def translate_history_to_basemessages(
history: list[ChatMessage] | list["PreviousMessage"],
history: list[ChatMessage] | list["PreviousMessage"], exclude_images: bool = False
) -> tuple[list[BaseMessage], list[int]]:
history_basemessages = [
translate_danswer_msg_to_langchain(msg)
translate_danswer_msg_to_langchain(msg, exclude_images)
for msg in history
if msg.token_count != 0
]
Expand Down
13 changes: 12 additions & 1 deletion web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,18 @@ export function ChatPage({
end: 0,
mostVisibleMessageId: null,
};

useEffect(() => {
if (
imageFileInMessageHistory &&
!checkLLMSupportsImageInput(llmOverrideManager.llmOverride.modelName)
) {
setPopup({
message:
"This LLM will not be able to process all files (i.e. image files) in your chat history",
type: "error",
});
}
}, [llmOverrideManager.llmOverride, imageFileInMessageHistory]);
useEffect(() => {
if (noAssistants) {
return;
Expand Down
5 changes: 0 additions & 5 deletions web/src/app/chat/modal/configuration/LlmTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { destructureValue } from "@/lib/llm/utils";
import { updateModelOverrideForChatSession } from "../../lib";
import { GearIcon } from "@/components/icons/icons";
import { LlmList } from "@/components/llm/LLMList";
import { checkPersonaRequiresImageGeneration } from "@/app/admin/assistants/lib";

interface LlmTabProps {
llmOverrideManager: LlmOverrideManager;
Expand All @@ -31,9 +30,6 @@ export const LlmTab = forwardRef<HTMLDivElement, LlmTabProps>(
},
ref
) => {
const requiresImageGeneration =
checkPersonaRequiresImageGeneration(currentAssistant);

const { llmProviders } = useChatContext();
const { updateLLMOverride, temperature, updateTemperature } =
llmOverrideManager;
Expand Down Expand Up @@ -70,7 +66,6 @@ export const LlmTab = forwardRef<HTMLDivElement, LlmTabProps>(
</button>
</div>
<LlmList
requiresImageGeneration={requiresImageGeneration}
llmProviders={llmProviders}
currentLlm={currentLlm}
onSelect={(value: string | null) => {
Expand Down
40 changes: 18 additions & 22 deletions web/src/components/llm/LLMList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface LlmListProps {
userDefault?: string | null;
scrollable?: boolean;
hideProviderIcon?: boolean;
requiresImageGeneration?: boolean;
}

export const LlmList: React.FC<LlmListProps> = ({
Expand All @@ -22,7 +21,6 @@ export const LlmList: React.FC<LlmListProps> = ({
onSelect,
userDefault,
scrollable,
requiresImageGeneration,
}) => {
const llmOptionsByProvider: {
[provider: string]: {
Expand Down Expand Up @@ -62,7 +60,9 @@ export const LlmList: React.FC<LlmListProps> = ({

return (
<div
className={`${scrollable ? "max-h-[200px] include-scrollbar" : "max-h-[300px]"} bg-background-175 flex flex-col gap-y-1 overflow-y-scroll`}
className={`${
scrollable ? "max-h-[200px] include-scrollbar" : "max-h-[300px]"
} bg-background-175 flex flex-col gap-y-1 overflow-y-scroll`}
>
{userDefault && (
<button
Expand All @@ -79,25 +79,21 @@ export const LlmList: React.FC<LlmListProps> = ({
</button>
)}

{llmOptions.map(({ name, icon, value }, index) => {
if (!requiresImageGeneration || checkLLMSupportsImageInput(name)) {
return (
<button
type="button"
key={index}
className={`w-full py-1.5 flex gap-x-2 px-2 text-sm ${
currentLlm == name
? "bg-background-200"
: "bg-background hover:bg-background-100"
} text-left rounded`}
onClick={() => onSelect(value)}
>
{icon({ size: 16 })}
{getDisplayNameForModel(name)}
</button>
);
}
})}
{llmOptions.map(({ name, icon, value }, index) => (
<button
type="button"
key={index}
className={`w-full py-1.5 flex gap-x-2 px-2 text-sm ${
currentLlm == name
? "bg-background-200"
: "bg-background hover:bg-background-100"
} text-left rounded`}
onClick={() => onSelect(value)}
>
{icon({ size: 16 })}
{getDisplayNameForModel(name)}
</button>
))}
</div>
);
};

0 comments on commit 578bdca

Please sign in to comment.