Skip to content

Commit 5cae95d

Browse files
committed
~drop litellm
1 parent 0a46ae2 commit 5cae95d

File tree

7 files changed

+181
-141
lines changed

7 files changed

+181
-141
lines changed

pyproject.toml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
# SPDX-License-Identifier: MPL-2.0 AND LicenseRef-Commons-Clause-License-Condition-1.0
2+
# <!-- // /* d a r k s h a p e s */ -->
3+
14
[build-system]
2-
requires = ["setuptools", "setuptools-scm"]
5+
requires = ["setuptools", "setuptools-scm"]
36
build-backend = "setuptools.build_meta"
47

58
[project]
6-
79
authors = [
810
{ name = "darkshapes", email = "91800957+exdysa@users.noreply.github.com" },
911
]
10-
description = "Multimodal generative media sequencer"
11-
license = { file = "LICENSE" }
1212
name = "zodiac"
13+
description = "Multimodal generative media sequencer"
1314
readme = "README.md"
14-
requires-python = ">=3.11"
1515
version = "0.0.2"
16+
license = { file = "LICENSE" }
17+
requires-python = ">=3.11"
1618
keywords = ["ML", "AI", "TUI", "no-code", "diffusion", "LLM", "torch"]
17-
1819
classifiers = [
1920
"Programming Language :: Python :: 3.11",
2021
"Programming Language :: Python :: 3.12",
@@ -42,10 +43,10 @@ classifiers = [
4243
"Topic :: Multimedia :: Video :: Non-Linear Editor",
4344

4445
]
46+
4547
dependencies = [
4648
"dspy>=2.6.27",
47-
"litellm>=1.72.0",
48-
"tokenizers==0.21.2", #force for non linux
49+
"tokenizers==0.21.2", #force for non linux
4950
"networkx>=3.5",
5051
"sounddevice>=0.5.2",
5152
"soundfile>=0.13.1",
@@ -57,7 +58,7 @@ dependencies = [
5758
"pyperclip>=1.9.0",
5859
"ftfy>=6.3.1",
5960
"pdoc>=16.0.0",
60-
61+
"any-llm-sdk[ollama,openai]>=1.13.0",
6162
]
6263

6364
[dependency-groups]
@@ -72,7 +73,7 @@ dev = [
7273

7374

7475
[project.optional-dependencies]
75-
mps = ["nnll[mps]@ git+https://github.com/darkshapes/nnll@0.1.dev799"]
76+
mps = ["nnll[mps]@ git+https://github.com/darkshapes/nnll@0.1.dev799"]
7677
cuda = ["nnll[cuda ]@ git+https://github.com/darkshapes/nnll@0.1.dev799"]
7778

7879
console = [
@@ -95,13 +96,13 @@ dev = [
9596
]
9697

9798
[project.urls]
98-
Homepage = "https://github.com/darkshapes/zodiac"
99+
Homepage = "https://github.com/darkshapes/zodiac"
99100
Documentation = "https://github.com/darkshapes/sdbx/wiki"
100101

101102
[project.scripts]
102-
zdac = "zodiac.toga.__main__:main"
103+
zdac = "zodiac.toga.__main__:main"
103104
zdac-pool = "zodiac.providers.pools:generate_pool"
104-
zodiac = "zodiac.toga.__main__:main"
105+
zodiac = "zodiac.toga.__main__:main"
105106

106107
[tool.setuptools]
107108
packages = ["zodiac"]
@@ -119,16 +120,16 @@ conflicts = [
119120
],
120121
]
121122
[tool.ruff]
122-
line-length = 140
123-
include = ["*.py"]
123+
line-length = 140
124+
include = ["*.py"]
124125
extend-exclude = ["^tests/.*$", "test.*$"]
125126

126127
# [tool.ruff.format]
127128
# exclude = ["*.py"]
128129

129130
[tool.pylint]
130131
max-line-length = 140
131-
ignore-paths = ["^tests/.*$", "test_.*$"]
132+
ignore-paths = ["^tests/.*$", "test_.*$"]
132133

133134
[tool.pylint.messages_control]
134135
disable = ["C0415"]
@@ -140,7 +141,7 @@ ignore = ["E731"]
140141
convention = "numpy"
141142

142143
[tool.ruff.lint.pycodestyle]
143-
max-line-length = 140
144+
max-line-length = 140
144145
ignore-overlong-task-comments = true
145146

146147
[tool.typos]

uv.lock

Lines changed: 136 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zodiac/__init__.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,6 @@ def set_env(args: argparse.ArgumentParser):
4848
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = str(not args.diag)
4949
os.environ["HF_HUB_OFFLINE"] = str(int(not args.net or not args.diag))
5050

51-
os.environ["DISABLE_HF_TOKENIZER_DOWNLOAD"] = str(not args.net or not args.diag) # litellm
52-
# huggingface_hub.constants.HF_HUB_VERBOSITY
53-
54-
try:
55-
import litellm
56-
except (ImportError, ModuleNotFoundError, Exception): # pylint: disable=broad-exception-caught
57-
pass
58-
else:
59-
litellm.disable_token_counter = False
60-
litellm.disable_streaming_logging = True
61-
litellm.turn_off_message_logging = True
62-
litellm.suppress_debug_info = False
63-
litellm.json_logs = False # type: ignore
64-
litellm.disable_end_user_cost_tracking = True
65-
litellm.telemetry = False
66-
litellm.disable_hf_tokenizer_download = not args.net # -net = True -> disable download = False/0
67-
os.environ["DISABLE_END_USER_COST_TRACKING"] = "True"
6851
return True
6952

7053

zodiac/streams/token_stream.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33

44
# pylint: disable=import-error
55

6-
7-
import warnings
8-
from pathlib import Path
96
from typing import Callable, Optional
107

11-
warnings.filterwarnings("ignore", category=DeprecationWarning)
12-
13-
from litellm.utils import create_tokenizer, token_counter
8+
import tiktoken
149
from toga.sources import Source
1510
from zodiac.providers.registry_entry import RegistryEntry
1611

1712

13+
async def tiktoken_counter(model="cl100k_base", message: str = ""):
14+
"""
15+
Return token count of gpt based on model\n
16+
:param model: Model path to lookup tokenizer for
17+
:param message: Message to tokenize
18+
:return: `int` Number of tokens needed to represent message
19+
"""
20+
21+
encoding = tiktoken.get_encoding(model)
22+
return len(encoding.encode(message))
23+
24+
1825
class TokenStream(Source):
1926
def __init__(self):
2027
self.tokenizer: Optional[str] = None
@@ -27,18 +34,7 @@ async def set_tokenizer(self, registry_entry: RegistryEntry) -> Callable:
2734
:param message: Text to encode
2835
:return: Token embeddings for the model"""
2936

30-
import json
31-
32-
if registry_entry.tokenizer:
33-
with open(str(registry_entry.tokenizer), encoding="UTF-8") as file_obj:
34-
tokenizer_json = json.load(file_obj)
35-
tokenizer_data = json.dumps(tokenizer_json)
36-
self.tokenizer_args = {"custom_tokenizer": create_tokenizer(tokenizer_data)}
37-
else:
38-
# model_name = os.path.split(registry_entry.model)
39-
# model_name = os.path.join(os.path.split(model_name[0])[-1], model_name[-1])
40-
# self.status_log.registry_entry.model
41-
self.tokenizer_args = {"model": registry_entry.model}
37+
self.tokenizer_args = {} # Disabled until suitable replacement is found
4238

4339
async def token_count(
4440
self,
@@ -52,4 +48,4 @@ async def token_count(
5248

5349
warnings.filterwarnings("ignore", category=DeprecationWarning)
5450
character_count = len(message)
55-
return token_counter(text=message, **self.tokenizer_args), character_count
51+
return tiktoken_counter(text=message, **self.tokenizer_args), character_count

zodiac/toga/app.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class Interface(toga.App):
2727
formatted_units = [" ❖ chr", " ⟐ tok", ' " sec ']
2828
bg_graph = "#070708"
29-
bg_text = "#1B1B1B" # "#1B1B1B" # "#09090B"
29+
bg_text = "#1E1C1D" # "#1B1B1B" # "#09090B"
3030
bg = bg_text
3131
bg_static = "#5D5E62"
3232
activity = "#8122C4"
@@ -53,33 +53,29 @@ async def ticker(self, widget: Callable, external: bool = False, **kwargs) -> to
5353
if self.message_panel.value:
5454
cache = False
5555
prompts.setdefault("text", self.message_panel.value)
56-
# prompts.setdefault("audio",[0]) if else []
57-
# prompts.setdefault("image",[]) if image": []
5856
if stream := self.output_types.value == "text":
5957
context_data, predictor_data = await ready_predictor(self.registry_entry, dspy_stream=stream, async_stream=stream, cache=cache)
6058
await self.stream_text(prompts, context_data, predictor_data)
6159
else:
62-
content = await self.generate_media(prompts, self.registry_entry) # context_data, predictor_data)
6360
return widget
6461
return widget
6562

6663
async def stream_text(self, prompts, context_data, predictor_data):
6764
from zodiac.toga.signatures import Predictor
68-
from litellm.types.utils import ModelResponseStream # StatusStreamingCallback
6965
from dspy.streaming import StatusMessage, StreamResponse
7066

7167
self.response_panel.scroll_to_bottom()
7268
with dspy_context(**context_data):
7369
self.program = streamify(Predictor(), **predictor_data)
7470
async for prediction in self.program(question=prompts["text"]):
75-
if isinstance(prediction, ModelResponseStream) and prediction["choices"][0]["delta"]["content"]:
76-
self.response_panel.value += prediction["choices"][0]["delta"]["content"]
77-
elif isinstance(prediction, StreamResponse) or hasattr(prediction, "chunk"):
71+
if isinstance(prediction, StreamResponse) or hasattr(prediction, "chunk"):
7872
self.response_panel.value += str(prediction.chunk)
7973
elif isinstance(prediction, Prediction) or hasattr(prediction, "answer"):
8074
self.response_panel.value += str(prediction.answer)
8175
elif isinstance(prediction, StatusMessage) or hasattr(prediction, "message"):
8276
self.status_display.text = self.status_text_prefix + str(prediction.message)
77+
elif prediction["choices"][0]["delta"].get("content"):
78+
self.response_panel.value += prediction["choices"][0]["delta"]["content"]
8379
self.response_panel.value += "\n--\n\n"
8480
return prediction
8581

zodiac/toga/palette.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async def ticker(self, widget: Callable, external: bool = False, **kwargs) -> to
1313
:param external: Indicates whether the processing should be handled externally (e.g., via clipboard), defaults to False
1414
:type external: bool"""
1515
from zodiac.toga.signatures import ready_predictor
16+
import os
1617

1718
self.response_panel.value += f"{os.path.basename(self.registry_entry.model)} :\n"
1819

@@ -34,21 +35,22 @@ async def ticker(self, widget: Callable, external: bool = False, **kwargs) -> to
3435

3536
async def stream_text(self, prompts, context_data, predictor_data):
3637
from zodiac.toga.signatures import Predictor
37-
from litellm.types.utils import ModelResponseStream # StatusStreamingCallback
38+
39+
from dspy import Prediction, context as dspy_context, streamify
3840
from dspy.streaming import StatusMessage, StreamResponse
3941

4042
self.response_panel.scroll_to_bottom()
4143
with dspy_context(**context_data):
4244
self.program = streamify(Predictor(), **predictor_data)
4345
async for prediction in self.program(question=prompts["text"]):
44-
if isinstance(prediction, ModelResponseStream) and prediction["choices"][0]["delta"]["content"]:
45-
self.response_panel.value += prediction["choices"][0]["delta"]["content"]
46-
elif isinstance(prediction, StreamResponse) or hasattr(prediction, "chunk"):
46+
if isinstance(prediction, StreamResponse) or hasattr(prediction, "chunk"):
4747
self.response_panel.value += str(prediction.chunk)
4848
elif isinstance(prediction, Prediction) or hasattr(prediction, "answer"):
4949
self.response_panel.value += str(prediction.answer)
5050
elif isinstance(prediction, StatusMessage) or hasattr(prediction, "message"):
5151
self.status_display.text = self.status_text_prefix + str(prediction.message)
52+
elif prediction["choices"][0]["delta"].get("content"):
53+
self.response_panel.value += prediction["choices"][0]["delta"]["content"]
5254
self.response_panel.value += "\n--\n\n"
5355
return prediction
5456

zodiac/toga/signatures.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,14 @@ def __init__(self):
8787
self.program = dspy.Predict(signature=QATask)
8888

8989
def __call__(self, question: str):
90-
from litellm.exceptions import APIConnectionError
91-
from litellm.llms.ollama.common_utils import OllamaError
90+
from any_llm.utils.exception_handler import AnyLLMError
9291
from httpx import ConnectError
9392
from dspy.utils.exceptions import AdapterParseError
9493
from aiohttp.client_exceptions import ClientConnectorError
9594

9695
try:
9796
return self.program(question=question)
98-
except (ClientConnectorError, ConnectError, AdapterParseError, APIConnectionError, OllamaError, OSError):
97+
except (ClientConnectorError, ConnectError, AdapterParseError, AnyLLMError, OSError):
9998
pass
10099

101100
# from nnll.tensor_pipe import segments

0 commit comments

Comments
 (0)