unocha / ocha_ai
OCHA AI module
Installs: 1 528
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 0
Open Issues: 0
Type:drupal-module
Requires
- php: >=8.2
- aws/aws-sdk-php: ^3.283
- drupal/core: ^10
- drupal/honeypot: ^2
- openai-php/client: ^0.7
- pear/text_languagedetect: ^1.0
- reliefweb/simple-autocomplete: ^v1.3
- reliefweb/simple-datepicker: ^v1.3
- symfony/uid: ^6.3
Requires (Dev)
- dev-develop
- v1.7.1
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-main
- dev-RW-1109
- dev-RW-1107
- dev-RW-1052
- dev-fix-bedrock-titan-premier-payload
- dev-RW-1057
- dev-fix-bedrock-payload
- dev-RW-1051
- dev-RW-1047
- dev-RW-1044-context-expansion
- dev-RW-1019-icon-fix
- dev-RW-1037
- dev-RW-1033
- dev-RW-1019-fix-php-notice
- dev-RW-1019-fix
- dev-RW-1022-logging
- dev-honeypot-service-fix
- dev-RW-1012-instructions-as-bubbles
- dev-RW-1010-ajax-progress-message-styling
- dev-RW-996
- dev-RW-944
- dev-ops-10278-ai-stats-fix
- dev-use-cache-for-embeddings
- dev-RW-931-tagger-settings
- dev-refactor-tagger-2
- dev-cafuego/config-whine
- dev-fix-text-splitter
- dev-refactor-tagger
- dev-cs1
- dev-variable-name
- dev-elasticsearch-settings
- dev-chat-form-settings
- dev-attributes
This package is auto-updated.
Last update: 2024-11-13 07:47:55 UTC
README
This module contains 2 additional modules
- OCHA AI Chat Module
- OCHA AI Tag Module
Migrate from ocha_ai_chat
- Uninstall
ocha_ai_chat
andreliefweb_openai
- Copy your
config/ocha_ai_chat.settings.yml
to a safe place - Run
druch cex -y
- Clone this repo and run
drush en ocha_ai_chat -y
- Run
druch cex -y
- Copy back your
config/ocha_ai_chat.settings.yml
to config - Run
druch cim -y
- Run
drush cr
New settings in settings/php
$config['ocha_ai.settings']['plugins']['text_extractor']['mupdf']['mutool'] = '/usr/bin/mutool'; $config['ocha_ai.settings']['plugins']['vector_store']['elasticsearch']['url'] = 'http://elasticsearch:9200'; $config['ocha_ai.settings']['plugins']['vector_store']['elasticsearch']['indexing_batch_size'] = 10; $config['ocha_ai.settings']['plugins']['vector_store']['elasticsearch']['topk'] = 5; $config['ocha_ai.settings']['plugins']['completion']['aws_bedrock']['region'] = ''; $config['ocha_ai.settings']['plugins']['completion']['aws_bedrock']['api_key'] = ''; $config['ocha_ai.settings']['plugins']['completion']['aws_bedrock']['api_secret'] = ''; $config['ocha_ai.settings']['plugins']['completion']['aws_bedrock']['model'] = 'amazon.titan-text-express-v1'; $config['ocha_ai.settings']['plugins']['completion']['aws_bedrock']['version'] = ''; $config['ocha_ai.settings']['plugins']['completion']['aws_bedrock']['max_tokens'] = 512; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['region'] = ''; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['api_key'] = ''; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['api_secret'] = ''; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['model'] = 'amazon.titan-embed-text-v1'; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['version'] = ''; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['batch_size'] = 1; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['dimensions'] = 1536; $config['ocha_ai.settings']['plugins']['embedding']['aws_bedrock']['max_tokens'] = 8192;
Plugins
The module uses a system of plugins to handle the different components of the functionality
- Completion plugins: handle the answer generation from inference models
- Embedding plugins: handle the generation of embeddings from embedding models
- Source plugins: handle the source of documents
- TextExtractor plugins: handle text extraction for files
- TextSplitter plugins: handle splitting texts into smaller ones
- VectorStore plugins: handle storage and retrieval of texts and embeddings
Dependencies
apt install mupdf-tools
TODO
Plugins
- OpenSearch vector store plugin.
OCHA AI Chat Module
This module provides a "chat" functionality to perform queries against ReliefWeb documents via AI (large language models).
This implements a RAG (retrieval augmented generation) approach:
- Get ReliefWeb documents so that we have a limited scope for the question.
- Extract texts from the documents and their attachments
- Split the texts into passages (smaller texts)
- Generate embeddings for the passages
- Store the passages and their embeddings in a vector database
- Uppon query, generate the embedding for the question
- Retrieve relevant passages from the vector store using a cosine similarity between the question embedding and the passage embeddings.
- Generate a prompt with the relevant passages, asking the AI to only answer based on the information in those passages
- Pass the prompt to a Large Language Model to get an answer to the question
Service (Chat)
The "chat" functionality is provided by the OchaAiChat service. This service glues the different plugins together.
User feedback on answers (Chat)
There are three feedback modes that visitors might see:
- Default: is an expandable area presenting a dropdown with values 1-5, plus an open textarea for comments.
- Simple mode: presents a thumbs up/down. Set config
ocha_ai_chat.settings.feedback='simple'
to adopt this UI, which replaces the default feedback UI. The data is stored in a separatethumbs
column in the logs table. - Combined mode: presents both widgets alongside each other.
Additionally, the Copy to Clipboard button can now store whether it was clicked for each answer. This data is found in the copied
column of the logs table.
TODO (Chat)
Plugins for Chat
- OpenSearch vector store plugin.
- Cache RW search conversion separately.
Improve answer
- Filter on the length of the extract (ex: at least 4 words)?
- Refine prompt, maybe separate each extract with some prefix like "Fact:" so that the AI understands they are separate pieces of information.
Logging
- Log requests (debug mode --> add setting to plugins).
- Log number of pages, passages and estimated count of tokens.
OCHA AI Tag Module
Service (tag)
The "tag" functionality is provided by the OchaAiTagTagger service. This service glues the different plugins together.