-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add import of args module in __init__.py
refactor(config): streamline argparse setup in args.py feat(config): add new command line argument for file input in args.py refactor(config): update constants with new system content description feat(main): integrate argument parsing and dynamic user content handling feat(main): add new payload creation function for POST requests feat(models): add new LMStudioChatResponse data model feat(utils): implement utility function to read file content
- Loading branch information
Showing
8 changed files
with
168 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .args import * | ||
from .constants import * | ||
from .enviornment_setup import * | ||
from .setup_logging import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .lm_studio_chat_completion import * |
54 changes: 54 additions & 0 deletions
54
filename_suggestion_ai/models/lm_studio_chat_completion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass, field | ||
from typing import Optional, Union | ||
|
||
|
||
@dataclass | ||
class Message: | ||
role: str | ||
content: str | ||
|
||
|
||
@dataclass | ||
class Choice: | ||
index: int | ||
message: Message | ||
finish_reason: str | ||
logprobs: dict | None = None | ||
|
||
|
||
@dataclass | ||
class Usage: | ||
prompt_tokens: int | ||
completion_tokens: int | ||
total_tokens: int | ||
|
||
|
||
@dataclass | ||
class LMStudioChatResponse: | ||
""" | ||
LM Studio chat response. | ||
See https://platform.openai.com/docs/api-reference/chat/create | ||
See https://lmstudio.ai/docs/local-server | ||
""" | ||
|
||
id: str | ||
object: str | ||
created: int | ||
model: str | ||
choices: list[Choice] | ||
usage: Usage | ||
system_fingerprint: str | ||
|
||
def __getitem__(self, key: str | int) -> LMStudioChatResponse: | ||
# if isinstance(key, int): | ||
# Assuming integer keys are for accessing choices list | ||
# return self.choices[key] | ||
if isinstance(key, str): | ||
# String keys for attribute access | ||
return getattr(self, key) | ||
else: | ||
msg = "Key must be either an integer or a string" | ||
raise TypeError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .file_util import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
|
||
def read_file_content(file_path: Path) -> str | None: | ||
""" | ||
Reads the content of a file and returns it as a string. | ||
Args: | ||
file_path (Path): The path to the file to be read. | ||
Returns: | ||
Optional[str]: The content of the file as a string, or None if an error occurs. | ||
""" | ||
try: | ||
with file_path.open("r") as file: | ||
return file.read().replace("\n", "\\n") | ||
except FileNotFoundError: | ||
logging.exception("File not found: %s", file_path) | ||
except OSError as e: | ||
logging.exception(f"I/O error({e.errno}): {e.strerror}") | ||
except Exception: | ||
logging.exception("An unexpected error occurred while reading the file") | ||
return None |