Skip to content

Commit

Permalink
Merge pull request #520 from deeppavlov/dev
Browse files Browse the repository at this point in the history
Release v1.8.2
  • Loading branch information
dilyararimovna authored Jul 10, 2023
2 parents 58e6912 + ede443e commit fa72dc6
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 24 deletions.
22 changes: 22 additions & 0 deletions annotators/doc_retriever/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Document Retriever

## Description

Document Retriever is an annotator with two endpoints used to retrieve `PARAGRAPHS_NUM` document parts most relevant to the user request.

1. **train_and_upload_model** endpoint converts the documents provided by the user to txt format (if necessary) and splits them into chunks of ~100 words. Chunks are then transformed into a TF-IDF matrix; the resulting vectors and the vectorizer are saved for future use. This step is performed only once, in the beginning of the dialog.
Documents (txt format), matrix, and vectorizer are uploaded to file server to be used by **return_candidates** endpoint and **dff_document_qa_llm** skill.
2. **return_candidates** endpoint downloads TF-IDF matrix and vectorizer from the file server. It then converts the user’s utterance into a TF-IDF vector and finds `PARAGRAPHS_NUM` candidates with highest cosine similarity among TF-IDF vectors of text chunks.

## Parameters

```
CONFIG_PATH: configuration file with parameters for doc_retriever model
FILE_SERVER_TIMEOUT: timeout for request where files are stored
PARAGRAPHS_NUM: number of most relevant chunks to retrieve. Don't make this number too large or the chunks won't fit into LLM context!
DOC_PATH_OR_LINK: paths or link to the files to be use for Question Answering. If paths, those are paths to files in `documents` folder in dream. If links, those must point to a file, not an Internet page. NB: file paths/links must be separated by a comma and no whitespace.
```

## Dependencies

