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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### Linux template
|
2 |
+
*~
|
3 |
+
|
4 |
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
5 |
+
.fuse_hidden*
|
6 |
+
|
7 |
+
# KDE directory preferences
|
8 |
+
.directory
|
9 |
+
|
10 |
+
# Linux trash folder which might appear on any partition or disk
|
11 |
+
.Trash-*
|
12 |
+
|
13 |
+
# .nfs files are created when an open file is removed but is still being accessed
|
14 |
+
.nfs*
|
15 |
+
|
16 |
+
### IDEs template
|
17 |
+
.vscode/
|
18 |
+
.idea/
|
19 |
+
.fleet/
|
20 |
+
### Windows template
|
21 |
+
# Windows thumbnail cache files
|
22 |
+
Thumbs.db
|
23 |
+
Thumbs.db:encryptable
|
24 |
+
ehthumbs.db
|
25 |
+
ehthumbs_vista.db
|
26 |
+
|
27 |
+
# Dump file
|
28 |
+
*.stackdump
|
29 |
+
|
30 |
+
# Folder config file
|
31 |
+
[Dd]esktop.ini
|
32 |
+
|
33 |
+
# Recycle Bin used on file shares
|
34 |
+
$RECYCLE.BIN/
|
35 |
+
|
36 |
+
# Windows Installer files
|
37 |
+
*.cab
|
38 |
+
*.msi
|
39 |
+
*.msix
|
40 |
+
*.msm
|
41 |
+
*.msp
|
42 |
+
|
43 |
+
# Windows shortcuts
|
44 |
+
*.lnk
|
45 |
+
|
46 |
+
### Archives template
|
47 |
+
# It's better to unpack these files and commit the raw source because
|
48 |
+
# git has its own built in compression methods.
|
49 |
+
*.7z
|
50 |
+
*.jar
|
51 |
+
*.rar
|
52 |
+
*.zip
|
53 |
+
*.gz
|
54 |
+
*.gzip
|
55 |
+
*.tgz
|
56 |
+
*.bzip
|
57 |
+
*.bzip2
|
58 |
+
*.bz2
|
59 |
+
*.xz
|
60 |
+
*.lzma
|
61 |
+
*.cab
|
62 |
+
*.xar
|
63 |
+
*.zst
|
64 |
+
*.tzst
|
65 |
+
|
66 |
+
# Packing-only formats
|
67 |
+
*.iso
|
68 |
+
*.tar
|
69 |
+
|
70 |
+
# Package management formats
|
71 |
+
*.dmg
|
72 |
+
*.xpi
|
73 |
+
*.gem
|
74 |
+
*.egg
|
75 |
+
*.deb
|
76 |
+
*.rpm
|
77 |
+
*.msi
|
78 |
+
*.msm
|
79 |
+
*.msp
|
80 |
+
*.txz
|
81 |
+
|
82 |
+
### macOS template
|
83 |
+
# General
|
84 |
+
.DS_Store
|
85 |
+
.AppleDouble
|
86 |
+
.LSOverride
|
87 |
+
|
88 |
+
# Icon must end with two \r
|
89 |
+
Icon
|
90 |
+
|
91 |
+
# Thumbnails
|
92 |
+
._*
|
93 |
+
|
94 |
+
# Files that might appear in the root of a volume
|
95 |
+
.DocumentRevisions-V100
|
96 |
+
.fseventsd
|
97 |
+
.Spotlight-V100
|
98 |
+
.TemporaryItems
|
99 |
+
.Trashes
|
100 |
+
.VolumeIcon.icns
|
101 |
+
.com.apple.timemachine.donotpresent
|
102 |
+
|
103 |
+
# Directories potentially created on remote AFP share
|
104 |
+
.AppleDB
|
105 |
+
.AppleDesktop
|
106 |
+
Network Trash Folder
|
107 |
+
Temporary Items
|
108 |
+
.apdisk
|
109 |
+
|
110 |
+
### Python template
|
111 |
+
# Byte-compiled / optimized / DLL files
|
112 |
+
__pycache__/
|
113 |
+
*.py[cod]
|
114 |
+
*$py.class
|
115 |
+
|
116 |
+
# C extensions
|
117 |
+
*.so
|
118 |
+
|
119 |
+
# Distribution / packaging
|
120 |
+
.Python
|
121 |
+
build/
|
122 |
+
develop-eggs/
|
123 |
+
dist/
|
124 |
+
downloads/
|
125 |
+
eggs/
|
126 |
+
.eggs/
|
127 |
+
lib/
|
128 |
+
lib64/
|
129 |
+
parts/
|
130 |
+
sdist/
|
131 |
+
var/
|
132 |
+
wheels/
|
133 |
+
share/python-wheels/
|
134 |
+
*.egg-info/
|
135 |
+
.installed.cfg
|
136 |
+
*.egg
|
137 |
+
MANIFEST
|
138 |
+
|
139 |
+
# PyInstaller
|
140 |
+
# Usually these files are written by a python script from a template
|
141 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
142 |
+
*.manifest
|
143 |
+
*.spec
|
144 |
+
|
145 |
+
# Installer logs
|
146 |
+
pip-log.txt
|
147 |
+
pip-delete-this-directory.txt
|
148 |
+
|
149 |
+
# Unit test / coverage reports
|
150 |
+
htmlcov/
|
151 |
+
.tox/
|
152 |
+
.nox/
|
153 |
+
.coverage
|
154 |
+
.coverage.*
|
155 |
+
.cache
|
156 |
+
nosetests.xml
|
157 |
+
coverage.xml
|
158 |
+
*.cover
|
159 |
+
*.py,cover
|
160 |
+
.hypothesis/
|
161 |
+
.pytest_cache/
|
162 |
+
cover/
|
163 |
+
|
164 |
+
# Translations
|
165 |
+
*.mo
|
166 |
+
*.pot
|
167 |
+
|
168 |
+
# Django stuff:
|
169 |
+
*.log
|
170 |
+
local_settings.py
|
171 |
+
db.sqlite3
|
172 |
+
db.sqlite3-journal
|
173 |
+
|
174 |
+
# Flask stuff:
|
175 |
+
instance/
|
176 |
+
.webassets-cache
|
177 |
+
|
178 |
+
# Scrapy stuff:
|
179 |
+
.scrapy
|
180 |
+
|
181 |
+
# Sphinx documentation
|
182 |
+
docs/_build/
|
183 |
+
|
184 |
+
# PyBuilder
|
185 |
+
.pybuilder/
|
186 |
+
target/
|
187 |
+
|
188 |
+
# Jupyter Notebook
|
189 |
+
.ipynb_checkpoints
|
190 |
+
|
191 |
+
# IPython
|
192 |
+
profile_default/
|
193 |
+
ipython_config.py
|
194 |
+
|
195 |
+
# pyenv
|
196 |
+
# For a library or package, you might want to ignore these files since the code is
|
197 |
+
# intended to run in multiple environments; otherwise, check them in:
|
198 |
+
.python-version
|
199 |
+
|
200 |
+
# pipenv
|
201 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
202 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
203 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
204 |
+
# install all needed dependencies.
|
205 |
+
#Pipfile.lock
|
206 |
+
|
207 |
+
# poetry
|
208 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
209 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
210 |
+
# commonly ignored for libraries.
|
211 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
212 |
+
#poetry.lock
|
213 |
+
|
214 |
+
# pdm
|
215 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
216 |
+
#pdm.lock
|
217 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
218 |
+
# in version control.
|
219 |
+
# https://pdm.fming.dev/#use-with-ide
|
220 |
+
.pdm.toml
|
221 |
+
|
222 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
223 |
+
__pypackages__/
|
224 |
+
|
225 |
+
# Celery stuff
|
226 |
+
celerybeat-schedule
|
227 |
+
celerybeat.pid
|
228 |
+
|
229 |
+
# SageMath parsed files
|
230 |
+
*.sage.py
|
231 |
+
|
232 |
+
# Environments
|
233 |
+
.env
|
234 |
+
.venv
|
235 |
+
env/
|
236 |
+
venv/
|
237 |
+
ENV/
|
238 |
+
env.bak/
|
239 |
+
venv.bak/
|
240 |
+
|
241 |
+
# Spyder project settings
|
242 |
+
.spyderproject
|
243 |
+
.spyproject
|
244 |
+
|
245 |
+
# Rope project settings
|
246 |
+
.ropeproject
|
247 |
+
|
248 |
+
# mkdocs documentation
|
249 |
+
/site
|
250 |
+
|
251 |
+
# mypy
|
252 |
+
.mypy_cache/
|
253 |
+
.dmypy.json
|
254 |
+
dmypy.json
|
255 |
+
|
256 |
+
# Pyre type checker
|
257 |
+
.pyre/
|
258 |
+
|
259 |
+
# pytype static type analyzer
|
260 |
+
.pytype/
|
261 |
+
|
262 |
+
# Cython debug symbols
|
263 |
+
cython_debug/
|
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
USER user
|
5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
+
|
7 |
+
WORKDIR /app
|
8 |
+
|
9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
+
|
12 |
+
COPY --chown=user . /app
|
13 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
from ecologits.tracers.utils import llm_impacts, ImpactsOutput
|
5 |
+
from fastapi import FastAPI
|
6 |
+
from pydantic import BaseModel
|
7 |
+
|
8 |
+
|
9 |
+
app = FastAPI()
|
10 |
+
|
11 |
+
|
12 |
+
class EstimationInputs(BaseModel):
|
13 |
+
provider: str
|
14 |
+
model_name: str
|
15 |
+
output_token_count: int
|
16 |
+
request_latency: Optional[float] = math.inf
|
17 |
+
electricity_mix_zone: Optional[str] = "WOR"
|
18 |
+
|
19 |
+
|
20 |
+
@app.post("/estimations")
|
21 |
+
def create_estimation(inputs: EstimationInputs) -> ImpactsOutput:
|
22 |
+
return llm_impacts(**inputs.model_dump())
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
ecologits
|
2 |
+
pydantic
|
3 |
+
fastapi[standard]
|