Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Mintplex-Labs/anything-llm into r…
Browse files Browse the repository at this point in the history
…ender
  • Loading branch information
timothycarambat committed Mar 26, 2024
2 parents 540d18e + 9f55f44 commit 971c54e
Show file tree
Hide file tree
Showing 31 changed files with 948 additions and 183 deletions.
4 changes: 2 additions & 2 deletions collector/processSingleFile/convert/asPDF.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ async function asPDF({ fullFilePath = "", filename = "" }) {
const data = {
id: v4(),
url: "file://" + fullFilePath,
title: docs[0]?.metadata?.pdf?.info?.Title || filename,
title: filename,
docAuthor: docs[0]?.metadata?.pdf?.info?.Creator || "no author found",
description: "No description found.",
description: docs[0]?.metadata?.pdf?.info?.Title || "No description found.",
docSource: "pdf file uploaded by the user.",
chunkSource: "",
published: createdDate(fullFilePath),
Expand Down
1 change: 1 addition & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ GID='1000'

# LLM_PROVIDER='lmstudio'
# LMSTUDIO_BASE_PATH='http://your-server:1234/v1'
# LMSTUDIO_MODEL_PREF='Loaded from Chat UI' # this is a bug in LMStudio 0.2.17
# LMSTUDIO_MODEL_TOKEN_LIMIT=4096

# LLM_PROVIDER='localai'
Expand Down
33 changes: 19 additions & 14 deletions docker/HOW_TO_USE_DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,33 @@ container rebuilds or pulls from Docker Hub.

Your docker host will show the image as online once the build process is completed. This will build the app to `http://localhost:3001`.

## ⚠️ Vector DB support ⚠️
## Integrations and one-click setups

Out of the box, all vector databases are supported. Any vector databases requiring special configuration are listed below.
The integrations below are templates or tooling built by the community to make running the docker experience of AnythingLLM easier.

### Using local ChromaDB with Dockerized AnythingLLM
### Use the Midori AI Subsystem to Manage AnythingLLM

- Ensure in your `./docker/.env` file that you have
Follow the setup found on [Midori AI Subsystem Site](https://io.midori-ai.xyz/subsystem/manager/) for your host OS
After setting that up install the AnythingLLM docker backend to the Midori AI Subsystem.

```
#./docker/.env
...other configs
Once that is done, you are all set!

VECTOR_DB="chroma"
CHROMA_ENDPOINT='http://host.docker.internal:8000' # Allow docker to look on host port, not container.
# CHROMA_API_HEADER="X-Api-Key" // If you have an Auth middleware on your instance.
# CHROMA_API_KEY="sk-123abc"
## Common questions and fixes

...other configs
### Cannot connect to service running on localhost!

```
If you are in docker and cannot connect to a service running on your host machine running on a local interface or loopback:

- `localhost`
- `127.0.0.1`
- `0.0.0.0`

> [!IMPORTANT]
> On linux `http://host.docker.internal:xxxx` does not work.
> Use `http://172.17.0.1:xxxx` instead to emulate this functionality.
Then in docker you need to replace that localhost part with `host.docker.internal`. For example, if running Ollama on the host machine, bound to http://127.0.0.1:11434 you should put `http://host.docker.internal:11434` into the connection URL in AnythingLLM.

## Common questions and fixes

### API is not working, cannot login, LLM is "offline"?

Expand Down
80 changes: 80 additions & 0 deletions frontend/src/components/LLMSelection/LMStudioOptions/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { useEffect, useState } from "react";
import { Info } from "@phosphor-icons/react";
import paths from "@/utils/paths";
import System from "@/models/system";

export default function LMStudioOptions({ settings, showAlert = false }) {
const [basePathValue, setBasePathValue] = useState(
settings?.LMStudioBasePath
);
const [basePath, setBasePath] = useState(settings?.LMStudioBasePath);

return (
<div className="w-full flex flex-col">
{showAlert && (
Expand Down Expand Up @@ -35,8 +42,11 @@ export default function LMStudioOptions({ settings, showAlert = false }) {
required={true}
autoComplete="off"
spellCheck={false}
onChange={(e) => setBasePathValue(e.target.value)}
onBlur={() => setBasePath(basePathValue)}
/>
</div>
<LMStudioModelSelection settings={settings} basePath={basePath} />
<div className="flex flex-col w-60">
<label className="text-white text-sm font-semibold block mb-4">
Token context window
Expand All @@ -57,3 +67,73 @@ export default function LMStudioOptions({ settings, showAlert = false }) {
</div>
);
}

function LMStudioModelSelection({ settings, basePath = null }) {
const [customModels, setCustomModels] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
async function findCustomModels() {
if (!basePath || !basePath.includes("/v1")) {
setCustomModels([]);
setLoading(false);
return;
}
setLoading(true);
const { models } = await System.customModels("lmstudio", null, basePath);
setCustomModels(models || []);
setLoading(false);
}
findCustomModels();
}, [basePath]);

if (loading || customModels.length == 0) {
return (
<div className="flex flex-col w-60">
<label className="text-white text-sm font-semibold block mb-4">
Chat Model Selection
</label>
<select
name="LMStudioModelPref"
disabled={true}
className="bg-zinc-900 border-gray-500 text-white text-sm rounded-lg block w-full p-2.5"
>
<option disabled={true} selected={true}>
{basePath?.includes("/v1")
? "-- loading available models --"
: "-- waiting for URL --"}
</option>
</select>
</div>
);
}

return (
<div className="flex flex-col w-60">
<label className="text-white text-sm font-semibold block mb-4">
Chat Model Selection
</label>
<select
name="LMStudioModelPref"
required={true}
className="bg-zinc-900 border-gray-500 text-white text-sm rounded-lg block w-full p-2.5"
>
{customModels.length > 0 && (
<optgroup label="Your loaded models">
{customModels.map((model) => {
return (
<option
key={model.id}
value={model.id}
selected={settings.LMStudioModelPref === model.id}
>
{model.id}
</option>
);
})}
</optgroup>
)}
</select>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,12 @@ import {
getFileExtension,
middleTruncate,
} from "@/utils/directories";
import { File, Trash } from "@phosphor-icons/react";
import System from "@/models/system";
import { File } from "@phosphor-icons/react";
import debounce from "lodash.debounce";

export default function FileRow({
item,
folderName,
selected,
toggleSelection,
fetchKeys,
setLoading,
setLoadingMessage,
}) {
export default function FileRow({ item, selected, toggleSelection }) {
const [showTooltip, setShowTooltip] = useState(false);

const onTrashClick = async (event) => {
event.stopPropagation();
if (
!window.confirm(
"Are you sure you want to delete this document?\nThis will require you to re-upload and re-embed it.\nThis document will be removed from any workspace that is currently referencing it.\nThis action is not reversible."
)
) {
return false;
}

try {
setLoading(true);
setLoadingMessage("This may take a while for large documents");
await System.deleteDocument(`${folderName}/${item.name}`);
await fetchKeys(true);
} catch (error) {
console.error("Failed to delete the document:", error);
}

if (selected) toggleSelection(item);
setLoading(false);
};

const handleShowTooltip = () => {
setShowTooltip(true);
};
Expand All @@ -56,11 +24,11 @@ export default function FileRow({
return (
<tr
onClick={() => toggleSelection(item)}
className={`transition-all duration-200 text-white/80 text-xs grid grid-cols-12 py-2 pl-3.5 pr-8 hover:bg-sky-500/20 cursor-pointer file-row ${
className={`text-white/80 text-xs grid grid-cols-12 py-2 pl-3.5 pr-8 hover:bg-sky-500/20 cursor-pointer file-row ${
selected ? "selected" : ""
}`}
>
<div className="pl-2 col-span-5 flex gap-x-[4px] items-center">
<div className="pl-2 col-span-6 flex gap-x-[4px] items-center">
<div
className="shrink-0 w-3 h-3 rounded border-[1px] border-white flex justify-center items-center cursor-pointer"
role="checkbox"
Expand Down Expand Up @@ -94,16 +62,12 @@ export default function FileRow({
<p className="col-span-2 pl-2 uppercase overflow-x-hidden">
{getFileExtension(item.url)}
</p>
<div className="col-span-2 flex justify-end items-center">
<div className="-col-span-2 flex justify-end items-center">
{item?.cached && (
<div className="bg-white/10 rounded-3xl">
<p className="text-xs px-2 py-0.5">Cached</p>
</div>
)}
<Trash
onClick={onTrashClick}
className="text-base font-bold w-4 h-4 ml-2 flex-shrink-0 cursor-pointer"
/>
</div>
</tr>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,18 @@
import { useState } from "react";
import FileRow from "../FileRow";
import { CaretDown, FolderNotch, Trash } from "@phosphor-icons/react";
import { CaretDown, FolderNotch } from "@phosphor-icons/react";
import { middleTruncate } from "@/utils/directories";
import System from "@/models/system";

export default function FolderRow({
item,
selected,
onRowClick,
toggleSelection,
isSelected,
fetchKeys,
setLoading,
setLoadingMessage,
autoExpanded = false,
}) {
const [expanded, setExpanded] = useState(autoExpanded);

const onTrashClick = async (event) => {
event.stopPropagation();
if (
!window.confirm(
"Are you sure you want to delete this folder?\nThis will require you to re-upload and re-embed it.\nAny documents in this folder will be removed from any workspace that is currently referencing it.\nThis action is not reversible."
)
) {
return false;
}

try {
setLoading(true);
setLoadingMessage("This may take a while for large folders");
await System.deleteFolder(item.name);
await fetchKeys(true);
} catch (error) {
console.error("Failed to delete the document:", error);
}

if (selected) toggleSelection(item);
setLoading(false);
};

const handleExpandClick = (event) => {
event.stopPropagation();
setExpanded(!expanded);
Expand All @@ -49,7 +22,7 @@ export default function FolderRow({
<>
<tr
onClick={onRowClick}
className={`transition-all duration-200 text-white/80 text-xs grid grid-cols-12 py-2 pl-3.5 pr-8 bg-[#2C2C2C] hover:bg-sky-500/20 cursor-pointer w-full file-row:0 ${
className={`text-white/80 text-xs grid grid-cols-12 py-2 pl-3.5 pr-8 bg-[#1C1E21] hover:bg-sky-500/20 cursor-pointer w-full file-row ${
selected ? "selected" : ""
}`}
>
Expand All @@ -59,6 +32,10 @@ export default function FolderRow({
role="checkbox"
aria-checked={selected}
tabIndex={0}
onClick={(event) => {
event.stopPropagation();
toggleSelection(item);
}}
>
{selected && <div className="w-2 h-2 bg-white rounded-[2px]" />}
</div>
Expand All @@ -75,35 +52,23 @@ export default function FolderRow({
weight="fill"
/>
<p className="whitespace-nowrap overflow-show">
{middleTruncate(item.name, 40)}
{middleTruncate(item.name, 35)}
</p>
</div>
<p className="col-span-2 pl-3.5" />
<p className="col-span-2 pl-2" />
<div className="col-span-2 flex justify-end items-center">
{item.name !== "custom-documents" && (
<Trash
onClick={onTrashClick}
className="text-base font-bold w-4 h-4 ml-2 flex-shrink-0 cursor-pointer"
/>
)}
</div>
</tr>
{expanded && (
<div className="col-span-full">
<>
{item.items.map((fileItem) => (
<FileRow
key={fileItem.id}
item={fileItem}
folderName={item.name}
selected={isSelected(fileItem.id)}
toggleSelection={toggleSelection}
fetchKeys={fetchKeys}
setLoading={setLoading}
setLoadingMessage={setLoadingMessage}
/>
))}
</div>
</>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { middleTruncate } from "@/utils/directories";

export default function FolderSelectionPopup({ folders, onSelect, onClose }) {
const handleFolderSelect = (folder) => {
onSelect(folder);
onClose();
};

return (
<div className="absolute bottom-full left-0 mb-2 bg-white rounded-lg shadow-lg">
<ul>
{folders.map((folder) => (
<li
key={folder.name}
onClick={() => handleFolderSelect(folder)}
className="px-4 py-2 text-xs text-gray-700 hover:bg-gray-200 rounded-lg cursor-pointer whitespace-nowrap"
>
{middleTruncate(folder.name, 25)}
</li>
))}
</ul>
</div>
);
}
Loading

0 comments on commit 971c54e

Please sign in to comment.