Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/danswer-ai/danswer into bug…
Browse files Browse the repository at this point in the history
…fix/celery_light_backoff
  • Loading branch information
rkuo-danswer committed Oct 25, 2024
2 parents 9e555ed + bd63119 commit 9469b3c
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def upgrade() -> None:


def downgrade() -> None:
# First, update any null values to a default value
op.execute(
"UPDATE connector_credential_pair SET last_attempt_status = 'NOT_STARTED' WHERE last_attempt_status IS NULL"
)

# Then, make the column non-nullable
op.alter_column(
"connector_credential_pair",
"last_attempt_status",
Expand Down
6 changes: 5 additions & 1 deletion backend/danswer/llm/answering/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _raw_output_for_explicit_tool_calling_llms(
prompt=prompt,
tools=final_tool_definitions if final_tool_definitions else None,
tool_choice="required" if self.force_use_tool.force_use else None,
structured_response_format=self.answer_style_config.structured_response_format,
):
if isinstance(message, AIMessageChunk) and (
message.tool_call_chunks or message.tool_calls
Expand Down Expand Up @@ -331,7 +332,10 @@ def _process_llm_stream(
tool_choice: ToolChoiceOptions | None = None,
) -> Iterator[str | StreamStopInfo]:
for message in self.llm.stream(
prompt=prompt, tools=tools, tool_choice=tool_choice
prompt=prompt,
tools=tools,
tool_choice=tool_choice,
structured_response_format=self.answer_style_config.structured_response_format,
):
if isinstance(message, AIMessageChunk):
if message.content:
Expand Down
47 changes: 23 additions & 24 deletions backend/tests/integration/tests/dev_apis/test_simple_chat_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,42 +154,38 @@ def test_send_message_simple_with_history_strict_json(
new_admin_user: DATestUser | None,
) -> None:
# create connectors
cc_pair_1: DATestCCPair = CCPairManager.create_from_scratch(
user_performing_action=new_admin_user,
)
api_key: DATestAPIKey = APIKeyManager.create(
user_performing_action=new_admin_user,
)
LLMProviderManager.create(user_performing_action=new_admin_user)
cc_pair_1.documents = DocumentManager.seed_dummy_docs(
cc_pair=cc_pair_1,
num_docs=NUM_DOCS,
api_key=api_key,
)

response = requests.post(
f"{API_SERVER_URL}/chat/send-message-simple-with-history",
json={
# intentionally not relevant prompt to ensure that the
# structured response format is actually used
"messages": [
{
"message": "List the names of the first three US presidents in JSON format",
"message": "What is green?",
"role": MessageType.USER.value,
}
],
"persona_id": 0,
"prompt_id": 0,
"structured_response_format": {
"type": "json_object",
"schema": {
"type": "object",
"properties": {
"presidents": {
"type": "array",
"items": {"type": "string"},
"description": "List of the first three US presidents",
}
"type": "json_schema",
"json_schema": {
"name": "presidents",
"schema": {
"type": "object",
"properties": {
"presidents": {
"type": "array",
"items": {"type": "string"},
"description": "List of the first three US presidents",
}
},
"required": ["presidents"],
"additionalProperties": False,
},
"required": ["presidents"],
"strict": True,
},
},
},
Expand All @@ -211,14 +207,17 @@ def clean_json_string(json_string: str) -> str:
try:
clean_answer = clean_json_string(response_json["answer"])
parsed_answer = json.loads(clean_answer)

# NOTE: do not check content, just the structure
assert isinstance(parsed_answer, dict)
assert "presidents" in parsed_answer
assert isinstance(parsed_answer["presidents"], list)
assert len(parsed_answer["presidents"]) == 3
for president in parsed_answer["presidents"]:
assert isinstance(president, str)
except json.JSONDecodeError:
assert False, "The answer is not a valid JSON object"
assert (
False
), f"The answer is not a valid JSON object - '{response_json['answer']}'"

# Check that the answer_citationless is also valid JSON
assert "answer_citationless" in response_json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export function ProviderCreationModal({

return (
<Modal
width="max-w-3xl"
title={`Configure ${selectedProvider.provider_type}`}
onOutsideClick={onCancel}
icon={selectedProvider.icon}
Expand Down
6 changes: 3 additions & 3 deletions web/src/app/admin/prompt-library/modals/AddPromptModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { Formik, Form } from "formik";
import * as Yup from "yup";
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { Button } from "@tremor/react";

import { BookstackIcon } from "@/components/icons/icons";
import { AddPromptModalProps } from "../interfaces";
import { TextFormField } from "@/components/admin/connectors/Field";
import { Modal } from "@/components/Modal";

const AddPromptSchema = Yup.object().shape({
title: Yup.string().required("Title is required"),
Expand All @@ -15,7 +15,7 @@ const AddPromptSchema = Yup.object().shape({

const AddPromptModal = ({ onClose, onSubmit }: AddPromptModalProps) => {
return (
<ModalWrapper onClose={onClose} modalClassName="max-w-xl">
<Modal onOutsideClick={onClose} width="max-w-xl">
<Formik
initialValues={{
title: "",
Expand Down Expand Up @@ -57,7 +57,7 @@ const AddPromptModal = ({ onClose, onSubmit }: AddPromptModalProps) => {
</Form>
)}
</Formik>
</ModalWrapper>
</Modal>
);
};

Expand Down
15 changes: 8 additions & 7 deletions web/src/app/admin/prompt-library/modals/EditPromptModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import { Formik, Form, Field, ErrorMessage } from "formik";
import * as Yup from "yup";
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { Modal } from "@/components/Modal";
import { Button, Textarea, TextInput } from "@tremor/react";

import { useInputPrompt } from "../hooks";
import { EditPromptModalProps } from "../interfaces";

Expand All @@ -25,20 +26,20 @@ const EditPromptModal = ({

if (error)
return (
<ModalWrapper onClose={onClose} modalClassName="max-w-xl">
<Modal onOutsideClick={onClose} width="max-w-xl">
<p>Failed to load prompt data</p>
</ModalWrapper>
</Modal>
);

if (!promptData)
return (
<ModalWrapper onClose={onClose} modalClassName="max-w-xl">
<Modal onOutsideClick={onClose} width="max-w-xl">
<p>Loading...</p>
</ModalWrapper>
</Modal>
);

return (
<ModalWrapper onClose={onClose} modalClassName="max-w-xl">
<Modal onOutsideClick={onClose} width="max-w-xl">
<Formik
initialValues={{
prompt: promptData.prompt,
Expand Down Expand Up @@ -131,7 +132,7 @@ const EditPromptModal = ({
</Form>
)}
</Formik>
</ModalWrapper>
</Modal>
);
};

Expand Down
6 changes: 3 additions & 3 deletions web/src/app/chat/modal/FeedbackModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useState } from "react";
import { FeedbackType } from "../types";
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { Modal } from "@/components/Modal";
import { FilledLikeIcon } from "@/components/icons/icons";

const predefinedPositiveFeedbackOptions =
Expand Down Expand Up @@ -49,7 +49,7 @@ export const FeedbackModal = ({
: predefinedNegativeFeedbackOptions;

return (
<ModalWrapper onClose={onClose} modalClassName="max-w-3xl">
<Modal onOutsideClick={onClose} width="max-w-3xl">
<>
<h2 className="text-2xl text-emphasis font-bold mb-4 flex">
<div className="mr-1 my-auto">
Expand Down Expand Up @@ -112,6 +112,6 @@ export const FeedbackModal = ({
</button>
</div>
</>
</ModalWrapper>
</Modal>
);
};
6 changes: 3 additions & 3 deletions web/src/app/chat/modal/MakePublicAssistantModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { Modal } from "@/components/Modal";
import { Button, Divider, Text } from "@tremor/react";

export function MakePublicAssistantModal({
Expand All @@ -11,7 +11,7 @@ export function MakePublicAssistantModal({
onClose: () => void;
}) {
return (
<ModalWrapper onClose={onClose} modalClassName="max-w-3xl">
<Modal onOutsideClick={onClose} width="max-w-3xl">
<div className="space-y-6">
<h2 className="text-2xl font-bold text-emphasis">
{isPublic ? "Public Assistant" : "Make Assistant Public"}
Expand Down Expand Up @@ -67,6 +67,6 @@ export function MakePublicAssistantModal({
</div>
)}
</div>
</ModalWrapper>
</Modal>
);
}
9 changes: 3 additions & 6 deletions web/src/app/chat/modal/SetDefaultModelModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, SetStateAction, useEffect, useRef } from "react";
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { Modal } from "@/components/Modal";
import { Text } from "@tremor/react";
import { getDisplayNameForModel, LlmOverride } from "@/lib/hooks";
import { LLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces";
Expand Down Expand Up @@ -123,10 +123,7 @@ export function SetDefaultModelModal({
);

return (
<ModalWrapper
onClose={onClose}
modalClassName="rounded-lg bg-white max-w-xl"
>
<Modal onOutsideClick={onClose} width="rounded-lg bg-white max-w-xl">
<>
<div className="flex mb-4">
<h2 className="text-2xl text-emphasis font-bold flex my-auto">
Expand Down Expand Up @@ -203,6 +200,6 @@ export function SetDefaultModelModal({
</div>
</div>
</>
</ModalWrapper>
</Modal>
);
}
6 changes: 3 additions & 3 deletions web/src/app/chat/modal/ShareChatSessionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { Modal } from "@/components/Modal";
import { Button, Callout, Divider, Text } from "@tremor/react";
import { Spinner } from "@/components/Spinner";
import { ChatSessionSharedStatus } from "../interfaces";
Expand Down Expand Up @@ -57,7 +57,7 @@ export function ShareChatSessionModal({
);

return (
<ModalWrapper onClose={onClose} modalClassName="max-w-3xl">
<Modal onOutsideClick={onClose} width="max-w-3xl">
<>
<div className="flex mb-4">
<h2 className="text-2xl text-emphasis font-bold flex my-auto">
Expand Down Expand Up @@ -154,6 +154,6 @@ export function ShareChatSessionModal({
)}
</div>
</>
</ModalWrapper>
</Modal>
);
}
6 changes: 3 additions & 3 deletions web/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export function Modal({
e.stopPropagation();
}
}}
className={`bg-background text-emphasis rounded shadow-2xl
className={`bg-background text-emphasis rounded shadow-2xl
transform transition-all duration-300 ease-in-out
${width ?? "w-11/12 max-w-5xl"}
${width ?? "w-11/12 max-w-4xl"}
${noPadding ? "" : "p-10"}
${className || ""}`}
>
Expand Down Expand Up @@ -88,7 +88,7 @@ export function Modal({
{!hideDividerForTitle && <Divider />}
</>
)}
{children}
<div className="max-h-[60vh] overflow-y-scroll">{children}</div>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/modals/DeleteEntityModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FiTrash, FiX } from "react-icons/fi";
import { ModalWrapper } from "@/components/modals/ModalWrapper";
import { BasicClickable } from "@/components/BasicClickable";
import { Modal } from "../Modal";

export const DeleteEntityModal = ({
onClose,
Expand All @@ -16,7 +16,7 @@ export const DeleteEntityModal = ({
additionalDetails?: string;
}) => {
return (
<ModalWrapper onClose={onClose}>
<Modal onOutsideClick={onClose}>
<>
<div className="flex mb-4">
<h2 className="my-auto text-2xl font-bold">Delete {entityType}?</h2>
Expand All @@ -37,6 +37,6 @@ export const DeleteEntityModal = ({
</div>
</div>
</>
</ModalWrapper>
</Modal>
);
};
6 changes: 3 additions & 3 deletions web/src/components/modals/GenericConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FiCheck } from "react-icons/fi";
import { ModalWrapper } from "./ModalWrapper";
import { Modal } from "@/components/Modal";
import { BasicClickable } from "@/components/BasicClickable";

export const GenericConfirmModal = ({
Expand All @@ -16,7 +16,7 @@ export const GenericConfirmModal = ({
onConfirm: () => void;
}) => {
return (
<ModalWrapper onClose={onClose}>
<Modal onOutsideClick={onClose}>
<div className="max-w-full">
<div className="flex mb-4">
<h2 className="my-auto text-2xl font-bold whitespace-normal overflow-wrap-normal">
Expand All @@ -37,6 +37,6 @@ export const GenericConfirmModal = ({
</div>
</div>
</div>
</ModalWrapper>
</Modal>
);
};
Loading

0 comments on commit 9469b3c

Please sign in to comment.