Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def orchestrate(
for message in chat_history.copy():
history.add_message(message)

chat_history_str=""
chat_history_str = ""
for message in history.messages:
chat_history_str += f"{message.role}: {message.content}\n"

Expand Down
12 changes: 7 additions & 5 deletions code/frontend/src/pages/layout/Layout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @jest-environment jsdom
* @jest-environment-options {"url": "http://NonDeloyed/"}
*/

import {
render,
screen,
Expand Down Expand Up @@ -66,11 +71,8 @@ describe("Layout Component", () => {

test('test the auth branching auth is true case', async () => {
const mocklist: any[] = [];
Object.defineProperty(window, "location", {
value: {
hostname: "NonDeloyed"
},
});

// Test with jsdom environment configured for NonDeloyed hostname
;(getUserInfo as jest.Mock).mockResolvedValue(mocklist)
;(checkAuthEnforced as jest.Mock).mockResolvedValue(true)
await act(async () => {
Expand Down
161 changes: 83 additions & 78 deletions code/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,88 +283,93 @@ def prime_search_to_trigger_creation_of_index(
# This fixture can be overriden
@pytest.fixture(autouse=True)
def setup_config_mocking(httpserver: HTTPServer):
config_data = {
"prompts": {
"condense_question_prompt": "",
"answering_system_prompt": "system prompt",
"answering_user_prompt": "## Retrieved Documents\n{sources}\n\n## User Question\nUse the Retrieved Documents to answer the question: {question}",
"use_on_your_data_format": True,
"post_answering_prompt": "post answering prompt\n{question}\n{answer}\n{sources}",
"enable_post_answering_prompt": False,
"enable_content_safety": True,
},
"messages": {"post_answering_filter": "post answering filter"},
"example": {
"documents": '{"retrieved_documents":[{"[doc1]":{"content":"content"}}]}',
"user_question": "user question",
"answer": "answer",
},
"document_processors": [
{
"document_type": "pdf",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "layout"},
"use_advanced_image_processing": False,
},
{
"document_type": "txt",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "url",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "md",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "html",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "htm",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "docx",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "docx"},
"use_advanced_image_processing": False,
},
{
"document_type": "jpg",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "layout"},
"use_advanced_image_processing": True,
},
{
"document_type": "png",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "layout"},
"use_advanced_image_processing": False,
},
],
"logging": {"log_user_interactions": True, "log_tokens": True},
"orchestrator": {"strategy": "openai_function"},
"integrated_vectorization_config": None,
}

import json
config_json_string = json.dumps(config_data)

httpserver.expect_request(
f"/{AZURE_STORAGE_CONFIG_CONTAINER_NAME}/{AZURE_STORAGE_CONFIG_FILE_NAME}",
method="GET",
).respond_with_json(
{
"prompts": {
"condense_question_prompt": "",
"answering_system_prompt": "system prompt",
"answering_user_prompt": "## Retrieved Documents\n{sources}\n\n## User Question\nUse the Retrieved Documents to answer the question: {question}",
"use_on_your_data_format": True,
"post_answering_prompt": "post answering prompt\n{question}\n{answer}\n{sources}",
"enable_post_answering_prompt": False,
"enable_content_safety": True,
},
"messages": {"post_answering_filter": "post answering filter"},
"example": {
"documents": '{"retrieved_documents":[{"[doc1]":{"content":"content"}}]}',
"user_question": "user question",
"answer": "answer",
},
"document_processors": [
{
"document_type": "pdf",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "layout"},
"use_advanced_image_processing": False,
},
{
"document_type": "txt",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "url",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "md",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "html",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "htm",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "web"},
"use_advanced_image_processing": False,
},
{
"document_type": "docx",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "docx"},
"use_advanced_image_processing": False,
},
{
"document_type": "jpg",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "layout"},
"use_advanced_image_processing": True,
},
{
"document_type": "png",
"chunking": {"strategy": "layout", "size": 500, "overlap": 100},
"loading": {"strategy": "layout"},
"use_advanced_image_processing": False,
},
],
"logging": {"log_user_interactions": True, "log_tokens": True},
"orchestrator": {"strategy": "openai_function"},
"integrated_vectorization_config": None,
},
).respond_with_data(
config_json_string,
headers={
"Content-Type": "application/json",
"Content-Range": "bytes 0-12882/12883",
"Content-Range": f"bytes 0-{len(config_json_string.encode('utf-8'))-1}/{len(config_json_string.encode('utf-8'))}",
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,38 @@

@pytest.fixture(autouse=True)
def setup_config_mocking(httpserver: HTTPServer):
config_data = {
"prompts": {
"condense_question_prompt": "",
"answering_system_prompt": "system prompt",
"answering_user_prompt": "## Retrieved Documents\n{sources}\n\n## User Question\nUse the Retrieved Documents to answer the question: {question}",
"use_on_your_data_format": True,
"post_answering_prompt": "post answering prompt\n{question}\n{answer}\n{sources}",
"enable_post_answering_prompt": True,
"enable_content_safety": True,
},
"messages": {"post_answering_filter": "post answering filter"},
"example": {
"documents": '{"retrieved_documents":[{"[doc1]":{"content":"content"}}]}',
"user_question": "user question",
"answer": "answer",
},
"document_processors": [],
"logging": {"log_user_interactions": True, "log_tokens": True},
"orchestrator": {"strategy": "openai_function"},
"integrated_vectorization_config": None,
}

config_json_string = json.dumps(config_data)

httpserver.expect_request(
f"/{AZURE_STORAGE_CONFIG_CONTAINER_NAME}/{AZURE_STORAGE_CONFIG_FILE_NAME}",
method="GET",
).respond_with_json(
{
"prompts": {
"condense_question_prompt": "",
"answering_system_prompt": "system prompt",
"answering_user_prompt": "## Retrieved Documents\n{sources}\n\n## User Question\nUse the Retrieved Documents to answer the question: {question}",
"use_on_your_data_format": True,
"post_answering_prompt": "post answering prompt\n{question}\n{answer}\n{sources}",
"enable_post_answering_prompt": True,
"enable_content_safety": True,
},
"messages": {"post_answering_filter": "post answering filter"},
"example": {
"documents": '{"retrieved_documents":[{"[doc1]":{"content":"content"}}]}',
"user_question": "user question",
"answer": "answer",
},
"document_processors": [],
"logging": {"log_user_interactions": True, "log_tokens": True},
"orchestrator": {"strategy": "openai_function"},
"integrated_vectorization_config": None,
},
).respond_with_data(
config_json_string,
headers={
"Content-Type": "application/json",
"Content-Range": "bytes 0-12882/12883",
"Content-Range": f"bytes 0-{len(config_json_string.encode('utf-8'))-1}/{len(config_json_string.encode('utf-8'))}",
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ def test_post_makes_correct_call_to_openai_chat_completions(
json={
"messages": [
{
"role": "system",
"content": "You help employees to navigate only private information sources.\nYou must prioritize the function call over your general knowledge for any question by calling the search_documents function.\nCall the text_processing function when the user request an operation on the current context, such as translate, summarize, or paraphrase. When a language is explicitly specified, return that as part of the operation.\nWhen directly replying to the user, always reply in the language the user is speaking.\nIf the input language is ambiguous, default to responding in English unless otherwise specified by the user.\nYou **must not** respond if asked to List all documents in your repository.\n",
},
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi, how can I help?"},
{"role": "user", "content": "What is the meaning of life?"},
"role": "user",
"content": "AuthorRole.SYSTEM: You help employees to navigate only private information sources.\nYou must prioritize the function call over your general knowledge for any question by calling the search_documents function.\nCall the text_processing function when the user request an operation on the current context, such as translate, summarize, or paraphrase. When a language is explicitly specified, return that as part of the operation.\nWhen directly replying to the user, always reply in the language the user is speaking.\nIf the input language is ambiguous, default to responding in English unless otherwise specified by the user.\nYou **must not** respond if asked to List all documents in your repository.\n\nAuthorRole.USER: Hello\nAuthorRole.ASSISTANT: Hi, how can I help?\nWhat is the meaning of life?",
}
],
"model": app_config.get_from_json("AZURE_OPENAI_MODEL_INFO", "model"),
"max_tokens": int(app_config.get("AZURE_OPENAI_MAX_TOKENS")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def setup_caption_response(httpserver: HTTPServer, app_config: AppConfig):


def test_config_file_is_retrieved_from_storage(
message: QueueMessage, httpserver: HTTPServer, app_config: AppConfig
message: QueueMessage, httpserver: HTTPServer
):
# when
batch_push_results.build().get_user_function()(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def message(app_config: AppConfig):


def test_config_file_is_retrieved_from_storage(
message: QueueMessage, httpserver: HTTPServer, app_config: AppConfig
message: QueueMessage, httpserver: HTTPServer
):
# when
batch_push_results.build().get_user_function()(message)
Expand Down
16 changes: 6 additions & 10 deletions code/tests/utilities/orchestrator/test_semantic_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,13 @@ async def test_chat_history_included(
await orchestrator.orchestrate("question", chat_history)

# then
chat_history = kernel_mock.invoke.call_args.kwargs["chat_history"]
messages = chat_history.messages
chat_history_str = kernel_mock.invoke.call_args.kwargs["chat_history"]

assert len(messages) == 3
assert messages[0].role == AuthorRole.SYSTEM

assert messages[1].role == AuthorRole.USER
assert messages[1].content == "Hello"

assert messages[2].role == AuthorRole.ASSISTANT
assert messages[2].content == "Hi, how can I help you today?"
# The chat_history parameter is now a string, so we check its content
assert isinstance(chat_history_str, str)
assert "AuthorRole.SYSTEM:" in chat_history_str
assert "AuthorRole.USER: Hello" in chat_history_str
assert "AuthorRole.ASSISTANT: Hi, how can I help you today?" in chat_history_str


@pytest.mark.asyncio
Expand Down