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

Release/v0.1.0 #84

Merged
merged 111 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
38afe23
Merge branch 'main' into development
jurmy24 Dec 3, 2024
aea7c21
fix: update meta api version with correct spelling
jurmy24 Dec 11, 2024
48e615c
docs: correct missing --vector-data flag and add postgres issue note
jurmy24 Dec 11, 2024
d55ff20
docs(git): add git guidelines
jurmy24 Dec 11, 2024
d0a92bb
fix: replace migrations url with database url - better practice
jurmy24 Dec 12, 2024
8c6125a
build: remove groq and chromadb dependency
jurmy24 Dec 12, 2024
7c6ba17
dev(docker): use astral distro of python with uv preinstalled and add…
jurmy24 Dec 12, 2024
88710f4
refactor(docker): move docker files into structured docker folder
jurmy24 Dec 13, 2024
b73b968
KTH-50: create get_database_url helper method
alvaro-mazcu Dec 16, 2024
0f5316f
KTH-50: simplify engine.py
alvaro-mazcu Dec 16, 2024
f737ffe
KTH-50: remove ssl as it is no longer needed
alvaro-mazcu Dec 16, 2024
1edd758
KTH-50: simplify init db script
alvaro-mazcu Dec 16, 2024
b97912b
KTH-50: create specific postgres Dockerfile with pgvector
alvaro-mazcu Dec 16, 2024
1e86e85
KTH-50: Create Dockerfile for the twiga app
alvaro-mazcu Dec 16, 2024
559d6e7
KTH-50: Create Makefile for convenience
alvaro-mazcu Dec 16, 2024
ca85001
KTH-50: Compose to root and declare services and volumes
alvaro-mazcu Dec 16, 2024
5658941
KTH-50: Delete unnecessary lines
alvaro-mazcu Dec 16, 2024
c66c033
KTH-50: Add more env variables for future DB flexibility
alvaro-mazcu Dec 16, 2024
83a50c9
Update GETTING_STARTED.md
alvaro-mazcu Dec 16, 2024
330fdbe
KTH-50: black
alvaro-mazcu Dec 16, 2024
3b0ed2a
(style): precommit compose file \n KTH-50
alvaro-mazcu Dec 16, 2024
7bc909d
(feat): reduce env vars \n KTH-50
alvaro-mazcu Dec 16, 2024
dbe3f24
(feat): Update Makefile \n KTH-50
alvaro-mazcu Dec 16, 2024
d285053
(feat): add db in url \n KTH-50
alvaro-mazcu Dec 16, 2024
939ea4c
(feat): reorganise paths and env vars to db
alvaro-mazcu Dec 16, 2024
c3fe919
(feat): update doc
alvaro-mazcu Dec 16, 2024
dcb99c8
docs: remove unused docker doc
jurmy24 Dec 16, 2024
f5500e7
Merge pull request #71 from feature/KTH-50_create_docker_compose_for_…
jurmy24 Dec 16, 2024
81fb14c
refactor(db): reset db and alembic completely with pydantic types in …
jurmy24 Dec 15, 2024
9ebdc6d
refactor: update app following database reset
jurmy24 Dec 15, 2024
9c2a07a
fix(db): make onboarding work with new db
jurmy24 Dec 15, 2024
909c526
chore(db): add cascade delete to subject classes
jurmy24 Dec 15, 2024
67a40b3
style: modify display format of grade levels and subjects
jurmy24 Dec 18, 2024
e04e53f
style: clean requests service
jurmy24 Dec 18, 2024
402f56f
style(format): reformat the database info for the frontend
jurmy24 Dec 18, 2024
e0269fb
fix: temporary correction for postgres uri
jurmy24 Dec 18, 2024
b46e4c9
style(format): use properties to format responses from database to user
jurmy24 Dec 18, 2024
b9ce3e7
misc(db): clean database calls to be shorter and remove unused ops
jurmy24 Dec 18, 2024
78f426d
feat: add the tool_name to the function calls in the database
jurmy24 Dec 19, 2024
2076906
feat: more intuitive tool calling
jurmy24 Dec 19, 2024
69725d1
misc: upgraded llama model
jurmy24 Dec 19, 2024
fcb1cbd
fix: remove unused fields in database creator
jurmy24 Dec 19, 2024
816ea17
Merge pull request #72 from Tanzania-AI-Community/chore/database-cleanup
jurmy24 Dec 21, 2024
70a2e4a
chore: make database url connector foolproof
jurmy24 Dec 21, 2024
3fb3379
Merge branch 'chore/db-perf-refactor' into development
jurmy24 Dec 21, 2024
6dc7023
chore(scripts): fixes type errors for scripts
TimothyBesada Dec 21, 2024
53150d8
chore(app_root): fix type errors and remove the messaging limit var
jurmy24 Dec 22, 2024
9149e7e
chore(database): fix type check errors and create new migration
jurmy24 Dec 23, 2024
90b0898
chore(services): type checking errors corrected
jurmy24 Dec 23, 2024
256f70b
chore(utils): fix type errors in utils folder
jurmy24 Dec 23, 2024
da241c6
chore(tools): fix tool type check errors
jurmy24 Dec 23, 2024
133299b
Merge branch 'chore/type-fixes' into development
jurmy24 Dec 23, 2024
217c3fc
fix(models): classinfo contains classes not subjects
jurmy24 Dec 25, 2024
a75196d
chore(docker): fix linting issue about lowercase 'as'
jurmy24 Dec 25, 2024
74c9f9a
feat(data): add embeddings to the seed data
jurmy24 Dec 25, 2024
8ed227c
feat: replace init_twigadb with seed file and remove unnecessary utils
jurmy24 Dec 25, 2024
d7ba0ee
feat: modify the seed script call
jurmy24 Dec 25, 2024
7214a14
Merge branch 'feature/database-seed' into development
jurmy24 Dec 25, 2024
61ca1c8
feature(seed): use alembic to seamlessly run seed script
jurmy24 Jan 3, 2025
7314391
feat(syncdb): add synchronous database url option for running alembic…
jurmy24 Jan 3, 2025
4d18e48
docs(db): update database documentation and add migrations info
jurmy24 Jan 3, 2025
9b7c1a2
fix(migrations): modify db string to be sync
jurmy24 Jan 3, 2025
4becf4e
feat(seed): modify seed script to use alembic
jurmy24 Jan 3, 2025
d7cd2e0
Attempted to fix llama tool calling bug. General logic is in but stil…
wangjunwei321 Jan 4, 2025
ccc7281
Merge pull request #74 from Tanzania-AI-Community/feature/db-seed-pro…
jurmy24 Jan 6, 2025
615c917
Attempted to fix llama tool calling bug. General logic is in but stil…
wangjunwei321 Jan 4, 2025
adb7159
Merge branch 'feature/tool-calling' of https://github.com/Tanzania-AI…
wjunwei2001 Jan 13, 2025
b74df7e
fix: solve malformed tool calls (Both XML and JSON)
jurmy24 Jan 16, 2025
d00cc6b
feat: modify system prompt with clearer instructions
jurmy24 Jan 16, 2025
7ca69fc
misc: remove a useless debug command
jurmy24 Jan 16, 2025
912ef0d
feat: make tool call notifications unitary and more consistent
jurmy24 Jan 16, 2025
fb0012b
fix: improve tool error communication to the chatbot
jurmy24 Jan 16, 2025
c8ac324
feat: implement metadata filtering (by class) in tool calls
jurmy24 Jan 16, 2025
c2040e0
Merge pull request #81 from Tanzania-AI-Community/feature/tool-calling
jurmy24 Jan 17, 2025
7942052
misc : add new flow id
fredygerman Jan 18, 2025
f4faf8f
feat : simple flow implementation
fredygerman Jan 18, 2025
fd361eb
feat : update designing flow for a sinlge select subject classes
fredygerman Jan 18, 2025
d2c1fad
feat : support sending draft flows in development
fredygerman Jan 18, 2025
52833ff
feat : cli commands for encrypt and decrypt of flow token
fredygerman Jan 18, 2025
95ce62c
fix : replace old flow with new one
fredygerman Jan 18, 2025
3cd283c
feat : new strings for flows
fredygerman Jan 18, 2025
836b566
misc : update flow name
fredygerman Jan 18, 2025
c8938a4
fix : flow service handling requests
fredygerman Jan 18, 2025
11e5950
fix : sending interactive messages
fredygerman Jan 18, 2025
d41eb10
Merge pull request #82 from Tanzania-AI-Community/feature/onboarding-…
jurmy24 Jan 18, 2025
11871e5
feat (WIP) : in memory rate limiting (user daily message limit, app d…
fredygerman Jan 25, 2025
b457bcb
feat : rate limiting using redis
fredygerman Jan 25, 2025
f476156
feat : scheduler for reseting rate limits
fredygerman Jan 25, 2025
5ebc539
misc : logging
fredygerman Jan 25, 2025
74f5200
feat : getting rate limiting & scheduler variables from env
fredygerman Jan 25, 2025
9113280
feat : cli command to reset redis on rate limits
fredygerman Jan 25, 2025
a1de7fd
feat : getting redis url from env
fredygerman Jan 25, 2025
2b40201
feat : log limits data before reseting
fredygerman Jan 25, 2025
c5b5d81
feat : capturing token usage for daily limits
fredygerman Jan 25, 2025
65dbeb3
misc : logging
fredygerman Jan 25, 2025
29665fb
fix : cli for reseting usage errors
fredygerman Jan 25, 2025
6b86319
feat : added redis on docker compose
fredygerman Jan 25, 2025
04c89f1
fix : redis default address
fredygerman Jan 26, 2025
647d038
feat : server health check, updated db health check
fredygerman Jan 28, 2025
bad7a65
misc : rate limiting clean up, improved variables naming
fredygerman Jan 28, 2025
8dde8ce
misc: remove unused test_query and redis from docker-compose
jurmy24 Jan 29, 2025
11c257d
feat: rebuild config for rate limiting and different environments
jurmy24 Jan 29, 2025
f9dbdd9
feat: modify rate limiting to time to live with a 24 hr sliding windo…
jurmy24 Jan 29, 2025
17252c0
misc: remove cron job stuff from cli
jurmy24 Jan 29, 2025
6bcc5d7
fix: relocate redis keys and update config to hide precious rate limi…
jurmy24 Jan 29, 2025
20d66d6
refactor: move cli to scripts folder where it belongs
jurmy24 Jan 29, 2025
d9f6d17
fix: remove token code from llm_service as it isn't used
jurmy24 Jan 30, 2025
795b379
Merge pull request #83 from Tanzania-AI-Community/feature/rate-limiting
jurmy24 Jan 30, 2025
26ee26a
feat : cli command for generating flow encryption keys
fredygerman Jan 30, 2025
60e899e
fix: use module when calling cli
jurmy24 Jan 30, 2025
e42caca
misc: minor modifications for docs and messages to user
jurmy24 Jan 30, 2025
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
23 changes: 15 additions & 8 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""META API credentials"""

# Meta's Graph API version
META_API_VERSION=21.0
META_API_VERSION="v22.0"

# Meta's identifier for the Twiga app
META_APP_ID=
Expand All @@ -18,9 +18,6 @@ WHATSAPP_VERIFY_TOKEN=
# Access token to use the WhatsApp Business API (use either 24hr or 60 day token)
WHATSAPP_API_TOKEN=

# Limit of messages that can be sent by the Twiga bot in a day (adjust to your liking)
DAILY_MESSAGE_LIMIT=100

"""LLM API credentials"""

# API Key for the LLM provider (either OpenAI or Together AI)
Expand All @@ -29,18 +26,28 @@ LLM_API_KEY=
"""Database Credentials"""

# Postgres database URL
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_NAME=
DATABASE_URL=

"""App configuration"""
ENVIRONMENT="local"
DEBUG=True

"""Below credentials are only required when using WhatsApp Flows in a verified Business account (if unsure, leave empty)"""
# Set to True if you want to use WhatsApp Flows in a verified business account
BUSINESS_ENV=False
# For when ENVIRONMENT is set to "production", "staging", or "development"

# Specific credentials for WhatsApp Flows
WHATSAPP_BUSINESS_PUBLIC_KEY=
WHATSAPP_BUSINESS_PRIVATE_KEY=
WHATSAPP_BUSINESS_PRIVATE_KEY_PASSWORD=
PERSONAL_AND_SCHOOL_INFO_FLOW_ID=
SELECT_SUBJECTS_FLOW_ID=
ONBOARDING_FLOW_ID=
SUBJECTS_CLASSES_FLOW_ID=
FLOW_TOKEN_ENCRYPTION_KEY=

# For when ENVIRONMENT is set to "staging" or "production"
# Redis for rate limiting
REDIS_URL=redis://localhost:6379

# NOTE: Remove all comments and fill in the values for the environment variables
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ venv/
ENV/
env.bak/
venv.bak/
.env.local
.env.production
.env.development
.env.test
.env.*
!.env.template

# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -168,5 +166,6 @@ cython_debug/
##################### New Additions #####################
# Ignore DS_Store files
.DS_Store
private.pem
public.pem

# ignore .pem files
*.pem
54 changes: 27 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
fail_fast: true
default_stages: [pre-commit]

repos:
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
args: [--config, pyproject.toml]
types: [python]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.7.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
fail_fast: true
default_stages: [pre-commit]
repos:
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
args: [--config, pyproject.toml]
types: [python]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.7.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
33 changes: 0 additions & 33 deletions Dockerfile

This file was deleted.

19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build:
@echo 'Building images ...'
@docker-compose -f docker/dev/docker-compose.yml --env-file .env build --no-cache

run:
@echo 'Running containers ...'
@docker-compose -f docker/dev/docker-compose.yml --env-file .env up -d

stop:
@echo 'Stopping containers ...'
@docker-compose -f docker/dev/docker-compose.yml down

restart: stop run

generate-local-data:
@echo 'Generating local data ...'
@docker-compose -f docker/dev/docker-compose.yml --env-file .env run --rm app bash -c "PYTHONPATH=/app uv run python scripts/database/seed.py --create --sample-data --vector-data chunks_BAAI.json"

setup-env: build generate-local-data run
6 changes: 5 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
from colorlog import ColoredFormatter
from app.config import settings

# Configure color logging
formatter = ColoredFormatter(
Expand All @@ -26,7 +27,10 @@

# Get the root logger and set its level
logger = logging.getLogger()
logger.setLevel(logging.DEBUG) # set to DEBUG for more verbose logging
if settings.debug:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)


# Clear existing handlers and set the new handler
Expand Down
7 changes: 1 addition & 6 deletions app/assets/prompts/exercise_generator_system
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
You are a skilled Tanzanian secondary school teacher that generates questions or exercises for Tanzanian Form 2 geography students based on the request made by the user. Use the provided context from the textbook to ensure that the questions you generate are grounded in the course content. Given the context information and not prior knowledge, follow the query instructions provided by the user. Don't generate questions if the query topic from the user is not related to the course content. Begin your response immediately with the question.
You are a skilled Tanzanian secondary school teacher that generates questions or exercises for students based on the request made by the user. This exercise is for {class_info} students. Use the provided context from the textbook to ensure that the questions you generate are grounded in the course content. Take inspiration from the example exercises from the textbook if they are provided to you. Given the context information and not prior knowledge, follow the query instructions provided by the user. Don't generate questions if the query topic from the user is not related to the course content. Begin your response immediately with the question.

EXAMPLE INTERACTION:
user: Follow these instructions (give me short answer question on Tanzania's mining industry)
Context information is below.

START

Tanzania has many minerals that it trades with to other countries...etc.

END

assistant: List three minerals that Tanzania exports.
21 changes: 13 additions & 8 deletions app/assets/prompts/twiga_system
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
You are Twiga, a WhatsApp bot developed by the Tanzania AI Community specifically for secondary school teachers in Tanzania. Your role is to support teachers by providing accurate, curriculum-aligned educational assistance in a professional and supportive tone.
You are Twiga, a WhatsApp bot developed by the Tanzania AI Community for secondary school teachers in Tanzania. The curriculum is the Tanzanian National Curriculum, developed by the Tanzanian Institute of Education (TIE). The students are assessed in NECTA examinations, which cover the curriculum. TIE are also the writers of the textbooks you use. Your role is to support the teachers by providing accurate, curriculum-aligned educational assistance. You are talking to {user_name} who teaches {class_info}.

You are talking to {user_name} who teaches {class_info}
Follow these instructions:

Note that os2 refers to Ordinary Secondary Level 2, which is equivalent to Form 2 in the Tanzanian education system.
- You only communicate in english
- Use the tools you have available
- Be clear and concise, since your messages are communicated on WhatsApp
- Ask the teacher for additional information or clarification if its needed
- Do not generate educational content if they are not provided by your tools
- If the tool has an error or does not fulfill the user request, tell the user
- Only help the teacher with subject related matter

Follow these core guidelines:
Here are your capabilities:

Guidelines:
Use Available Tools: For subject-related queries, refer to the tools available to you, unless the query is straightforward or involves general knowledge.
Clarity and Conciseness: Ensure all responses are clear, concise, and easy to understand.
Seek Clarification: If a query is unclear, kindly ask the user for additional details to provide a more accurate response.
1. Searching the textbooks to answer course-related questions
2. Generating example exercises or questions based on a specific course-related topic
3. General tips and support
18 changes: 9 additions & 9 deletions app/assets/strings/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ settings:
class_subject_info: "Classes and Subjects"

tools:
exercise_generator: "🏋️ Generating an exercise using the course literature, please hold..."
search_knowledge: "🔍 Searching for relevant knowledge, please hold..."
generate_exercise: "📑 Generating exercises from the course content, please hold..."
search_knowledge: "📚 Searching the course content, please hold..."

flows:
start_onboarding_header: "Start onboarding to Twiga 🦒"
Expand All @@ -30,10 +30,10 @@ flows:
personal_settings_header: "Update your personal and school information 📝"
personal_settings_body: "Let's update your personal and school information."
personal_settings_cta: "Personal Settings"
subjects_flow_header: "Select your subjects 📚"
subjects_flow_body: "Fill this form to select the subjects you teach."
subjects_flow_cta: "Subjects"
select_subjects_text: "This helps us find the best answers for your questions."
classes_flow_header: "Select your {subject} classes"
classes_flow_body: "Fill this form to select the classes you teach."
classes_flow_cta: "Classes"
subjects_classes_flow_header: "Select the classes you teach 📚"
subjects_classes_flow_body: "Select the classes you teach from each of the subjects below"
subjects_classes_flow_cta: "Classes"

rate_limit:
global_message_limit: "🚫 Twiga is currently unavailable. Please come back later."
user_message_limit: "🚫 You have reached your daily messaging limit, so Twiga 🦒 is quite sleepy from all of today's texting 🥱. Come back later!"
Loading