Skip to content

Commit 24aec71

Browse files
committedDec 21, 2024
AFter many installs en INIT en CONFIG gedoe - niet werkend
1 parent 9bce29c commit 24aec71

File tree

12 files changed

+194
-45
lines changed

12 files changed

+194
-45
lines changed
 

‎agents/BuildSQLAgent.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from abc import ABC
2-
from vertexai.language_models import CodeChatModel
3-
from vertexai.generative_models import GenerativeModel, Content, Part, GenerationConfig
2+
from google.cloud import aiplatform
3+
from google.cloud import language_v1
4+
from google.cloud.aiplatform import gapic as aiplatform_gapic
5+
from google.cloud.aiplatform.language_models import CodeChatModel
6+
from google.cloud.aiplatform.language_models import CodeChatModel, Content, Part, GenerationConfig
47
from .core import Agent
58
import pandas as pd
69
import json

‎config.ini

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[CONFIG]
2-
embedding_model = vertex
2+
# The embedding_model parameter specifies the model used for embeddings.
3+
# Possible values: 'vertex', 'other_model_name'
4+
embedding_model = vertex # hard coeded in init_py
35
description_model = gemini-1.5-pro
46
vector_store = bigquery-vector
57
debugging = yes
@@ -10,7 +12,7 @@ use_session_history = yes
1012
use_column_samples = no
1113

1214
[GCP]
13-
project_id = three-p-o
15+
project_id = dp-alpha-conversational-agents
1416

1517
[PGCLOUDSQL]
1618
pg_region = us-central1

‎frontend/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
1414
gcloud services enable firebase.googleapis.com --project=$PROJECT_ID # Enable firebase management API
1515
16-
npm install -g firebase-tools
16+
17+
1718
1819
```
1920
```

‎frontend/frontend-flutter/lib/main.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ class _ContentTtmdState extends State<ContentTtmd> {
13781378

13791379
final now = DateTime.now();
13801380
dateTimeS = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
1381-
return dateTimeS!;
1381+
return dateTimeS;
13821382
}
13831383

