Refactor and enhance type hints across multiple modules

- Updated the `from_tuple` method in `Prof` class to specify return type.
- Added type hints for various methods in `LehmannsClient`, `OpenAI`, `WebRequest`, and `ZoteroController` classes to improve code clarity and type safety.
- Modified `pdf_to_csv` function to return a string instead of a DataFrame.
- Enhanced error handling and type hints in `wordparser` and `xmlparser` modules.
- Removed unused UI file `Ui_medianadder.ts`.
- Improved the layout and structure of the `semesterapparat_ui` to enhance user experience.
- Updated file picker to support `.doc` files in addition to `.docx`.
- Added unique item handling in `Ui` class to prevent duplicates in apparat list.
- General code cleanup and consistency improvements across various files.
This commit is contained in:
2025-10-21 09:09:54 +02:00
parent 560d8285b5
commit 0406fe4f6f
26 changed files with 437 additions and 396 deletions

View File

@@ -1,10 +1,12 @@
from openai import OpenAI
from src import settings
import json
from typing import Any
from openai import OpenAI
from src import settings
def init_client():
def init_client() -> OpenAI:
"""Initialize the OpenAI client with the API key and model from settings."""
global client, model, api_key
if not settings.openAI.api_key:
@@ -16,9 +18,11 @@ def init_client():
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) -> list[dict[str, Any]]:
client = init_client()
response = client.responses.create(
response = client.responses.create( # type: ignore
model=model,
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.
@@ -27,27 +31,28 @@ based on that, please reply only the shortened string. Give me 5 choices. if the
)
answers = response.output_text
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) -> dict:
client = init_client()
response = client.responses.create(
model = model,
response = client.responses.create( # type: ignore
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""",
input = f'{{"name":"{name}"}}'
input=f'{{"name":"{name}"}}',
)
answers = response.output_text
return json.loads(answers)
def semester_converter(semester:str):
def semester_converter(semester: str) -> str:
client = init_client()
response = client.responses.create(
model = model,
response = client.responses.create( # type: ignore
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.""",
input = semester
input=semester,
)
answers = response.output_text
return answers
return answers