Skip to content

Commit

Permalink
feat: update dependencies
Browse files Browse the repository at this point in the history
make openai optional
downgrade wrapt to compatible with tensorflow 2.15.0 (colab)
  • Loading branch information
samuelrince committed Apr 18, 2024
1 parent 5439457 commit ad208fe
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 29 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: publish-pypi

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
# check-out repo and set-up python
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: "3.9"

# install & configure poetry
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

# configure credentials
- name: Configure credentials
run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_KEY }}

# build package
- name: Build package
run: poetry build

# publish package
- name: Publish package
run: poetry publish
2 changes: 1 addition & 1 deletion .github/workflows/publish-testpypi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish package on Test PyPI
name: publish-testpypi

on:
push:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ EcoLogits

## ⚙️ Installation

Coming soon...
```shell
pip install ecologits
```

## 🚀 Usage

Expand All @@ -23,7 +25,7 @@ client = OpenAI(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Hello, can you explain what is the GenAI Impact project?"}
{"role": "user", "content": "Tell me a funny joke!"}
]
)

Expand Down
18 changes: 14 additions & 4 deletions ecologits/tracers/openai_tracer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import time
from typing import Any, Callable, Union

from openai import AsyncStream, Stream
from openai.resources.chat import AsyncCompletions, Completions
from openai.types.chat import ChatCompletion as _ChatCompletion
from openai.types.chat import ChatCompletionChunk as _ChatCompletionChunk
from wrapt import wrap_function_wrapper

from ecologits.impacts import Impacts
from ecologits.tracers.utils import compute_llm_impacts

try:
from openai import AsyncStream, Stream
from openai.resources.chat import AsyncCompletions, Completions
from openai.types.chat import ChatCompletion as _ChatCompletion
from openai.types.chat import ChatCompletionChunk as _ChatCompletionChunk
except ImportError:
AsyncStream = object()
Stream = object()
AsyncCompletions = object()
Completions = object()
_ChatCompletion = object()
_ChatCompletionChunk = object()


PROVIDER = "openai"


Expand Down
19 changes: 10 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ build-backend = "poetry.core.masonry.api"
name = "ecologits"
version = "0.1.0"
description = "EcoLogits tracks and estimates the energy consumption and environmental impacts of using generative AI models through APIs."
authors = ["GenAI Impact"]
authors = [
"GenAI Impact",
"Data For Good"
]
maintainers = [
"GenAI Impact"
]
license = "MPL-2.0"
readme = "README.md"
repository = "https://github.com/genai-impact/ecologits"
classifiers = [
# "Programming Language :: Python",
# "Programming Language :: Python :: 3.9",
# "Programming Language :: Python :: 3.10",
# "Programming Language :: Python :: 3.11",
# "Programming Language :: Python :: 3.12",
# "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Topic :: Internet",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand All @@ -33,18 +34,19 @@ classifiers = [

[tool.poetry.dependencies]
python = ">=3.9,<4"
openai = "^1.12.0"
wrapt = "^1.16.0"
wrapt = "^1.14.1"
pydantic = ">=2,<3"
openai = { version = "^1.12.0", optional = true }
mistralai = { version = "^0.1.3", optional = true }
anthropic = { version = "^0.18.1", optional = true }
cohere = {version = "^5.2.5", optional = true}
huggingface-hub = { version = "^0.22.2", optional = true }
tiktoken = {version = "^0.6.0", optional = true}
aiohttp = {version = "^3.9.3", optional = true}
minijinja = {version = "^1.0.16", optional = true}
tiktoken = { version = "^0.6.0", optional = true }
aiohttp = { version = "^3.9.3", optional = true }
minijinja = { version = "^1.0.16", optional = true }

[tool.poetry.extras]
openai = ["openai"]
mistralai = ["mistralai"]
anthropic = ["anthropic"]
cohere = ["cohere"]
Expand Down Expand Up @@ -178,7 +180,7 @@ line-length = 120

dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

target-version = "py38"
target-version = "py39"

[tool.ruff.mccabe]
max-complexity = 10

0 comments on commit ad208fe

Please sign in to comment.