13841384
Widget createCards(
@@ -2405,7 +2405,7 @@ class _ContentTtmdState extends State<ContentTtmd> {
24052405
print(
24062406
'Main: ttmd : importQuestions() : rowsAsListOfValues = ${rowsAsListOfValues}');
24072407

2408-
if (rowsAsListOfValues!.length < 2 ||
2408+
if (rowsAsListOfValues.length < 2 ||
24092409
rowsAsListOfValues[0].length > 4 ||
24102410
(rowsAsListOfValues[0].length <= 4 &&
24112411
(rowsAsListOfValues[0][0] != "user_grouping" ||

‎frontend/frontend-flutter/lib/screens/bot.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ class BotState extends State<Bot> with SingleTickerProviderStateMixin {
10921092
Uint8List? capturedImage = await webViewController!.takeScreenshot();
10931093

10941094
print('Bot : _generateImage() : capturedImage != null)');
1095-
_graphsImagesMap[imageId!] = capturedImage!;
1095+
_graphsImagesMap[imageId!] = capturedImage;
10961096
//ShowCapturedWidget(context, capturedImage!);
10971097

10981098
return capturedImage;
@@ -1442,7 +1442,7 @@ class BotState extends State<Bot> with SingleTickerProviderStateMixin {
14421442
pickFromJson(jsonResponseRunQuery, 'NaturalResponse').asStringOrNull();
14431443

14441444
print(
1445-
"bot() : extractContentResultsOpenDataQnA() : knownDB.length = ${knownDB!.length}; ");
1445+
"bot() : extractContentResultsOpenDataQnA() : knownDB.length = ${knownDB.length}; ");
14461446
print(
14471447
"bot() : extractContentResultsOpenDataQnA() : knownDB = ${knownDB}; ");
14481448

@@ -1471,7 +1471,7 @@ class BotState extends State<Bot> with SingleTickerProviderStateMixin {
14711471
"main: extractContentResultsOpenDataQnA() : After BlocProvider.of<UpdateStepperCubit>(context).updateStepperStatusUploaded() : run_query");
14721472

14731473
try {
1474-
if (knownDB != "[]" && error!.length == 0 ?? false) {
1474+
if (knownDB != "[]" && error.length == 0 ?? false) {
14751475
print("bot() : extractContentResults() : VALID ANSWER");
14761476
var knowDBJson = jsonDecode(knownDB);
14771477
//Check if it is worth displaying data. If just one row is returned, no use.
@@ -1507,7 +1507,7 @@ class BotState extends State<Bot> with SingleTickerProviderStateMixin {
15071507
RespList.add(knownDB);
15081508
RespList.add(isText);
15091509
RespList.add(googleChartVizRes!);
1510-
RespList.add(naturalResponseText!.trim());
1510+
RespList.add(naturalResponseText.trim());
15111511
} else {
15121512
print("bot() : extractContentResultsOpenDataQnA() : UNVALID ANSWER");
15131513
RespList.add("");
@@ -1523,7 +1523,7 @@ class BotState extends State<Bot> with SingleTickerProviderStateMixin {
15231523
RespList.add(knownDB);
15241524
RespList.add(isText);
15251525
RespList.add(googleChartVizRes!);
1526-
RespList.add(naturalResponseText!);
1526+
RespList.add(naturalResponseText);
15271527
return RespList;
15281528
}
15291529
}
@@ -1706,7 +1706,7 @@ class BotState extends State<Bot> with SingleTickerProviderStateMixin {
17061706

17071707
final now = DateTime.now();
17081708
dateTimeS = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
1709-
return dateTimeS!;
1709+
return dateTimeS;
17101710
}
17111711

17121712
List<types.Message> get messages {

‎frontend/frontend-flutter/lib/screens/settings.dart

+21-27
Original file line numberDiff line numberDiff line change
@@ -317,37 +317,31 @@ class SettingsState extends State<Settings> {
317317
TextToDocParameter.imported_questions = cfg["imported_questions"];
318318
});
319319

320-
if (TextToDocParameter.expert_mode != null
321-
) {
322-
print('Settings: importFrontEndCfgFile() : Trying to update front_end_flutter_cfg');
323-
try {
324-
widget.db
325-
.collection("${TextToDocParameter.firestore_cfg_collection}")
326-
.doc('${TextToDocParameter.userID}')
327-
.set({
328-
"endpoint_opendataqnq":
329-
"${TextToDocParameter.endpoint_opendataqnq}",
330-
"firestore_database_id":
331-
"${TextToDocParameter.firestore_database_id}",
332-
"expert_mode": TextToDocParameter.expert_mode,
333-
"anonymized_data": TextToDocParameter.anonymized_data,
334-
"firebase_app_name": "${TextToDocParameter.firebase_app_name}",
335-
"firestore_history_collection": "${TextToDocParameter.firestore_history_collection}",
336-
"firestore_cfg_collection": "${TextToDocParameter.firestore_cfg_collection}",
337-
"imported_questions": "${TextToDocParameter.imported_questions}"
338-
});
320+
print('Settings: importFrontEndCfgFile() : Trying to update front_end_flutter_cfg');
321+
try {
322+
widget.db
323+
.collection("${TextToDocParameter.firestore_cfg_collection}")
324+
.doc('${TextToDocParameter.userID}')
325+
.set({
326+
"endpoint_opendataqnq":
327+
"${TextToDocParameter.endpoint_opendataqnq}",
328+
"firestore_database_id":
329+
"${TextToDocParameter.firestore_database_id}",
330+
"expert_mode": TextToDocParameter.expert_mode,
331+
"anonymized_data": TextToDocParameter.anonymized_data,
332+
"firebase_app_name": "${TextToDocParameter.firebase_app_name}",
333+
"firestore_history_collection": "${TextToDocParameter.firestore_history_collection}",
334+
"firestore_cfg_collection": "${TextToDocParameter.firestore_cfg_collection}",
335+
"imported_questions": "${TextToDocParameter.imported_questions}"
336+
});
339337

340-
showSuccessfulUploadMsg();
338+
showSuccessfulUploadMsg();
341339

342-
} catch (e) {
343-
print('Settings: importFrontEndCfgFile() : EXCEPTION : ${e}');
344-
displayCfgUploadErrorMsg();
345-
}
346-
} else {
347-
print('Settings: importFrontEndCfgFile() : some fields if cfg are null, could not update firestore_cfg_collection');
340+
} catch (e) {
341+
print('Settings: importFrontEndCfgFile() : EXCEPTION : ${e}');
348342
displayCfgUploadErrorMsg();
349343
}
350-
}
344+
}
351345
}
352346
}
353347

‎frontend/frontend-flutter/lib/services/new_suggestions/new_suggestion_cubit.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class NewSuggestionCubit extends Cubit<NewSuggestionState> {
270270

271271
final now = DateTime.now();
272272
dateTimeS = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
273-
return dateTimeS!;
273+
return dateTimeS;
274274
}
275275

276276
List<String> pickUpNextQuestions(int scenarioNumber, String question) {

‎frontend/frontend-flutter/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1335,4 +1335,4 @@ packages:
13351335
version: "6.5.0"
13361336
sdks:
13371337
dart: ">=3.4.0 <4.0.0"
1338-
flutter: ">=3.22.0"
1338+
flutter: ">=3.27.1"

‎frontend/frontend-flutter/pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ dependencies:
6969
flutter_inappwebview: ^6.0.0
7070
cloud_firestore: ^5.4.0
7171

72+
http: any
73+
bloc: any
7274
dependency_overrides:
7375
libphonenumber_plugin: ^0.3.3
7476
libphonenumber_web: ^0.3.2

‎pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[tool.poetry]
1+
2+
exit()[tool.poetry]
23
name = "opendataqna"
34
version = "0.1.0"
45
description = ""

‎utilities/__init__ - kopie.py

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import configparser
2+
import os
3+
import sys
4+
import yaml
5+
6+
config = configparser.ConfigParser()
7+
8+
def is_root_dir():
9+
"""
10+
Checks if the current working directory is the root directory of a project
11+
by looking for either the "/notebooks" or "/agents" folders.
12+
13+
Returns:
14+
bool: True if either directory exists in the current directory, False otherwise.
15+
"""
16+
17+
current_dir = os.getcwd()
18+
print("current dir: ", current_dir)
19+
notebooks_path = os.path.join(current_dir, "notebooks")
20+
agents_path = os.path.join(current_dir, "agents")
21+
22+
return os.path.exists(notebooks_path) or os.path.exists(agents_path)
23+
24+
def load_yaml(file_path: str) -> dict:
25+
with open(file_path, "r", encoding="utf-8") as f:
26+
return yaml.safe_load(f)
27+
28+
if is_root_dir():
29+
current_dir = os.getcwd()
30+
config.read(current_dir + '/config.ini')
31+
root_dir = current_dir
32+
else:
33+
root_dir = os.path.abspath(os.path.join(os.getcwd(), '..'))
34+
config.read(root_dir+'/config.ini')
35+
36+
37+
def save_config():
38+
with open(root_dir + '/config.ini', 'w') as configfile:
39+
config.write(configfile)
40+
41+
42+
if not 'root_dir' in locals(): # If not found in any parent dir
43+
raise FileNotFoundError("config.ini not found in current or parent directories.")
44+
45+
print(f'root_dir set to: {root_dir}')
46+
47+
def format_prompt(context_prompt, **kwargs):
48+
"""
49+
Formats a context prompt by replacing placeholders with values from keyword arguments.
50+
Args:
51+
context_prompt (str): The prompt string containing placeholders (e.g., {var1}).
52+
**kwargs: Keyword arguments representing placeholder names and their values.
53+
Returns:
54+
str: The formatted prompt with placeholders replaced.
55+
"""
56+
return context_prompt.format(**kwargs)
57+
58+
59+
# Ensure that the config dictionary is properly initialized and contains the 'CONFIG' key before this line executes
60+
# Ensure that the config dictionary is properly initialized and contains the 'CONFIG' key before this line executes
61+
62+
63+
# [CONFIG]
64+
EMBEDDING_MODEL = config['CONFIG']['EMBEDDING_MODEL']
65+
DESCRIPTION_MODEL = config['CONFIG']['DESCRIPTION_MODEL']
66+
# DATA_SOURCE = config['CONFIG']['DATA_SOURCE']
67+
VECTOR_STORE = config['CONFIG']['VECTOR_STORE']
68+
69+
#CACHING = config.getboolean('CONFIG','CACHING')
70+
#DEBUGGING = config.getboolean('CONFIG','DEBUGGING')
71+
LOGGING = config.getboolean('CONFIG','LOGGING')
72+
EXAMPLES = config.getboolean('CONFIG', 'KGQ_EXAMPLES')
73+
USE_SESSION_HISTORY = config.getboolean('CONFIG', 'USE_SESSION_HISTORY')
74+
USE_COLUMN_SAMPLES = config.getboolean('CONFIG','USE_COLUMN_SAMPLES')
75+
76+
#[GCP]
77+
PROJECT_ID = config['GCP']['PROJECT_ID']
78+
79+
#[PGCLOUDSQL]
80+
PG_REGION = config['PGCLOUDSQL']['PG_REGION']
81+
# PG_SCHEMA = config['PGCLOUDSQL']['PG_SCHEMA']
82+
PG_INSTANCE = config['PGCLOUDSQL']['PG_INSTANCE']
83+
PG_DATABASE = config['PGCLOUDSQL']['PG_DATABASE']
84+
PG_USER = config['PGCLOUDSQL']['PG_USER']
85+
PG_PASSWORD = config['PGCLOUDSQL']['PG_PASSWORD']
86+
87+
#[BIGQUERY]
88+
BQ_REGION = config['BIGQUERY']['BQ_DATASET_REGION']
89+
# BQ_DATASET_NAME = config['BIGQUERY']['BQ_DATASET_NAME']
90+
BQ_OPENDATAQNA_DATASET_NAME = config['BIGQUERY']['BQ_OPENDATAQNA_DATASET_NAME']
91+
BQ_LOG_TABLE_NAME = config['BIGQUERY']['BQ_LOG_TABLE_NAME']
92+
# BQ_TABLE_LIST = config['BIGQUERY']['BQ_TABLE_LIST']
93+
94+
#[FIRESTORE]
95+
FIRESTORE_REGION = config['CONFIG']['FIRESTORE_REGION']
96+
97+
#[PROMPTS]
98+
PROMPTS = load_yaml(root_dir + '/prompts.yaml')
99+
100+
__all__ = ["EMBEDDING_MODEL",
101+
"DESCRIPTION_MODEL",
102+
#"DATA_SOURCE",
103+
"VECTOR_STORE",
104+
#"CACHING",
105+
#"DEBUGGING",
106+
"LOGGING",
107+
"EXAMPLES",
108+
"PROJECT_ID",
109+
"PG_REGION",
110+
# "PG_SCHEMA",
111+
"PG_INSTANCE",
112+
"PG_DATABASE",
113+
"PG_USER",
114+
"PG_PASSWORD",
115+
"BQ_REGION",
116+
# "BQ_DATASET_NAME",
117+
"BQ_OPENDATAQNA_DATASET_NAME",
118+
"BQ_LOG_TABLE_NAME",
119+
# "BQ_TABLE_LIST",
120+
"FIRESTORE_REGION",
121+
"PROMPTS"
122+
"root_dir",
123+
"save_config"]

‎utilities/__init__.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ def is_root_dir():
1414
bool: True if either directory exists in the current directory, False otherwise.
1515
"""
1616

17+
18+
config = configparser.ConfigParser()
19+
config.read('config.ini')
20+
21+
try:
22+
embedding_model = config['CONFIG']['EMBEDDING_MODEL']
23+
except KeyError as e:
24+
print(f"KeyError: {e} not found in the configuration file.")
25+
# Handle the missing key or section appropriately
26+
27+
28+
1729
current_dir = os.getcwd()
1830
print("current dir: ", current_dir)
1931
notebooks_path = os.path.join(current_dir, "notebooks")
@@ -33,6 +45,12 @@ def load_yaml(file_path: str) -> dict:
3345
root_dir = os.path.abspath(os.path.join(os.getcwd(), '..'))
3446
config.read(root_dir+'/config.ini')
3547

48+
49+
def save_config():
50+
with open(root_dir + '/config.ini', 'w') as configfile:
51+
config.write(configfile)
52+
53+
3654
if not 'root_dir' in locals(): # If not found in any parent dir
3755
raise FileNotFoundError("config.ini not found in current or parent directories.")
3856

@@ -49,8 +67,13 @@ def format_prompt(context_prompt, **kwargs):
4967
"""
5068
return context_prompt.format(**kwargs)
5169

70+
71+
# Ensure that the config dictionary is properly initialized and contains the 'CONFIG' key before this line executes
72+
# Ensure that the config dictionary is properly initialized and contains the 'CONFIG' key before this line executes
73+
74+
5275
# [CONFIG]
53-
EMBEDDING_MODEL = config['CONFIG']['EMBEDDING_MODEL']
76+
embedding_model = config['CONFIG']['EMBEDDING_MODEL']
5477
DESCRIPTION_MODEL = config['CONFIG']['DESCRIPTION_MODEL']
5578
# DATA_SOURCE = config['CONFIG']['DATA_SOURCE']
5679
VECTOR_STORE = config['CONFIG']['VECTOR_STORE']
@@ -109,4 +132,4 @@ def format_prompt(context_prompt, **kwargs):
109132
"FIRESTORE_REGION",
110133
"PROMPTS"
111134
"root_dir",
112-
"save_config"]
135+
"save_config"]

0 commit comments

Comments
 (0)
Please sign in to comment.