Skip to content

Commit

Permalink
prompt_name (#57)
Browse files Browse the repository at this point in the history
* updated various configs
added prompt_name to configuration

* minor updates

* minor updates
  • Loading branch information
ofermend authored Sep 12, 2023
1 parent a0b925a commit 2a88e3b
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 75 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,18 @@ The way summarization works can be configured as follows:
ux: "summary"

# Default language for summary response (if not specified defaults to "auto")
summary_default_language: "en"
summary_default_language: "eng"

# Number of sentences before and after relevant text segment used for summarization
summary_num_sentences: 3

# Number of results used for summarization
summary_num_results: 10

# The name of the summarization prompt in Vectara
# If you are a Vectara scale customer you can use custom prompts.
# This field names a custom prompt, otherwise it uses the default for the account.
summary_prompt_name: vectara-summary-ext-v1.2.0
```
#### Reranking (optional)
Expand Down
10 changes: 0 additions & 10 deletions config/docs-langchain/config.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions config/docs-langchain/queries.json

This file was deleted.

12 changes: 0 additions & 12 deletions config/docs-vectara/config.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions config/docs-vectara/queries.json

This file was deleted.

14 changes: 0 additions & 14 deletions config/feynman/config.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions config/feynman/queries.json

This file was deleted.

2 changes: 2 additions & 0 deletions docker/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ app.post("/config", (req, res) => {
summary_default_language,
summary_num_results,
summary_num_sentences,
summary_prompt_name,

// rerank
rerank,
Expand Down Expand Up @@ -114,6 +115,7 @@ app.post("/config", (req, res) => {
summary_default_language,
summary_num_results,
summary_num_sentences,
summary_prompt_name,

// rerank
rerank,
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@types/lodash": "^4.14.195",
"@types/node": "^16.18.12",
"@types/prismjs": "^1.26.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"axios": "^0.27.2",
"classnames": "^2.3.2",
"dotenv": "^16.0.3",
Expand Down Expand Up @@ -43,8 +43,7 @@
"inline-source-cli": "^2.0.0",
"prettier": "2.8.3",
"pretty-quick": "^3.1.3",
"sass": "^1.58.0",
"typescript": "^4.9.5"
"sass": "^1.58.0"
},
"scripts": {
"start": "PORT=4444 react-scripts start",
Expand Down
2 changes: 2 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ app.post("/config", (req, res) => {
summary_default_language,
summary_num_results,
summary_num_sentences,
summary_prompt_name,

// rerank
rerank,
Expand Down Expand Up @@ -113,6 +114,7 @@ app.post("/config", (req, res) => {
summary_default_language,
summary_num_results,
summary_num_sentences,
summary_prompt_name,

// rerank
rerank,
Expand Down
5 changes: 5 additions & 0 deletions src/contexts/ConfigurationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface Config {
config_summary_default_language?: string;
config_summary_num_results?: number;
config_summary_num_sentences?: number;
config_summary_prompt_name?: string

// rerank
config_rerank?: string;
Expand Down Expand Up @@ -107,6 +108,7 @@ type Summary = {
defaultLanguage: string;
summaryNumResults: number;
summaryNumSentences: number;
summaryPromptName: string;
};

type SearchHeader = {
Expand Down Expand Up @@ -242,6 +244,7 @@ export const ConfigContextProvider = ({ children }: Props) => {
defaultLanguage: "auto",
summaryNumResults: 7,
summaryNumSentences: 3,
summaryPromptName: "vectara-summary-ext-v1.2.0",
});

useEffect(() => {
Expand Down Expand Up @@ -328,6 +331,7 @@ export const ConfigContextProvider = ({ children }: Props) => {
config_summary_default_language,
config_summary_num_results,
config_summary_num_sentences,
config_summary_prompt_name,
} = config;

setSearch({
Expand Down Expand Up @@ -391,6 +395,7 @@ export const ConfigContextProvider = ({ children }: Props) => {
),
summaryNumResults: config_summary_num_results ?? 7,
summaryNumSentences: config_summary_num_sentences ?? 3,
summaryPromptName: config_summary_prompt_name ?? "vectara-summary-ext-v1.2.0",
});

setSearchHeader({
Expand Down
3 changes: 3 additions & 0 deletions src/contexts/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface SearchContextType {
language: SummaryLanguage;
summaryNumResults: number;
summaryNumSentences: number;
summaryPromptName: string;
history: HistoryItem[];
clearHistory: () => void;
searchResultsRef: React.MutableRefObject<HTMLElement[] | null[]>;
Expand Down Expand Up @@ -238,6 +239,7 @@ export const SearchContextProvider = ({ children }: Props) => {
rerankNumResults: rerank.numResults,
summaryNumResults: summary.summaryNumResults,
summaryNumSentences: summary.summaryNumSentences,
summaryPromptName: summary.summaryPromptName,
language,
customerId: search.customerId!,
corpusId: search.corpusId!,
Expand Down Expand Up @@ -293,6 +295,7 @@ export const SearchContextProvider = ({ children }: Props) => {
language: getLanguage(),
summaryNumResults: summary.summaryNumResults,
summaryNumSentences: summary.summaryNumSentences,
summaryPromptName: summary.summaryPromptName,
history,
clearHistory,
searchResultsRef,
Expand Down
14 changes: 12 additions & 2 deletions src/contexts/sendSearchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config = {
rerankNumResults?: number;
summaryNumResults?: number;
summaryNumSentences?: number;
summaryPromptName?: string;
customerId: string;
corpusId: string;
endpoint: string;
Expand All @@ -26,14 +27,15 @@ export const sendSearchRequest = async ({
rerankNumResults,
summaryNumResults,
summaryNumSentences,
summaryPromptName,
customerId,
corpusId,
endpoint,
apiKey,
}: Config) => {
const lambda =
typeof query_str === "undefined" || query_str.trim().split(" ").length > 1
? 0.025
typeof query_str === "undefined" || query_str.trim().split(" ").length > 2
? 0
: 0.1;
const corpusKeyList = corpusId.split(",").map((id) => {
return {
Expand Down Expand Up @@ -65,6 +67,7 @@ export const sendSearchRequest = async ({
{
responseLang: language,
maxSummarizedResults: summaryNumResults,
summarizer_prompt_name: summaryPromptName,
},
],
}
Expand Down Expand Up @@ -120,6 +123,13 @@ export const sendSearchRequest = async ({
) {
throw new Error(`BAD REQUEST: Too much text for the summarizer to summarize. Please try reducing the number of search results to summarize, or the context of each result by adjusting the 'summary_num_sentences', and 'summary_num_results' parameters respectively.`);
}
if (
summaryStatus.length > 0 &&
summaryStatus[0]["code"] === "NOT_FOUND" &&
summaryStatus[0]["statusDetail"] === "Failed to retrieve summarizer."
) {
throw new Error(`BAD REQUEST: summarizer ${summaryPromptName} is invalid for this account.`);
}
}

return result["data"]["responseSet"][0];
Expand Down
24 changes: 24 additions & 0 deletions src/views/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export const SUMMARY_LANGUAGES = [
"jpn",
"pol",
"tur",
"heb",
"vie",
"ind",
"ces",
"ukr",
"ell",
"fas",
"hin",
"urd",
"swe",
"ben",
"msa",
] as const;

export type SummaryLanguage = (typeof SUMMARY_LANGUAGES)[number];
Expand All @@ -100,6 +112,18 @@ const codeToLanguageMap: Record<SummaryLanguage, string> = {
jpn: "Japanese",
pol: "Polish",
tur: "Turkish",
heb: "Hebrew",
vie: "Vietnamese",
ind: "Indonesian",
ces: "Czech",
ukr: "Ukrainian",
ell: "Greek",
fas: "Farsi",
hin: "Hindi",
urd: "Urdu",
swe: "Swedish",
ben: "Bengali",
msa: "Malay",
} as const;

export const humanizeLanguage = (language: SummaryLanguage): string => {
Expand Down

0 comments on commit 2a88e3b

Please sign in to comment.