- **return_candidates** endpoint depends on **train_and_upload_model** endpoint
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERVICE_PORT: 8135
SERVICE_NAME: prompt_selector
N_SENTENCES_TO_RETURN: 3
PROMPTS_TO_CONSIDER: dream_persona
PROMPTS_TO_CONSIDER: dream_persona,dream_faq
FLASK_APP: server
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ compose:
SERVICE_PORT: 8135
SERVICE_NAME: prompt_selector
N_SENTENCES_TO_RETURN: 3
PROMPTS_TO_CONSIDER: dream_persona
PROMPTS_TO_CONSIDER: dream_persona,dream_faq
FLASK_APP: server
context: .
dockerfile: ./annotators/prompt_selector/Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion assistant_dists/document_based_qa/pipeline_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"metadata": {
"display_name": "ChatGPT-based Document QA",
"author": "DeepPavlov",
"description": "This assistant uses the power of ChatGPT to answer you questions based on the document you provide.",
"description": "This assistant uses the power of ChatGPT to answer your questions based on the document you provide.",
"version": "0.0.1",
"date_created": "2023-01-10T02:00:00",
"ram_usage": "9 GB",
Expand Down
19 changes: 15 additions & 4 deletions assistant_dists/dream_persona_openai_prompted/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ services:
- "./annotators/SentSeg:/src"
ports:
- 8011:8011
ranking-based-response-selector:
llm-based-response-selector:
volumes:
- "./response_selectors/ranking_based_response_selector:/src"
- "./response_selectors/llm_based_response_selector:/src"
- "./common:/src/common"
ports:
- 8002:8002
- 8003:8003
combined-classification:
volumes:
- "./common:/src/common"
Expand Down Expand Up @@ -52,5 +52,16 @@ services:
- "./common:/src/common"
ports:
- 8162:8162

dff-dream-faq-prompted-skill:
volumes:
- "./skills/dff_template_prompted_skill:/src"
- "./common:/src/common"
ports:
- 8170:8170
openai-api-chatgpt-16k:
volumes:
- "./services/openai_api_lm:/src"
- "./common:/src/common"
ports:
- 8167:8167
version: "3.7"
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ services:
agent:
command: sh -c 'bin/wait && python -m deeppavlov_agent.run agent.pipeline_config=assistant_dists/dream_persona_openai_prompted/pipeline_conf.json'
environment:
WAIT_HOSTS: "sentseg:8011, ranking-based-response-selector:8002, combined-classification:8087,
WAIT_HOSTS: "sentseg:8011, llm-based-response-selector:8003, combined-classification:8087,
sentence-ranker:8128, prompt-selector:8135, openai-api-chatgpt:8145,
dff-dream-persona-chatgpt-prompted-skill:8137"
dff-dream-persona-chatgpt-prompted-skill:8137, dff-dream-faq-prompted-skill:8170,
openai-api-chatgpt-16k:8167"
WAIT_HOSTS_TIMEOUT: ${WAIT_TIMEOUT:-1000}
HIGH_PRIORITY_INTENTS: 1
RESTRICTION_FOR_SENSITIVE_CASE: 1
Expand Down Expand Up @@ -44,21 +45,22 @@ services:
reservations:
memory: 2G

ranking-based-response-selector:
env_file: [ .env ]
llm-based-response-selector:
env_file: [ .env,.env_secret ]
build:
args:
SERVICE_PORT: 8002
SERVICE_PORT: 8003
SERVICE_NAME: response_selector
LANGUAGE: EN
SENTENCE_RANKER_ANNOTATION_NAME: sentence_ranker
SENTENCE_RANKER_SERVICE_URL: http://sentence-ranker:8128/respond
SENTENCE_RANKER_TIMEOUT: 3
N_UTTERANCES_CONTEXT: 5
GENERATIVE_SERVICE_URL: http://openai-api-chatgpt:8145/respond
GENERATIVE_SERVICE_CONFIG: openai-chatgpt.json
GENERATIVE_TIMEOUT: 120
N_UTTERANCES_CONTEXT: 7
ENVVARS_TO_SEND: OPENAI_API_KEY,OPENAI_ORGANIZATION
FILTER_TOXIC_OR_BADLISTED: 1
context: .
dockerfile: ./response_selectors/ranking_based_response_selector/Dockerfile
command: flask run -h 0.0.0.0 -p 8002
dockerfile: ./response_selectors/llm_based_response_selector/Dockerfile
command: flask run -h 0.0.0.0 -p 8003
environment:
- FLASK_APP=server
deploy:
Expand All @@ -75,7 +77,7 @@ services:
SERVICE_PORT: 8135
SERVICE_NAME: prompt_selector
N_SENTENCES_TO_RETURN: 3
PROMPTS_TO_CONSIDER: dream_persona
PROMPTS_TO_CONSIDER: dream_persona,dream_faq
context: .
dockerfile: ./annotators/prompt_selector/Dockerfile
command: flask run -h 0.0.0.0 -p 8135
Expand Down Expand Up @@ -164,4 +166,44 @@ services:
reservations:
memory: 128M

dff-dream-faq-prompted-skill:
env_file: [ .env,.env_secret ]
build:
args:
SERVICE_PORT: 8170
SERVICE_NAME: dff_dream_faq_prompted_skill
PROMPT_FILE: common/prompts/dream_faq.json
GENERATIVE_SERVICE_URL: http://openai-api-chatgpt-16k:8167/respond
GENERATIVE_SERVICE_CONFIG: openai-chatgpt.json
GENERATIVE_TIMEOUT: 120
N_UTTERANCES_CONTEXT: 7
ENVVARS_TO_SEND: OPENAI_API_KEY,OPENAI_ORGANIZATION
context: .
dockerfile: ./skills/dff_template_prompted_skill/Dockerfile
deploy:
resources:
limits:
memory: 128M
reservations:
memory: 128M

openai-api-chatgpt-16k:
env_file: [ .env ]
build:
args:
SERVICE_PORT: 8167
SERVICE_NAME: openai_api_chatgpt_16k
PRETRAINED_MODEL_NAME_OR_PATH: gpt-3.5-turbo-16k
context: .
dockerfile: ./services/openai_api_lm/Dockerfile
command: flask run -h 0.0.0.0 -p 8167
environment:
- FLASK_APP=server
deploy:
resources:
limits:
memory: 500M
reservations:
memory: 100M

version: '3.7'
27 changes: 24 additions & 3 deletions assistant_dists/dream_persona_openai_prompted/pipeline_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@
"component": "components/uYkoK0vRp4bbIg9akI1yw.yml",
"service": "skills/dummy_skill/service_configs/agent"
}
},
"dff_dream_faq_prompted_skill": {
"connector": {
"protocol": "http",
"timeout": 120.0,
"url": "http://dff-dream-faq-prompted-skill:8170/respond"
},
"dialog_formatter": {
"name": "state_formatters.dp_formatters:dff_prompted_skill_formatter",
"skill_name": "dff_dream_faq_prompted_skill"
},
"response_formatter": "state_formatters.dp_formatters:skill_with_attributes_formatter_service",
"previous_services": [
"skill_selectors"
],
"state_manager_method": "add_hypothesis",
"is_enabled": true,
"source": {
"component": "components/jFmKPqMJh0.yml",
"service": "skills/dff_template_prompted_skill/service_configs/dff-dream-faq-prompted-skill"
}
}
},
"candidate_annotators": {
Expand Down Expand Up @@ -269,8 +290,8 @@
"response_selector": {
"connector": {
"protocol": "http",
"timeout": 1.0,
"url": "http://ranking-based-response-selector:8002/respond"
"timeout": 120.0,
"url": "http://llm-based-response-selector:8003/respond"
},
"dialog_formatter": "state_formatters.dp_formatters:cropped_dialog",
"response_formatter": "state_formatters.dp_formatters:base_response_selector_formatter_service",
Expand All @@ -281,7 +302,7 @@
"is_enabled": true,
"source": {
"component": "components/YJzc7NwGrLmKp6gfZJh7X1.yml",
"service": "response_selectors/ranking_based_response_selector/service_configs/ranking-based-response-selector"
"service": "response_selectors/llm_based_response_selector/service_configs/llm-based-response-selector"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion response_selectors/llm_based_response_selector/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def respond():
hypotheses = [hyp for hyp in dialog["human_utterances"][-1]["hypotheses"]]
if FILTER_TOXIC_OR_BADLISTED:
hypotheses = filter_out_badlisted_or_toxic(hypotheses)

hypotheses_texts = "\n".join([f'{h["skill_name"]} (conf={h["confidence"]}): {h["text"]}' for h in hypotheses])
logger.info(f"Hypotheses: {hypotheses_texts}")
dialog_context = [uttr["text"] for uttr in dialog["utterances"][-N_UTTERANCES_CONTEXT:]]
selected_resp = select_response(
dialog_context, hypotheses, dialog["human_utterances"][-1].get("attributes", {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def send(self, payload: Dict, callback: Callable):
skills_for_uttr.extend(prompted_skills)
logger.info("Adding all prompted skills as prompt selector did not select anything.")

if is_any_question_sentence_in_utterance(dialog["human_utterances"][-1]) and is_factoid:
if is_any_question_sentence_in_utterance(dialog["human_utterances"][-1]):
skills_for_uttr.append("dff_google_api_skill")

if is_factoid:
Expand Down
28 changes: 28 additions & 0 deletions skills/dff_document_qa_llm_skill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# LLM-based Q&A on Documents Skill

## Description

LLM-based Q&A on Documents Skill answers questions about long documents provided by the user. It passes on document chunks most relevant to the user's question alongside with an instruction and the dialog context as a prompt to ChatGPT.

## Parameters

```
GENERATIVE_SERVICE_URL: LLM to utilize
GENERATIVE_SERVICE_CONFIG: configuration file with generative parameters to utilize
GENERATIVE_TIMEOUT: timeout for request to LLM
N_UTTERANCES_CONTEXT: number of last utterances to consider as a dialog context
ENVVARS_TO_SEND: API keys splitted by comma to get as env variables
FILE_SERVER_TIMEOUT: timeout for request where files are stored
DOCUMENT_PROMPT_FILE: file to get the instruction from (to insert into prompt guiding the Question Answering model)
```

## Dependencies

- LLM service provided in `GENERATIVE_SERVICE_URL`
- annotator Document Retriever (both endpoints)
- API keys in environmental variables for key-required LLMs (OpenAI API, Anthropic API)


## How to get OpenAI API key

Go to OpenAI and find your Secret API key in your [user settings](https://platform.openai.com/account/api-keys).

0 comments on commit fa72dc6

Please sign in to comment.