Skip to content

Commit d31278e

Browse files
authored
Merge pull request #174 from bettersg/stg
Stg
2 parents f20b68e + 10ccd86 commit d31278e

File tree

16 files changed

+9031
-3454
lines changed

16 files changed

+9031
-3454
lines changed

.github/workflows/deploy_functions_dev.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
# Step 1: Checkout the code
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4 # Updated to v4 for better compatibility
1818

19-
# Step 1.5: Environment variables
20-
- name: create env file
21-
working-directory: backend
19+
# Step 1.5: Environment variables
20+
- name: Create env file
21+
working-directory: backend/functions
2222
run: |
23-
cd functions
2423
touch .env
2524
echo "${{ secrets.FUNCTIONS_ENV_VARS }}" >> .env
2625
@@ -32,9 +31,9 @@ jobs:
3231

3332
# Step 3: Set up Node.js environment
3433
- name: Set up Node
35-
uses: actions/setup-node@v3
34+
uses: actions/setup-node@v4 # Updated to v4
3635
with:
37-
node-version: 19.7.0
36+
node-version: '20' # Upgraded to 20 to meet firebase-tools@14.2.0 requirements
3837

3938
# Step 3.5: Download the ZIP file from Google Drive
4039
- name: Download Models ZIP
@@ -58,7 +57,7 @@ jobs:
5857
# Step 4: Create Service Account Key and Set Env Variables
5958
- name: Create SA key and set env variables
6059
run: |
61-
echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCHEMESSG_V3_DEV }}' > ${{ runner.temp }}/gcloud.json
60+
echo "${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCHEMESSG_V3_DEV }}" > ${{ runner.temp }}/gcloud.json
6261
echo "GOOGLE_APPLICATION_CREDENTIALS=${{ runner.temp }}/gcloud.json" >> $GITHUB_ENV
6362
6463
# Step 5: Prepare the environment
@@ -69,8 +68,10 @@ jobs:
6968
. venv/bin/activate
7069
npx firebase-tools --version
7170
python3.10 -m pip install -r requirements.txt
71+
npm install -g firebase-tools@14.2.0 # Install firebase-tools globally
72+
npx firebase-tools --version # Verify version
7273
73-
# Step 6: deploy functions
74+
# Step 6: Deploy functions
7475
- name: Deploy functions
7576
working-directory: backend
7677
env:

.github/workflows/firebase-hosting-staging.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This file was auto-generated by the Firebase CLI
2-
# https://github.com/firebase/firebase-tools
3-
41
name: Deploy Frontend to Firebase Hosting
52
on:
63
push:
@@ -17,9 +14,9 @@ jobs:
1714
steps:
1815
- uses: actions/checkout@v4
1916
- name: Use Node.js
20-
uses: actions/setup-node@v3
17+
uses: actions/setup-node@v4 # Updated to v4
2118
with:
22-
node-version: "18"
19+
node-version: "20"
2320
- name: Cache dependencies
2421
uses: actions/cache@v3
2522
with:
@@ -43,14 +40,13 @@ jobs:
4340
run: |
4441
cd frontend
4542
npm ci
46-
npm install sharp
4743
npm run build
4844
- name: Debug Variables
4945
run: |
50-
echo "Using vars context: ${{ vars.NEXT_PUBLIC_API_BASE_URL }}"
51-
echo "Current branch: ${{ github.ref_name }}"
52-
echo "All environment variables:"
53-
env
46+
echo "Using vars context: ${{ vars.NEXT_PUBLIC_API_BASE_URL }}"
47+
echo "Current branch: ${{ github.ref_name }}"
48+
echo "All environment variables:"
49+
env
5450
- uses: FirebaseExtended/action-hosting-deploy@v0
5551
with:
5652
repoToken: ${{ secrets.GITHUB_TOKEN }}
@@ -65,4 +61,4 @@ jobs:
6561
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: ${{ vars.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}
6662
NEXT_PUBLIC_FB_API_KEY: ${{ vars.NEXT_PUBLIC_FB_API_KEY }}
6763
NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{ vars.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}
68-
NEXT_PUBLIC_FIREBASE_APP_ID: ${{ vars.NEXT_PUBLIC_FIREBASE_APP_ID }}
64+
NEXT_PUBLIC_FIREBASE_APP_ID: ${{ vars.NEXT_PUBLIC_FIREBASE_APP_ID }}

backend/functions/ml_logic/chatbotManager.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,21 @@ def dataframe_to_text(df: pd.DataFrame) -> str:
6363
"""
6464
text_summary = ""
6565
for _, row in df.iterrows():
66-
cleanScrape = row["scraped_text"]
67-
sentence = clean_scraped_text(cleanScrape)
68-
69-
text_summary += f"Scheme Name: {row['Scheme']}, Agency: {row['Agency']}, Description: {row['Description']}, Link: {row['Link']}, Scraped Text from website: {sentence}\n"
66+
# Handle both uppercase and lowercase column names
67+
scheme = row.get("scheme", "")
68+
agency = row.get("agency", "")
69+
description = row.get("description", "")
70+
link = row.get("link", "")
71+
phone = row.get("phone", "")
72+
address = row.get("address", "")
73+
eligibility = row.get("eligibility", "")
74+
email = row.get("email", "")
75+
how_to_apply = row.get("how_to_apply", "")
76+
scraped_text = row.get("scraped_text", "")
77+
78+
sentence = clean_scraped_text(scraped_text)
79+
80+
text_summary += f"Scheme Name: {scheme}, Agency: {agency}, Phone: {phone}, Address: {address}, Eligibility: {eligibility}, Email: {email}, How to Apply: {how_to_apply}, Description: {description}, Link: {link}, Scraped Text from website: {sentence}\n"
7081
return text_summary
7182

7283

@@ -123,7 +134,7 @@ def initialise(cls):
123134
top_p=0.9,
124135
presence_penalty=0.2,
125136
frequency_penalty=0.2,
126-
max_tokens=512
137+
max_tokens=512,
127138
)
128139
logger.info("Chatbot initialised")
129140
except Exception as e: # TODO: logger
@@ -272,7 +283,6 @@ def chatbot(
272283

273284
template_text = system_instructions + top_schemes_text + "<END OF SCHEMES RESULTS>"
274285

275-
276286
prompt_template = ChatPromptTemplate.from_messages(
277287
[
278288
("system", template_text),
@@ -369,7 +379,6 @@ def chatbot_stream(self, top_schemes_text: str, input_text: str, session_id: str
369379

370380
template_text = system_instructions + top_schemes_text + "<END OF SCHEMES RESULTS>"
371381

372-
373382
prompt_template = ChatPromptTemplate.from_messages(
374383
[
375384
("system", template_text),

backend/functions/ml_logic/searchModelManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def combine_and_aggregate_results(
322322

323323
# Drop duplicates and sort by similarity
324324
aggregated_results = combined_results.sort_values("Similarity", ascending=False).drop_duplicates(
325-
subset=["Scheme"]
325+
subset=["scheme"]
326326
)
327327

328328
# Filter by similarity threshold

0 commit comments

Comments
 (0)