emiAi 0.1.0__tar.gz
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.
- emiai-0.1.0/PKG-INFO +7 -0
- emiai-0.1.0/README.md +0 -0
- emiai-0.1.0/pyproject.toml +19 -0
- emiai-0.1.0/setup.cfg +4 -0
- emiai-0.1.0/src/emiAi/__init__.py +3 -0
- emiai-0.1.0/src/emiAi/client.py +48 -0
- emiai-0.1.0/src/emiAi.egg-info/PKG-INFO +7 -0
- emiai-0.1.0/src/emiAi.egg-info/SOURCES.txt +9 -0
- emiai-0.1.0/src/emiAi.egg-info/dependency_links.txt +1 -0
- emiai-0.1.0/src/emiAi.egg-info/requires.txt +1 -0
- emiai-0.1.0/src/emiAi.egg-info/top_level.txt +1 -0
emiai-0.1.0/PKG-INFO
ADDED
emiai-0.1.0/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "emiAi"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for EmiAI API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"requests>=2.28"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.setuptools.packages.find]
|
|
16
|
+
where = ["src"]
|
|
17
|
+
|
|
18
|
+
[tool.setuptools]
|
|
19
|
+
package-dir = {"" = "src"}
|
emiai-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EmiAI:
|
|
5
|
+
def __init__(self, api_key):
|
|
6
|
+
self.api_key = api_key
|
|
7
|
+
self.url = "https://emiai.pythonanywhere.com/v1/chat/completions"
|
|
8
|
+
|
|
9
|
+
def chat(self, message):
|
|
10
|
+
response = requests.post(
|
|
11
|
+
self.url,
|
|
12
|
+
headers={
|
|
13
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"Accept": "application/json",
|
|
16
|
+
},
|
|
17
|
+
json={
|
|
18
|
+
"model": "Emi-o-mini/free",
|
|
19
|
+
"messages": [
|
|
20
|
+
{
|
|
21
|
+
"role": "user",
|
|
22
|
+
"content": message
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
timeout=60
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
data = response.json()
|
|
31
|
+
except ValueError:
|
|
32
|
+
raise Exception(
|
|
33
|
+
f"EmiAI API returned non-JSON response.\n"
|
|
34
|
+
f"HTTP Status: {response.status_code}\n"
|
|
35
|
+
f"Response:\n{response.text[:2000]}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
if response.status_code == 200:
|
|
39
|
+
try:
|
|
40
|
+
return data["choices"][0]["message"]["content"]
|
|
41
|
+
except (KeyError, IndexError, TypeError):
|
|
42
|
+
raise Exception(
|
|
43
|
+
f"Invalid EmiAI API response:\n{data}"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
raise Exception(
|
|
47
|
+
f"EmiAI API Error ({response.status_code}):\n{data}"
|
|
48
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
emiAi
|