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

fix: changing developer settings sends the correct overrides #154

Merged
merged 3 commits into from
Dec 4, 2023
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
6 changes: 3 additions & 3 deletions packages/chat-component/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ declare interface ChatRequestOptions {
}

declare interface RequestOverrides {
retrieval_mode?: string;
retrieval_mode?: 'hybrid' | 'text' | 'vectors';
semantic_ranker?: boolean;
semantic_captions?: boolean;
exclude_category?: string;
top?: number;
suggest_followup_questions?: boolean;
temperature?: number;
prompt_template?: string;
prompt_template_prefix?: string;
prompt_template_suffix?: string;
exclude_category?: string[];
suggest_followup_questions?: boolean;
}

declare interface BotResponse {
Expand Down
4 changes: 2 additions & 2 deletions packages/search/src/lib/approaches/ask-read-retrieve-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export class AskReadRetrieveRead extends ApproachBase implements AskApproach {
const executor = await initializeAgentExecutorWithOptions(tools, chatModel, {
agentType: 'chat-zero-shot-react-description',
agentArgs: {
prefix: context?.prompt_template_prefix ?? TEMPLATE_PREFIX,
suffix: context?.prompt_template_suffix ?? TEMPLATE_SUFFIX,
prefix: context?.prompt_template_prefix || TEMPLATE_PREFIX,
suffix: context?.prompt_template_suffix || TEMPLATE_SUFFIX,
inputVariables: ['input', 'agent_scratchpad'],
},
returnIntermediateSteps: true,
Expand Down
13 changes: 13 additions & 0 deletions packages/webapp/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ export const enum RetrievalMode {
Vectors = 'vectors',
Text = 'text',
}

export type RequestOverrides = {
retrieval_mode?: RetrievalMode;
semantic_ranker?: boolean;
semantic_captions?: boolean;
exclude_category?: string;
top?: number;
temperature?: number;
prompt_template?: string;
prompt_template_prefix?: string;
prompt_template_suffix?: string;
suggest_followup_questions?: boolean;
};
20 changes: 10 additions & 10 deletions packages/webapp/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from 'react';
import styles from './Chat.module.css';
import { RetrievalMode, apiBaseUrl } from '../../api/index.js';
import { RetrievalMode, apiBaseUrl, type RequestOverrides } from '../../api/index.js';
import { SettingsButton } from '../../components/SettingsButton/index.js';
import { Checkbox, DefaultButton, Dropdown, Panel, SpinButton, TextField, TooltipHost } from '@fluentui/react';
import type { IDropdownOption } from '@fluentui/react/lib-commonjs/Dropdown';
Expand Down Expand Up @@ -66,16 +66,16 @@ const Chat = () => {
setUseSuggestFollowupQuestions(!!checked);
};

const overrides = {
retrievalMode,
const overrides: RequestOverrides = {
retrieval_mode: retrievalMode,
top: retrieveCount,
useSemanticRanker,
useSemanticCaptions,
excludeCategory,
promptTemplate,
promptTemplatePrefix: '',
promptTemplateSuffix: '',
suggestFollowupQuestions: useSuggestFollowupQuestions,
semantic_ranker: useSemanticRanker,
semantic_captions: useSemanticCaptions,
exclude_category: excludeCategory,
prompt_template: promptTemplate,
prompt_template_prefix: '',
prompt_template_suffix: '',
suggest_followup_questions: useSuggestFollowupQuestions,
};

return (
Expand Down
20 changes: 10 additions & 10 deletions packages/webapp/src/pages/oneshot/OneShot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useState } from 'react';

import styles from './OneShot.module.css';

import { Approaches, RetrievalMode, apiBaseUrl } from '../../api/index.js';
import { Approaches, RetrievalMode, apiBaseUrl, type RequestOverrides } from '../../api/index.js';
import { SettingsButton } from '../../components/SettingsButton/SettingsButton.jsx';

import 'chat-component';
Expand Down Expand Up @@ -92,15 +92,15 @@ export function Component(): JSX.Element {
},
];

const overrides = {
retrievalMode,
retrieveCount,
useSemanticRanker,
useSemanticCaptions,
excludeCategory,
promptTemplate,
promptTemplatePrefix,
promptTemplateSuffix,
const overrides: RequestOverrides = {
retrieval_mode: retrievalMode,
top: retrieveCount,
semantic_ranker: useSemanticRanker,
semantic_captions: useSemanticCaptions,
exclude_category: excludeCategory,
prompt_template: promptTemplate,
prompt_template_prefix: promptTemplatePrefix,
prompt_template_suffix: promptTemplateSuffix,
};

return (
Expand Down
16 changes: 7 additions & 9 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defineConfig, devices } from '@playwright/test';
*/
// require('dotenv').config();

const useLocalServer = true;
const useLocalServer = false;

/**
* See https://playwright.dev/docs/test-configuration.
Expand All @@ -27,7 +27,7 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: useLocalServer ? 'http://localhost:5173' : process.env.WEBAPP_URI,
baseURL: 'http://localhost:5173',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand Down Expand Up @@ -72,11 +72,9 @@ export default defineConfig({
],

/* Run your local dev server before starting the tests */
webServer: useLocalServer
? {
command: 'npm run start:webapp',
url: 'http://localhost:5173',
reuseExistingServer: !process.env.CI,
}
: undefined,
webServer: {
command: 'npm run start:webapp',
url: 'http://localhost:5173',
reuseExistingServer: useLocalServer || !process.env.CI,
},
});
50 changes: 25 additions & 25 deletions tests/e2e/hars/default-ask-response.har

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions tests/e2e/hars/default-chat-response-nostream.har

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions tests/e2e/hars/default-chat-response-stream.har

Large diffs are not rendered by default.

47 changes: 24 additions & 23 deletions tests/e2e/hars/error-chat-response-stream.har
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@
},
"entries": [
{
"startedDateTime": "2023-10-25T00:27:07.983Z",
"time": 4348.057,
"startedDateTime": "2023-11-30T19:20:30.588Z",
"time": -1,
"request": {
"method": "POST",
"url": "http://localhost:5173/chat",
"httpVersion": "HTTP/2.0",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{ "name": ":authority", "value": "http://localhost:5173" },
{ "name": ":method", "value": "POST" },
{ "name": ":path", "value": "/chat" },
{ "name": ":scheme", "value": "http" },
{ "name": "accept", "value": "*/*" },
{ "name": "accept-encoding", "value": "gzip, deflate, br" },
{ "name": "accept-language", "value": "en-US" },
{ "name": "content-length", "value": "437" },
{ "name": "content-type", "value": "application/json" },
{ "name": "origin", "value": "http://localhost:5173" },
{ "name": "sec-fetch-dest", "value": "empty" },
{ "name": "sec-fetch-mode", "value": "cors" },
{ "name": "sec-fetch-site", "value": "cross-site" },
{ "name": "Accept", "value": "*/*" },
{ "name": "Accept-Encoding", "value": "gzip, deflate, br" },
{ "name": "Accept-Language", "value": "en-US" },
{ "name": "Connection", "value": "keep-alive" },
{ "name": "Content-Length", "value": "333" },
{ "name": "Content-Type", "value": "application/json" },
{ "name": "Host", "value": "localhost:5173" },
{ "name": "Origin", "value": "http://localhost:5173" },
{ "name": "Referer", "value": "http://localhost:5173/" },
{ "name": "Sec-Fetch-Dest", "value": "empty" },
{ "name": "Sec-Fetch-Mode", "value": "cors" },
{ "name": "Sec-Fetch-Site", "value": "same-origin" },
{
"name": "user-agent",
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.9 Safari/537.36"
}
],
Expand All @@ -42,19 +41,21 @@
"bodySize": -1,
"postData": {
"mimeType": "application/json",
"text": "{\"messages\":[{\"content\":\"How to search and book rentals?\",\"role\":\"user\"}],\"context\":{\"retrieval_mode\":\"hybrid\",\"semantic_ranker\":true,\"semantic_captions\":false,\"suggest_followup_questions\":true,\"retrievalMode\":\"hybrid\",\"top\":3,\"useSemanticRanker\":true,\"useSemanticCaptions\":false,\"excludeCategory\":\"\",\"promptTemplate\":\"\",\"promptTemplatePrefix\":\"\",\"promptTemplateSuffix\":\"\",\"suggestFollowupQuestions\":true,\"approach\":\"rrr\"},\"stream\":true}",
"text": "{\"messages\":[{\"content\":\"How to search and book rentals?\",\"role\":\"user\"}],\"context\":{\"retrieval_mode\":\"hybrid\",\"semantic_ranker\":true,\"semantic_captions\":false,\"suggest_followup_questions\":true,\"top\":3,\"exclude_category\":\"\",\"prompt_template\":\"\",\"prompt_template_prefix\":\"\",\"prompt_template_suffix\":\"\",\"approach\":\"rrr\"},\"stream\":true}",
"params": []
}
},
"response": {
"status": 200,
"statusText": "",
"httpVersion": "HTTP/2.0",
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{ "name": "access-control-allow-origin", "value": "http://localhost:5173" },
{ "name": "access-control-allow-origin", "value": "*" },
{ "name": "connection", "value": "close" },
{ "name": "content-type", "value": "application/x-ndjson" },
{ "name": "date", "value": "Wed, 25 Oct 2023 00:27:10 GMT" },
{ "name": "date", "value": "Thu, 30 Nov 2023 19:20:33 GMT" },
{ "name": "transfer-encoding", "value": "chunked" },
{ "name": "vary", "value": "Origin" }
],
"content": {
Expand All @@ -67,7 +68,7 @@
"redirectURL": ""
},
"cache": {},
"timings": { "send": -1, "wait": -1, "receive": 4348.057 }
"timings": { "send": -1, "wait": -1, "receive": -1 }
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/webapp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ test.describe('errors', () => {
await page.routeFromHAR('./tests/e2e/hars/error-chat-response-stream.har', {
url: '/chat',
update: false,
updateContent: 'embed',
});

await page.getByTestId('submit-question-button').click();
Expand Down Expand Up @@ -409,6 +410,7 @@ test.describe('developer settings', () => {
await page.routeFromHAR('./tests/e2e/hars/default-chat-response-nostream.har', {
url: '/chat',
update: false,
updateContent: 'embed',
});

await page.getByTestId('button__developer-settings').click();
Expand Down