edi-core 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of edi-core might be problematic. Click here for more details.

edi_core/__init__.py ADDED
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ WRITESONIC_BASE_URL = 'https://api.writesonic.com'
2
+ CHATSONIC_URL_PATH = '/v2/business/content/chatsonic'
3
+ WRITESONIC_ENGINE_PREMIUM = 'premium'
4
+ WRITESONIC_ENGINE_SUPERIUM = 'superium'
5
+ WRITESONIC_ENGINES = (WRITESONIC_ENGINE_PREMIUM, WRITESONIC_ENGINE_SUPERIUM)
6
+ WRITESONIC_LANGUAGE_ENGLISH = 'en'
7
+ WRITESONIC_LANGUAGE_CHINESE = 'zh'
8
+ WRITESONIC_LANGUAGES = (WRITESONIC_LANGUAGE_ENGLISH, WRITESONIC_LANGUAGE_CHINESE)
@@ -0,0 +1,108 @@
1
+ import json
2
+ import os
3
+ from dataclasses import dataclass, field
4
+ from typing import List
5
+
6
+ import requests
7
+ from edi_core.ai.writesonic import *
8
+
9
+
10
+ @dataclass(kw_only=True)
11
+ class ChatSonicConfig:
12
+ api_key: str = os.environ.get("SONIC_KEY")
13
+ base_url: str = WRITESONIC_BASE_URL
14
+ path: str = CHATSONIC_URL_PATH
15
+ engine: str = WRITESONIC_ENGINE_PREMIUM
16
+ language: str = WRITESONIC_LANGUAGE_ENGLISH
17
+ enable_memory: bool = False
18
+ enable_google_results: bool = False
19
+
20
+ def __post_init__(self):
21
+ if not self.api_key:
22
+ raise ValueError("token is required")
23
+ if self.engine not in WRITESONIC_ENGINES:
24
+ raise ValueError("engine is invalid")
25
+ if self.language not in WRITESONIC_LANGUAGES:
26
+ raise ValueError("language is invalid")
27
+
28
+ def get_request_url(self):
29
+ return f'{self.base_url}{self.path}'
30
+
31
+
32
+ @dataclass
33
+ class ChatSonicPayload:
34
+ @dataclass
35
+ class Message:
36
+ is_sent: bool
37
+ message: str
38
+
39
+ input_text: str
40
+ history_data: List[Message] = field(default_factory=list)
41
+ enable_memory: bool = False
42
+ enable_google_results: bool = False
43
+
44
+ def push_response(self, message: str):
45
+ message_sent = self.Message(is_sent=True, message=self.input_text)
46
+ message_received = self.Message(is_sent=False, message=message)
47
+ self.history_data.append(message_sent)
48
+ self.history_data.append(message_received)
49
+ self.input_text = ''
50
+
51
+ def set_config(self, config: ChatSonicConfig):
52
+ self.enable_memory = config.enable_memory
53
+ self.enable_google_results = config.enable_google_results
54
+
55
+ def to_json(self):
56
+ return json.dumps(self.__dict__)
57
+
58
+
59
+ @dataclass
60
+ class ChatSonicResponse:
61
+ message: str
62
+ image_urls: List[str] = field(default_factory=list)
63
+
64
+ @staticmethod
65
+ def from_json(json_data):
66
+ return ChatSonicResponse(
67
+ message=json_data['message'],
68
+ image_urls=json_data['image_urls']
69
+ )
70
+
71
+
72
+ class ChatSonic:
73
+ _config: ChatSonicConfig
74
+ _session = requests.Session()
75
+
76
+ def __init__(self, config: ChatSonicConfig):
77
+ self._config = config
78
+
79
+ def call(self, payload: ChatSonicPayload) -> (ChatSonicResponse, ChatSonicPayload):
80
+ url = self._config.get_request_url()
81
+
82
+ raw_response = self._session.post(
83
+ url=url,
84
+ headers=self.get_request_headers(),
85
+ params=self.get_request_params(),
86
+ data=payload.to_json()
87
+ )
88
+
89
+ raw_response.raise_for_status()
90
+
91
+ response = ChatSonicResponse.from_json(raw_response.json())
92
+ payload.push_response(response.message)
93
+
94
+ return response, payload
95
+
96
+ def chat(self, message: str) -> ChatSonicPayload:
97
+ payload = ChatSonicPayload(input_text=message);
98
+ payload.set_config(self._config)
99
+ return self.call(payload)
100
+
101
+ def get_request_headers(self):
102
+ return {'X-API-KEY': self._config.api_key}
103
+
104
+ def get_request_params(self):
105
+ return {
106
+ 'engine': self._config.engine,
107
+ 'language': self._config.language
108
+ }
File without changes
@@ -0,0 +1,25 @@
1
+ directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
2
+
3
+
4
+ class SliderPuzzle:
5
+
6
+ def solve(self):
7
+ return
8
+
9
+
10
+ class SearchNode:
11
+ board: list
12
+ free: tuple
13
+
14
+ step: 0
15
+
16
+ def get_distance(self):
17
+ distance = 0
18
+ for i in range(len(self.board)):
19
+ for j in range(len(self.board[i])):
20
+ if self.board[i][j] != i * len(self.board[i]) + j + 1:
21
+ distance += abs(i - (self.board[i][j] - 1) // len(self.board[i])) + abs(
22
+ j - (self.board[i][j] - 1) % len(self.board[i]))
23
+ return distance + self.step
24
+
25
+
File without changes
@@ -0,0 +1,5 @@
1
+ import pyautogui
2
+
3
+
4
+ def write(text: str, interval: float = 0.1):
5
+ pyautogui.write(text, interval)
File without changes
File without changes
File without changes
edi_core/db/tinydb.py ADDED
@@ -0,0 +1,23 @@
1
+ from typing import List
2
+
3
+ from tinydb import TinyDB
4
+ from tinydb.table import Document
5
+
6
+
7
+ class Tiny:
8
+ _db = None
9
+
10
+ def __init__(self, db_file):
11
+ self._db = TinyDB(db_file)
12
+
13
+ def insert(self, data: dict) -> int:
14
+ return self._db.insert(data)
15
+
16
+ def all(self) -> List[Document]:
17
+ return self._db.all()
18
+
19
+ def search(self, query) -> List[Document]:
20
+ return self._db.search(query)
21
+
22
+ def close(self):
23
+ self._db.close()
File without changes
edi_core/file/file.py ADDED
@@ -0,0 +1,19 @@
1
+ import os.path
2
+ import shutil
3
+
4
+
5
+ def isdir(path: str) -> bool:
6
+ return os.path.isdir(path)
7
+
8
+
9
+ def isfile(path: str) -> bool:
10
+ return os.path.isfile(path)
11
+
12
+
13
+ def move(src, dest):
14
+ shutil.move(src, dest)
15
+
16
+
17
+ def delete_file(path: str):
18
+ if isfile(path):
19
+ os.remove(path)
@@ -0,0 +1,5 @@
1
+ import filetype
2
+
3
+
4
+ def guess_mime(file):
5
+ return filetype.guess_mime(file)
edi_core/file/hash.py ADDED
@@ -0,0 +1,9 @@
1
+ import hashlib
2
+
3
+ algorithms_available = hashlib.algorithms_available
4
+
5
+
6
+ def hash_str(data: str, algo='md5') -> str:
7
+ h = hashlib.new(algo)
8
+ h.update(data.encode('utf-8'))
9
+ return h.hexdigest()
File without changes
@@ -0,0 +1,15 @@
1
+ import toml
2
+
3
+
4
+ def parse_toml_file(toml_file_path: str) -> dict:
5
+ with open(toml_file_path, 'r') as file:
6
+ return toml.load(file)
7
+
8
+
9
+ def parse_toml_str(toml_str: str) -> dict:
10
+ return toml.loads(toml_str)
11
+
12
+
13
+ def save_to_toml_file(path: str, data: dict):
14
+ with open(path, 'w') as file:
15
+ toml.dump(data, file)
File without changes
@@ -0,0 +1,6 @@
1
+ import pendulum
2
+ from pendulum import DateTime
3
+
4
+
5
+ def now(tz='Asia/Shanghai') -> DateTime:
6
+ return pendulum.now(tz)
@@ -0,0 +1,13 @@
1
+ import platform
2
+
3
+
4
+ def get_platform():
5
+ return platform.platform()
6
+
7
+
8
+ def get_system():
9
+ return platform.system()
10
+
11
+
12
+ def is_windows():
13
+ return get_system() == 'Windows'
@@ -0,0 +1,13 @@
1
+ from typing import Dict, Any
2
+
3
+ from edi_core.parser.toml_parser import parse_toml_file
4
+
5
+
6
+ class PyProject:
7
+ _root: str
8
+ _config: Dict[str, Any]
9
+ _config_file_name = "pyproject.toml"
10
+
11
+ def __init__(self, path: str):
12
+ self.path = path
13
+ self._config = parse_toml_file(f'{path}/{self._config_file_name}')
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.1
2
+ Name: edi-core
3
+ Version: 0.3.0
4
+ Summary:
5
+ License: MIT
6
+ Author: LtttAZ
7
+ Author-email: louis_zhang_1303@126.com
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Requires-Dist: dataclass-wizard (>=0.22.3,<0.23.0)
14
+ Requires-Dist: filetype (>=1.2.0,<2.0.0)
15
+ Requires-Dist: matplotlib (>=3.8.4,<4.0.0)
16
+ Requires-Dist: pendulum (>=3.0.0,<4.0.0)
17
+ Requires-Dist: pyautogui (>=0.9.54,<0.10.0)
18
+ Requires-Dist: pytest (>=8.1.1,<9.0.0)
19
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
20
+ Requires-Dist: requests-mock (>=1.12.1,<2.0.0)
21
+ Requires-Dist: tinydb (>=4.8.0,<5.0.0)
22
+ Requires-Dist: toml (>=0.10.2,<0.11.0)
23
+ Requires-Dist: tomlkit (>=0.13.0,<0.14.0)
24
+ Description-Content-Type: text/markdown
25
+
26
+ # EDI
27
+
28
+
@@ -0,0 +1,25 @@
1
+ edi_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ edi_core/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ edi_core/ai/writesonic/__init__.py,sha256=QCibWjBh4QqvUeJUscjByC-zHd__21J6jfTPJcWJxO8,412
4
+ edi_core/ai/writesonic/chatsonic.py,sha256=cmV1445v6cnvxY3kSkU5uLyLcPCHjWhvpEQ6zbfR9ug,3098
5
+ edi_core/algo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ edi_core/algo/silder_puzzle.py,sha256=lyPvnL32VAsTghrz2WBsPMPJqnMeFxbBgSt4khfPNVI,586
7
+ edi_core/auto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ edi_core/auto/control.py,sha256=W8JROSAAc900qUWNlCIQV9BikqeAtEycOXxA_7Eimqc,100
9
+ edi_core/cloud/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ edi_core/cloud/aliyun.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ edi_core/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ edi_core/db/tinydb.py,sha256=DB8trZcsxsLPSwlQjJemlOs68F4AcEMJJmyK0x7BXg0,463
13
+ edi_core/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ edi_core/file/file.py,sha256=VoydbmagVOSkE8EnJl8TpBckM7go_ayfjfz_pBVNfvU,282
15
+ edi_core/file/filetype.py,sha256=yfGavZWzMkbmRUeYPFySZ7xVd1olbeCBc7oQVOMvtCE,77
16
+ edi_core/file/hash.py,sha256=9YRLLDbPdTlZok6zGKfCLmDL9wXUpYVyHcTgz1Gt0Yc,200
17
+ edi_core/parser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ edi_core/parser/toml_parser.py,sha256=ll7RXZQsw68hx--PbtLR5kNh-52sOjq5m7x_XDmJAhI,328
19
+ edi_core/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ edi_core/util/datetime.py,sha256=sctJzZw_Uruq-qp6IW_JuqZvcJq_fXDbTMpfEwkAPlg,117
21
+ edi_core/util/environment.py,sha256=rQmkKN5TWuhe-2NNGirQCeVW95dLz27pjeYDsB5yIII,175
22
+ edi_core/util/pyproject.py,sha256=3mdC-a6rqx9zlZUHeGyDIjz0EcT_TmTINRKLxYRvIac,325
23
+ edi_core-0.3.0.dist-info/METADATA,sha256=8vjVJGMonLuydRI4BB26XNrfgfVkDwRBDvPLnAQ4IH0,876
24
+ edi_core-0.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
25
+ edi_core-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any