Skip to content

Commit

Permalink
Fix misc tool call errors (#2544)
Browse files Browse the repository at this point in the history
* Fix misc tool call errors

* Fix middleware
  • Loading branch information
Weves authored Sep 23, 2024
1 parent 316b6b9 commit 77650c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions backend/danswer/llm/answering/answer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
from collections.abc import Callable
from collections.abc import Iterator
from typing import Any
Expand Down Expand Up @@ -554,8 +555,7 @@ def _process_stream(

def _stream() -> Iterator[str]:
nonlocal stream_stop_info
yield cast(str, message)
for item in stream:
for item in itertools.chain([message], stream):
if isinstance(item, StreamStopInfo):
stream_stop_info = item
return
Expand Down
25 changes: 15 additions & 10 deletions web/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@ import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED } from "./lib/constants";

// NOTE: have to have the "/:path*" here since NextJS doesn't allow any real JS to
// be run before the config is defined e.g. if we try and do a .map it will complain
const eePaths = [
"/admin/groups",
"/admin/api-key",
"/admin/performance/usage",
"/admin/performance/query-history",
"/admin/whitelabeling",
"/admin/performance/custom-analytics",
"/admin/standard-answer",
"/admin/groups/:path*",
"/admin/api-key/:path*",
"/admin/performance/usage/:path*",
"/admin/performance/query-history/:path*",
"/admin/whitelabeling/:path*",
"/admin/performance/custom-analytics/:path*",
"/admin/standard-answer/:path*",
];

const eePathsForMatcher = eePaths.map((path) => `${path}/:path*`);
// removes the "/:path*" from the end
const strippedEEPaths = eePaths.map((path) =>
path.replace(/(.*):\path\*$/, "$1").replace(/\/$/, "")
);

export async function middleware(request: NextRequest) {
if (SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED) {
const pathname = request.nextUrl.pathname;

// Check if the current path is in the eePaths list
if (eePaths.some((path) => pathname.startsWith(path))) {
if (strippedEEPaths.some((path) => pathname.startsWith(path))) {
// Add '/ee' to the beginning of the pathname
const newPathname = `/ee${pathname}`;

Expand All @@ -37,5 +42,5 @@ export async function middleware(request: NextRequest) {

// Specify the paths that the middleware should run for
export const config = {
matcher: eePathsForMatcher,
matcher: eePaths,
};

0 comments on commit 77650c9

Please sign in to comment.