Skip to content

Commit 3337a95

Browse files
committed
feat: Add Novita support to Python-TGPT library
fix: Update README.md to include Novita details patch: Bump version number to 0.7.5 fix: Add Novita provider to async_providers.py feat: Implement Novita provider in console.py fix: Add UnsupportedModelError exception handling
1 parent 5aff2c6 commit 3337a95

File tree

11 files changed

+147
-6
lines changed

11 files changed

+147
-6
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define targets
2-
.PHONY: install install-minimal test build build-deb build-minimal-deb clean
2+
.PHONY: install install-minimal test test_tgpt build build-deb build-minimal-deb clean
33

44
# Define variables
55
PYTHON := python3
@@ -27,6 +27,10 @@ install-minimal: clean
2727
test:
2828
$(PYTHON) -m unittest discover -s tests -p 'test_*.py' -f -v
2929

30+
# Target to run tgpt providers test
31+
test_tgpt:
32+
$(PYTHON) -m unittest discover -s tests -p 'test_*_tgpt.py' -f -v
33+
3034
# Target to create an executable using PyInstaller
3135
build: install
3236
$(PI) install --upgrade pyinstaller

docs/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ These are simply the hosts of the LLMs, which include:
8888
14. [Groq](https://console.groq.com/playground) *(API Key required)*
8989
15. [Perplexity](https://www.perplexity.ai)
9090
16. [YepChat](https://yep.com)
91-
91+
17. [Novita](https://novita.ai) *(API key required)*
9292

9393
<details>
9494

@@ -349,6 +349,21 @@ print(bot.chat("<Your-prompt>"))
349349

350350
</details>
351351

352+
<details>
353+
354+
<summary>
355+
Novita
356+
357+
</summary>
358+
359+
```python
360+
import pytgpt.novita as novita
361+
bot = novita.NOVITA("<NOVITA-API-KEY>")
362+
print(bot.chat("<Your-prompt>"))
363+
```
364+
365+
</details>
366+
352367
### Asynchronous
353368

354369
**Version 0.7.0** introduces asynchronous implementation to almost all providers except a few such as *perplexity & gemini*, which relies on other libraries which lacks such implementation.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
setup(
5858
name="python-tgpt",
59-
version="0.7.4",
59+
version="0.7.5",
6060
license="MIT",
6161
author="Smartwa",
6262
maintainer="Smartwa",

src/pytgpt/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"groq",
2929
"perplexity",
3030
"yepchat",
31+
"novita",
3132
]
3233

3334
gpt4free_providers = [

src/pytgpt/async_providers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pytgpt.koboldai import AsyncKOBOLDAI
88
from pytgpt.groq import AsyncGROQ
99
from pytgpt.blackboxai import AsyncBLACKBOXAI
10+
from pytgpt.novita import AsyncNOVITA
1011
from pytgpt.gpt4free import AsyncGPT4FREE
1112

1213
mapper: dict[str, object] = {
@@ -20,6 +21,7 @@
2021
"leo": AsyncLEO,
2122
"groq": AsyncGROQ,
2223
"openai": AsyncOPENAI,
24+
"novita": AsyncNOVITA,
2325
}
2426

2527
tgpt_mapper: dict[str, object] = {

src/pytgpt/console.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,30 @@ def __init__(
724724
quiet=quiet,
725725
)
726726

727+
elif provider == "novita":
728+
assert auth, (
729+
"Novita's API-key is required. " "Use the flag `--key` or `-k`"
730+
)
731+
from pytgpt.novita import main
732+
733+
self.bot = main.NOVITA(
734+
api_key=auth,
735+
is_conversation=disable_conversation,
736+
max_tokens=max_tokens,
737+
temperature=temperature,
738+
presence_penalty=top_p,
739+
frequency_penalty=top_k,
740+
top_p=top_p,
741+
model=getOr(model, main.model),
742+
timeout=timeout,
743+
intro=intro,
744+
filepath=filepath,
745+
update_file=update_file,
746+
proxies=proxies,
747+
history_offset=history_offset,
748+
act=awesome_prompt,
749+
)
750+
727751
else:
728752
raise NotImplementedError(
729753
f"The provider `{provider}` is not yet implemented."

src/pytgpt/exceptions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class FailedToGenerateResponseError(Exception):
22
"""Provider failed to fetch response"""
33

4-
pass
4+
5+
class UnsupportedModelError(Exception):
6+
"""Model passed is not supported by the provider"""

src/pytgpt/novita/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pytgpt.novita.main import NOVITA
2+
from pytgpt.novita.main import AsyncNOVITA
3+
from pytgpt.novita.main import available_models
4+
from pytgpt.openai.main import session
5+
6+
7+
__info__ = "Interact with NOVITA's model. " "API key is required"
8+
9+
__all__ = ["NOVITA", "AsyncNOVITA", "available_models", "session"]

src/pytgpt/novita/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from pytgpt.openai import OPENAI, AsyncOPENAI
2+
from pytgpt.exceptions import UnsupportedModelError
3+
4+
model = "meta-llama/llama-3.1-8b-instruct"
5+
6+
available_models = [
7+
"meta-llama/llama-3.1-8b-instruct",
8+
"meta-llama/llama-3.1-70b-instruct",
9+
"meta-llama/llama-3.1-405b-instruct",
10+
"meta-llama/llama-3-8b-instruct",
11+
"meta-llama/llama-3-70b-instruct",
12+
"gryphe/mythomax-l2-13b",
13+
"google/gemma-2-9b-it",
14+
"mistralai/mistral-nemo",
15+
"microsoft/wizardlm-2-8x22b",
16+
"mistralai/mistral-7b-instruct",
17+
"microsoft/wizardlm-2-7b",
18+
"openchat/openchat-7b",
19+
"nousresearch/hermes-2-pro-llama-3-8b",
20+
"sao10k/l3-70b-euryale-v2.1",
21+
"cognitivecomputations/dolphin-mixtral-8x22b",
22+
"jondurbin/airoboros-l2-70b",
23+
"lzlv_70b",
24+
"nousresearch/nous-hermes-llama2-13b",
25+
"teknium/openhermes-2.5-mistral-7b",
26+
"sophosympatheia/midnight-rose-70b",
27+
"meta-llama/llama-3.1-8b-instruct-bf16",
28+
"qwen/qwen-2.5-72b-instruct",
29+
"sao10k/l31-70b-euryale-v2.2",
30+
"qwen/qwen-2-7b-instruct",
31+
"qwen/qwen-2-72b-instruct",
32+
]
33+
34+
35+
class NOVITA(OPENAI):
36+
"""Novita AI provider"""
37+
38+
def __init__(self, *args, **kwargs):
39+
kwargs.setdefault("model", model)
40+
if not model in available_models:
41+
raise UnsupportedModelError(
42+
f"Model '{model}' is not yet supported. Choose from {available_models}"
43+
)
44+
super().__init__(*args, **kwargs)
45+
self.chat_endpoint = "https://api.novita.ai/v3/openai/chat/completions"
46+
47+
48+
class AsyncNOVITA(AsyncOPENAI):
49+
"""Async Novita AI provider"""
50+
51+
def __init__(self, *args, **kwargs):
52+
kwargs.setdefault("model", model)
53+
if not model in available_models:
54+
raise UnsupportedModelError(
55+
f"Model '{model}' is not yet supported choose from {available_models}"
56+
)
57+
super().__init__(*args, **kwargs)
58+
self.chat_endpoint = "https://api.novita.ai/v3/openai/chat/completions"

tests/test_novita.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
import tests.base as base
3+
from os import getenv
4+
from pytgpt.novita import NOVITA
5+
from pytgpt.novita import AsyncNOVITA
6+
7+
API_KEY = getenv("NOVITA_API_KEY")
8+
9+
10+
class TestOpenai(base.llmBase):
11+
def setUp(self):
12+
self.bot = NOVITA(API_KEY)
13+
self.prompt = base.prompt
14+
15+
16+
class TestAsyncOpenai(base.AsyncProviderBase):
17+
18+
def setUp(self):
19+
self.bot = AsyncNOVITA(API_KEY)
20+
self.prompt = base.prompt
21+
22+
23+
if __name__ == "__main__":
24+
unittest.main()

0 commit comments

Comments
 (0)