refactor: update configuration handling and OpenAI client initialization
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
[tool.bumpversion]
|
|
||||||
current_version = "0.2.1"
|
|
||||||
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
|
||||||
serialize = ["{major}.{minor}.{patch}"]
|
|
||||||
search = "{current_version}"
|
|
||||||
replace = "{new_version}"
|
|
||||||
regex = false
|
|
||||||
ignore_missing_version = false
|
|
||||||
ignore_missing_files = false
|
|
||||||
tag = true
|
|
||||||
sign_tags = false
|
|
||||||
tag_name = "v{new_version}"
|
|
||||||
tag_message = "Bump version: {current_version} → {new_version}"
|
|
||||||
allow_dirty = false
|
|
||||||
commit = true
|
|
||||||
message = "Bump version: {current_version} → {new_version}"
|
|
||||||
commit_args = ""
|
|
||||||
setup_hooks = []
|
|
||||||
pre_commit_hooks = []
|
|
||||||
post_commit_hooks = []
|
|
||||||
[[tool.bumpversion.files]]
|
|
||||||
filename = "src/__init__.py"
|
|
||||||
@@ -149,7 +149,14 @@ class Config:
|
|||||||
FileNotFoundError: Configuration file not found
|
FileNotFoundError: Configuration file not found
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(config_path):
|
if not os.path.exists(config_path):
|
||||||
raise FileNotFoundError(f"Configuration file not found: {config_path}")
|
# copy base config file to the given path
|
||||||
|
base = "config/base_config.yaml"
|
||||||
|
if not os.path.exists(base):
|
||||||
|
raise FileNotFoundError(f"Base configuration file not found: {base}")
|
||||||
|
with open(base, "r") as base_file:
|
||||||
|
base_config = base_file.read()
|
||||||
|
with open(config_path, "w") as config_file:
|
||||||
|
config_file.write(base_config)
|
||||||
self._config = OmegaConf.load(config_path)
|
self._config = OmegaConf.load(config_path)
|
||||||
self.config_path = config_path
|
self.config_path = config_path
|
||||||
|
|
||||||
|
|||||||
@@ -35,3 +35,29 @@ dev = [
|
|||||||
"icecream>=2.1.4",
|
"icecream>=2.1.4",
|
||||||
"nuitka>=2.5.9",
|
"nuitka>=2.5.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.bumpversion]
|
||||||
|
current_version = "0.1.0"
|
||||||
|
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
|
||||||
|
serialize = ["{major}.{minor}.{patch}"]
|
||||||
|
search = "{current_version}"
|
||||||
|
replace = "{new_version}"
|
||||||
|
regex = false
|
||||||
|
ignore_missing_version = false
|
||||||
|
ignore_missing_files = false
|
||||||
|
tag = false
|
||||||
|
sign_tags = false
|
||||||
|
tag_name = "v{new_version}"
|
||||||
|
tag_message = "Bump version: {current_version} → {new_version}"
|
||||||
|
allow_dirty = false
|
||||||
|
commit = false
|
||||||
|
message = "Bump version: {current_version} → {new_version}"
|
||||||
|
moveable_tags = []
|
||||||
|
commit_args = ""
|
||||||
|
setup_hooks = []
|
||||||
|
pre_commit_hooks = []
|
||||||
|
post_commit_hooks = []
|
||||||
|
[[tool.bumpversion.files]]
|
||||||
|
filename = "src/__init__.py"
|
||||||
|
[[tool.bumpversion.files]]
|
||||||
|
filename = ".version"
|
||||||
@@ -15,7 +15,7 @@ if not os.path.exists(CONFIG_DIR):
|
|||||||
os.makedirs(CONFIG_DIR)
|
os.makedirs(CONFIG_DIR)
|
||||||
|
|
||||||
|
|
||||||
settings = Config("config/config.yaml")
|
settings = Config(f"{CONFIG_DIR}/config.yaml")
|
||||||
if not os.path.exists(settings.database.temp.expanduser()):
|
if not os.path.exists(settings.database.temp.expanduser()):
|
||||||
settings.database.temp.expanduser().mkdir(parents=True, exist_ok=True)
|
settings.database.temp.expanduser().mkdir(parents=True, exist_ok=True)
|
||||||
from .utils.icon import Icon
|
from .utils.icon import Icon
|
||||||
|
|||||||
@@ -1,28 +1,37 @@
|
|||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from src import settings
|
from src import settings
|
||||||
import json
|
import json
|
||||||
from src import LOG_DIR
|
|
||||||
|
|
||||||
model = settings.openAI.model
|
|
||||||
api_key = settings.openAI.api_key
|
|
||||||
client = OpenAI(api_key = api_key)
|
|
||||||
|
|
||||||
|
|
||||||
|
def init_client():
|
||||||
|
"""Initialize the OpenAI client with the API key and model from settings."""
|
||||||
|
global client, model, api_key
|
||||||
|
if not settings.openAI.api_key:
|
||||||
|
raise ValueError("OpenAI API key is not set in the configuration.")
|
||||||
|
if not settings.openAI.model:
|
||||||
|
raise ValueError("OpenAI model is not set in the configuration.")
|
||||||
|
|
||||||
|
model = settings.openAI.model
|
||||||
|
api_key = settings.openAI.api_key
|
||||||
|
client = OpenAI(api_key=api_key)
|
||||||
|
return client
|
||||||
def run_shortener(title:str, length:int):
|
def run_shortener(title:str, length:int):
|
||||||
|
client = init_client()
|
||||||
response = client.responses.create(
|
response = client.responses.create(
|
||||||
model = model,
|
model=model,
|
||||||
instructions = """you are a sentence shortener. The next message will contain the string to shorten and the length limit.
|
instructions="""you are a sentence shortener. The next message will contain the string to shorten and the length limit.
|
||||||
You need to shorten the string to be under the length limit, while keeping as much detail as possible. The result may NOT be longer than the length limit.
|
You need to shorten the string to be under the length limit, while keeping as much detail as possible. The result may NOT be longer than the length limit.
|
||||||
based on that, please reply only the shortened string. Give me 5 choices. if the length is too long, discard the string and try another one.Return the data as a python list containing the result as {"shortened_string": shortened_string, "length": lengthasInt}. Do not return the answer in a codeblock, use a pure string. Before answering, check the results and if ANY is longer than the needed_length, discard all and try again""",
|
based on that, please reply only the shortened string. Give me 5 choices. if the length is too long, discard the string and try another one.Return the data as a python list containing the result as {"shortened_string": shortened_string, "length": lengthasInt}. Do not return the answer in a codeblock, use a pure string. Before answering, check the results and if ANY is longer than the needed_length, discard all and try again""",
|
||||||
input = f'{{"string":"{title}", "needed_length":{length}}}'
|
input=f'{{"string":"{title}", "needed_length":{length}}}',
|
||||||
)
|
)
|
||||||
print(length)
|
|
||||||
answers = response.output_text
|
answers = response.output_text
|
||||||
print(answers)
|
|
||||||
return eval(answers) # type: ignore
|
return eval(answers) # type: ignore
|
||||||
#answers are strings in json format, so we need to convert them to a list of dicts
|
#answers are strings in json format, so we need to convert them to a list of dicts
|
||||||
|
|
||||||
|
|
||||||
def name_tester(name: str):
|
def name_tester(name: str):
|
||||||
|
client = init_client()
|
||||||
response = client.responses.create(
|
response = client.responses.create(
|
||||||
model = model,
|
model = model,
|
||||||
instructions="""you are a name tester, You are given a name and will have to split the name into first name, last name, and if present the title. Return the name in a json format with the keys "title", "first_name", "last_name". If no title is present, set title to none. Do NOt return the answer in a codeblock, use a pure json string. Assume the names are in the usual german naming scheme""",
|
instructions="""you are a name tester, You are given a name and will have to split the name into first name, last name, and if present the title. Return the name in a json format with the keys "title", "first_name", "last_name". If no title is present, set title to none. Do NOt return the answer in a codeblock, use a pure json string. Assume the names are in the usual german naming scheme""",
|
||||||
@@ -33,6 +42,7 @@ def name_tester(name: str):
|
|||||||
return json.loads(answers)
|
return json.loads(answers)
|
||||||
|
|
||||||
def semester_converter(semester:str):
|
def semester_converter(semester:str):
|
||||||
|
client = init_client()
|
||||||
response = client.responses.create(
|
response = client.responses.create(
|
||||||
model = model,
|
model = model,
|
||||||
instructions="""you are a semester converter. You will be given a string. Convert this into a string like this: SoSe YY or WiSe YY/YY+1. Do not return the answer in a codeblock, use a pure string.""",
|
instructions="""you are a semester converter. You will be given a string. Convert this into a string like this: SoSe YY or WiSe YY/YY+1. Do not return the answer in a codeblock, use a pure string.""",
|
||||||
|
|||||||
@@ -160,6 +160,8 @@ class ZoteroController:
|
|||||||
zoterocfg = settings.zotero
|
zoterocfg = settings.zotero
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
if self.zoterocfg.library_id is None:
|
||||||
|
return
|
||||||
self.zot = zotero.Zotero(
|
self.zot = zotero.Zotero(
|
||||||
self.zoterocfg.library_id,
|
self.zoterocfg.library_id,
|
||||||
self.zoterocfg.library_type,
|
self.zoterocfg.library_type,
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
from PyQt6 import QtWidgets, QtCore
|
import sys
|
||||||
from PyQt6.QtCore import QDate
|
|
||||||
from PyQt6.QtGui import QColor, QPen
|
|
||||||
from src.backend import Database
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import darkdetect
|
import darkdetect
|
||||||
import loguru
|
import loguru
|
||||||
import sys
|
from PyQt6 import QtCore, QtWidgets
|
||||||
|
from PyQt6.QtCore import QDate
|
||||||
|
from PyQt6.QtGui import QColor, QPen
|
||||||
|
|
||||||
from src import LOG_DIR
|
from src import LOG_DIR
|
||||||
|
from src.backend import Database
|
||||||
|
|
||||||
log = loguru.logger
|
log = loguru.logger
|
||||||
log.remove()
|
log.remove()
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import random
|
import random
|
||||||
from typing import Union, Any
|
import sys
|
||||||
|
from typing import Any, Union
|
||||||
|
|
||||||
|
import loguru
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from PyQt6 import QtWidgets
|
from PyQt6 import QtWidgets
|
||||||
import loguru
|
|
||||||
import sys
|
|
||||||
from src import LOG_DIR
|
from src import LOG_DIR
|
||||||
|
|
||||||
log = loguru.logger
|
log = loguru.logger
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
from .widget_sources.search_statistic_page_ui import Ui_Dialog
|
|
||||||
from PyQt6 import QtWidgets, QtGui, QtCore
|
|
||||||
from PyQt6.QtCore import pyqtSignal
|
|
||||||
from src.backend import Database, Semester
|
|
||||||
|
|
||||||
from src.logic import custom_sort, Prof, sort_semesters_list
|
|
||||||
from src.ui.dialogs import Mail_Dialog, ApparatExtendDialog, ReminderDialog
|
|
||||||
from src.ui.widgets import DataGraph, StatusWidget
|
|
||||||
from src import LOG_DIR
|
|
||||||
from natsort import natsorted
|
|
||||||
import loguru
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import loguru
|
||||||
|
from natsort import natsorted
|
||||||
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
|
from PyQt6.QtCore import pyqtSignal
|
||||||
|
|
||||||
|
from src import LOG_DIR
|
||||||
|
from src.backend import Database, Semester
|
||||||
|
from src.logic import Prof, custom_sort, sort_semesters_list
|
||||||
|
from src.ui.dialogs import ApparatExtendDialog, Mail_Dialog, ReminderDialog
|
||||||
|
from src.ui.widgets import DataGraph, StatusWidget
|
||||||
|
|
||||||
|
from .widget_sources.search_statistic_page_ui import Ui_Dialog
|
||||||
|
|
||||||
log = loguru.logger
|
log = loguru.logger
|
||||||
log.remove()
|
log.remove()
|
||||||
log.add(sys.stdout, level="INFO")
|
log.add(sys.stdout, level="INFO")
|
||||||
|
|||||||
Reference in New Issue
Block a user