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

feature: add highlight options checkbox to chat playground #2965

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions frontends/chat/src/components/Layouts/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const MainLayout = (props: LayoutProps) => {
null,
);

const [highlightResults, setHighlightResults] = createSignal<boolean | null>(
null,
);
const [streamCompletionsFirst, setStreamCompletionsFirst] = createSignal<
boolean | null
>(null);
Expand Down Expand Up @@ -244,6 +247,9 @@ const MainLayout = (props: LayoutProps) => {
use_group_search: useGroupSearch(),
search_type: searchType(),
context_options: contextOptions(),
highlight_options: {
highlight_results: highlightResults(),
},
}),
signal: completionAbortController().signal,
});
Expand Down Expand Up @@ -452,6 +458,20 @@ const MainLayout = (props: LayoutProps) => {
tabIndex={0}
>
<div class="flex flex-col gap-2">
<div class="flex w-full items-center gap-x-2">
<label for="stream_completion_first">
Highlight Results
</label>
<input
type="checkbox"
id="stream_completion_first"
class="h-4 w-4 rounded-md border border-neutral-300 bg-neutral-100 p-1 dark:border-neutral-900 dark:bg-neutral-800"
checked={highlightResults() ?? false}
onChange={(e) => {
setHighlightResults(e.target.checked);
}}
/>
</div>
<div class="flex w-full items-center gap-x-2">
<label for="stream_completion_first">
Stream Completions First
Expand Down
6 changes: 6 additions & 0 deletions frontends/dashboard/src/components/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const ApiRoutes = {
"POST /api/topic",
"POST /api/message",
"PUT /api/message",
"POST /api/chunk/recommend",
"POST /api/chunk_group/recommend",
"GET /api/chunk/tracking_id/{tracking_id}",
"GET /api/chunk/{chunk_id}",
"GET /api/chunk_group/tracking_id/{tracking_id}",
"GET /api/chunk_group/{group_id}",
],
"api/analytics/*": [
"POST /api/analytics/rag",
Expand Down
23 changes: 21 additions & 2 deletions server/src/middleware/auth_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,29 @@ where
}
}

let route = format!("{} {}", req.method(), req.match_info().as_str());
let curly_matcher =
regex::Regex::new(r"\{[a-zA-Z0-9_-]+\}").expect("Valid regex");

let route = format!("{} {}", req.method(), req.match_info().as_str());
if let Some(api_key_scopes) = user_api_key.scopes {
if !api_key_scopes.is_empty() && api_key_scopes.contains(&Some(route)) {
if !api_key_scopes.is_empty()
&& (api_key_scopes.contains(&Some(route.clone()))
|| api_key_scopes
.iter()
.filter_map(|scope| scope.as_ref())
.any(|scope| {
let wildcard_scope = curly_matcher
.replace_all(scope, "[a-zA-Z0-9_-]+")
.to_string();
if let Ok(wildcard_scope_regex) =
regex::Regex::new(&wildcard_scope)
{
wildcard_scope_regex.is_match(&route)
} else {
false
}
}))
{
if let Some(ref mut user) = user {
user.user_orgs.iter_mut().for_each(|org| {
if org.organization_id
Expand Down