Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added setting to allow to disable ssl verification for Website RAG #1912

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions backend/apps/rag/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
RAG_RERANKING_MODEL_TRUST_REMOTE_CODE,
RAG_OPENAI_API_BASE_URL,
RAG_OPENAI_API_KEY,
RAG_BYPASS_SSL_VERIFY,
DEVICE_TYPE,
CHROMA_CLIENT,
CHUNK_SIZE,
Expand Down Expand Up @@ -112,6 +113,7 @@
app.state.RAG_EMBEDDING_MODEL = RAG_EMBEDDING_MODEL
app.state.RAG_RERANKING_MODEL = RAG_RERANKING_MODEL
app.state.RAG_TEMPLATE = RAG_TEMPLATE
app.state.RAG_BYPASS_SSL_VERIFY = RAG_BYPASS_SSL_VERIFY

app.state.OPENAI_API_BASE_URL = RAG_OPENAI_API_BASE_URL
app.state.OPENAI_API_KEY = RAG_OPENAI_API_KEY
Expand Down Expand Up @@ -380,6 +382,25 @@ async def update_query_settings(
}


@app.get("/system/settings")
async def get_system_settings(user=Depends(get_admin_user)):
return {
"bypassSSLVerify": app.state.RAG_BYPASS_SSL_VERIFY
}

class SystemSettingsForm(BaseModel):
bypassSSLVerify: Optional[bool] = None

@app.post("/system/settings/update")
async def update_system_settings(
form_data: SystemSettingsForm, user=Depends(get_admin_user)
):
app.state.RAG_BYPASS_SSL_VERIFY = form_data.bypassSSLVerify if form_data.bypassSSLVerify else False
return {
"bypassSSLVerify": app.state.RAG_BYPASS_SSL_VERIFY
}


class QueryDocForm(BaseModel):
collection_name: str
query: str
Expand Down Expand Up @@ -486,6 +507,7 @@ def store_web(form_data: UrlForm, user=Depends(get_current_user)):
# "https://www.gutenberg.org/files/1727/1727-h/1727-h.htm"
try:
loader = get_web_loader(form_data.url)
loader.requests_kwargs = {'verify': app.state.RAG_BYPASS_SSL_VERIFY}
data = loader.load()

collection_name = form_data.collection_name
Expand Down
4 changes: 4 additions & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ def create_config_file(file_path):
os.environ.get("RAG_RERANKING_MODEL_TRUST_REMOTE_CODE", "").lower() == "true"
)

RAG_BYPASS_SSL_VERIFY = (
os.environ.get("RAG_BYPASS_SSL_VERIFY", "").lower() == "true"
)

# device type embedding models - "cpu" (default), "cuda" (nvidia gpu required) or "mps" (apple silicon) - choosing this right can lead to better performance
USE_CUDA = os.environ.get("USE_CUDA_DOCKER", "false")

Expand Down
61 changes: 61 additions & 0 deletions src/lib/apis/rag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,67 @@ export const updateQuerySettings = async (token: string, settings: QuerySettings
return res;
};

export const getSystemSettings = async (token: string) => {
let error = null;

const res = await fetch(`${RAG_API_BASE_URL}/system/settings`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.log(err);
error = err.detail;
return null;
});

if (error) {
throw error;
}

return res;
};

type SystemSettings = {
bypassSSLVerify: boolean | null;
};

export const updateSystemSettings = async (token: string, settings: SystemSettings) => {
let error = null;

const res = await fetch(`${RAG_API_BASE_URL}/system/settings/update`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
...settings
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.log(err);
error = err.detail;
return null;
});

if (error) {
throw error;
}

return res;
};

export const uploadDocToVectorDB = async (token: string, collection_name: string, file: File) => {
const data = new FormData();
data.append('file', file);
Expand Down
49 changes: 49 additions & 0 deletions src/lib/components/chat/Settings/RAG.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script lang="ts">
import {
getSystemSettings,
updateSystemSettings
} from '$lib/apis/rag';

import { getContext, onMount } from 'svelte';
const i18n = getContext('i18n');

let systemSettings = {
bypassSSLVerify: false
};

const toggleBypassSSLVerification = async () => {
systemSettings.bypassSSLVerify = !systemSettings.bypassSSLVerify;

systemSettings = await updateSystemSettings(localStorage.token, systemSettings);
};

onMount(async () => {
systemSettings = await getSystemSettings(localStorage.token);
});
</script>

<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[22rem]">
<div>
<div class=" mb-1 text-sm font-medium">{$i18n.t('Retrieval Augmented Generation Settings')}</div>

<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Bypass SSL verification for Websites')}</div>

<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleBypassSSLVerification();
}}
type="button"
>
{#if systemSettings.bypassSSLVerify === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
</div>
</div>
39 changes: 39 additions & 0 deletions src/lib/components/chat/SettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Models from './Settings/Models.svelte';
import General from './Settings/General.svelte';
import Interface from './Settings/Interface.svelte';
import RAG from './Settings/RAG.svelte';
import Audio from './Settings/Audio.svelte';
import Chats from './Settings/Chats.svelte';
import Connections from './Settings/Connections.svelte';
Expand Down Expand Up @@ -165,6 +166,38 @@
<div class=" self-center">{$i18n.t('Interface')}</div>
</button>

{#if $user.role === 'admin'}
<button
class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
'rag'
? 'bg-gray-200 dark:bg-gray-700'
: ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
on:click={() => {
selectedTab = 'rag';
}}
>
<div class=" self-center mr-2">
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 0.48 0.48"
fill="none"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M.271.209a.087.087 0 0 0-.124 0L.085.271a.087.087 0 1 0 .124.124L.24.364" stroke="#000" stroke-width=".04" stroke-linecap="round" stroke-linejoin="round"
clip-rule="evenodd"
/>
<path
fill-rule="evenodd"
d="M.209.271a.087.087 0 0 0 .124 0L.395.209A.087.087 0 1 0 .271.085L.24.116" stroke="#000" stroke-width=".04" stroke-linecap="round" stroke-linejoin="round"
clip-rule="evenodd"
/>
</svg>
</div>
<div class=" self-center">{$i18n.t('RAG')}</div>
</button>
{/if}

<button
class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
'audio'
Expand Down Expand Up @@ -323,6 +356,12 @@
toast.success($i18n.t('Settings saved successfully!'));
}}
/>
{:else if selectedTab === 'rag'}
<RAG
on:save={() => {
toast.success($i18n.t('Settings saved successfully!'));
}}
/>
{:else if selectedTab === 'audio'}
<Audio
{saveSettings}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/i18n/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"Add Tags": "",
"Add User": "",
"Adjusting these settings will apply changes universally to all users.": "",
"RAG": "",
"Retrieval Augmented Generation Settings": "",
"Bypass SSL verification for Websites": "",
"admin": "",
"Admin Panel": "",
"Admin Settings": "",
Expand Down