Skip to content

Commit fbdfed1

Browse files
committed
feat: Update Makefile targets and add new test commands
fix: Correct Python path in Makefile chore: Update requirements.txt and setup.py chore: Update src/pytgpt/__init__.py chore: Update src/pytgpt/api/__init__.py chore: Update src/pytgpt/api/v1.py chore: Update src/pytgpt/console.py
1 parent 45b75d4 commit fbdfed1

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

Makefile

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define targets
2-
.PHONY: install install-minimal test test_tgpt build build-deb build-minimal-deb clean
2+
.PHONY: install install-minimal test test-tgpt test-api test-utils build build-deb build-minimal-deb clean
33

44
# Define variables
55
PYTHON := python3
@@ -15,22 +15,30 @@ default: install test build
1515
# Target to install dependencies
1616
install: clean
1717
$(PI) install -r requirements.txt
18-
$(PI) install .
18+
$(PI) install -e .
1919
$(PI) install --upgrade g4f[all]
2020

2121
# Target to install minimal dependencies
2222
install-minimal: clean
2323
$(PI) install -r requirements.txt
24-
$(PI) install .
24+
$(PI) install -e .
2525

2626
# Target to run tests
27-
test:
27+
test: install
2828
$(PYTHON) -m unittest discover -s tests -p 'test_*.py' -f -v
2929

3030
# Target to run tgpt providers test
31-
test-tgpt:
31+
test-tgpt: install
3232
$(PYTHON) -m unittest discover -s tests -p 'test_*_tgpt.py' -f -v
3333

34+
# Target to run REST-api test
35+
test-api: install
36+
$(PYTHON) -m unittest discover -s tests -p 'test_api.py' -f -v
37+
38+
# Target to run pytgpt utils test
39+
test-utils: install
40+
$(PYTHON) -m unittest discover -s tests -p 'test_utils.py' -f -v
41+
3442
# Target to create an executable using PyInstaller
3543
build: install
3644
$(PI) install --upgrade pyinstaller

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ poe-api-wrapper==1.3.6
1515
python-dotenv==1.0.0
1616
brotli==1.1.0
1717
Helpingai_T2-fork==0.3.2
18-
fastapi[all]==0.110.1
18+
fastapi[all]==0.115.4
1919
python-vlc>=3.0.20
20-
httpx==0.27.0
20+
httpx==0.27.2

setup.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"g4f>=0.2.6.1",
1717
"Helpingai_T2-fork==0.3.2",
1818
"python-vlc>=3.0.20",
19-
"httpx==0.27.0",
19+
"httpx==0.27.2",
2020
]
2121

2222
cli_reqs = [
@@ -30,7 +30,7 @@
3030
]
3131

3232
api = [
33-
"fastapi[all]==0.110.1",
33+
"fastapi[all]==0.115.4",
3434
]
3535

3636
termux = [
@@ -56,7 +56,7 @@
5656

5757
setup(
5858
name="python-tgpt",
59-
version="0.7.5",
59+
version="0.7.6",
6060
license="MIT",
6161
author="Smartwa",
6262
maintainer="Smartwa",
@@ -110,7 +110,6 @@
110110
classifiers=[
111111
"License :: OSI Approved :: MIT License",
112112
"Intended Audience :: Developers",
113-
"Intended Audience :: Developers",
114113
"Natural Language :: English",
115114
"License :: Free For Home Use",
116115
"Intended Audience :: Customer Service",

src/pytgpt/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from pytgpt.utils import appdir
21
import g4f
32
from importlib import metadata
43
import logging

src/pytgpt/api/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pytgpt import __version__
99
from pytgpt.utils import api_static_dir
1010
from pydantic import BaseModel
11-
from datetime import datetime
11+
from datetime import datetime, UTC
1212
from . import v1
1313

1414
app = FastAPI(
@@ -51,7 +51,7 @@ async def server_status() -> ServerStatus:
5151
- `is_alive` : status
5252
- `as_at` : Time checked.
5353
"""
54-
return ServerStatus(as_at=datetime.utcnow())
54+
return ServerStatus(as_at=datetime.now(UTC))
5555

5656

5757
app.include_router(v1.app, prefix="/v1", tags=["v1"])

src/pytgpt/api/v1.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from fastapi.responses import Response, StreamingResponse, RedirectResponse
33
from fastapi.encoders import jsonable_encoder
44
from json import dumps
5-
from pydantic import BaseModel, validator, PositiveInt
6-
from typing import Union, Any, Generator
5+
from pydantic import BaseModel, field_validator, PositiveInt
6+
from typing import Union, Any, AsyncGenerator
77
from pytgpt import gpt4free_providers
88
from uuid import uuid4
99
from .utils import api_exception_handler
@@ -77,7 +77,7 @@ class TextGenerationPayload(BaseModel):
7777
}
7878
}
7979

80-
@validator("provider")
80+
@field_validator("provider")
8181
def validate_provider(provider: str) -> object:
8282
if provider not in supported_providers:
8383
raise HTTPException(
@@ -162,7 +162,7 @@ class ImagePayload(BaseModel):
162162
}
163163
}
164164

165-
@validator("amount")
165+
@field_validator("amount")
166166
def validate_amount(amount: int) -> PositiveInt:
167167
if amount > 10:
168168
raise HTTPException(
@@ -173,7 +173,7 @@ def validate_amount(amount: int) -> PositiveInt:
173173
)
174174
return amount
175175

176-
@validator("provider")
176+
@field_validator("provider")
177177
def validate_provider(provider: Union[str, None]) -> str:
178178

179179
if provider is not None and not provider in image_providers:
@@ -209,7 +209,7 @@ class ImageBytesPayload(BaseModel):
209209
}
210210
}
211211

212-
@validator("provider")
212+
@field_validator("provider")
213213
def validate_provider(provider: Union[str, None]) -> str:
214214
if provider is not None and not provider in image_providers:
215215
raise HTTPException(
@@ -265,7 +265,7 @@ class TextToAudioPayload(BaseModel):
265265
}
266266
}
267267

268-
@validator("voice")
268+
@field_validator("voice")
269269
def validate_voice(voice) -> str:
270270
if not voice in Audio.all_voices:
271271
raise HTTPException(
@@ -345,7 +345,7 @@ async def non_stream(payload: TextGenerationPayload) -> ProviderResponse:
345345
)
346346

347347

348-
async def generate_streaming_response(payload: TextGenerationPayload) -> Generator:
348+
async def generate_streaming_response(payload: TextGenerationPayload) -> AsyncGenerator:
349349
provider_obj = await init_provider(payload)
350350
async_chat = await provider_obj.chat(payload.prompt, stream=True)
351351
async for text in async_chat:

src/pytgpt/console.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from rich.table import Table
2323
from rich.prompt import Prompt
2424
from rich.progress import Progress
25-
from typing import Iterator
25+
from typing import Iterable
2626
from pytgpt.utils import Optimizers
2727
from pytgpt.utils import default_path
2828
from pytgpt.utils import AwesomePrompts
@@ -163,7 +163,7 @@ def sanitize_provider(provider: object):
163163

164164
@staticmethod
165165
def stream_output(
166-
iterable: Iterator,
166+
iterable: Iterable,
167167
title: str = "",
168168
is_markdown: bool = True,
169169
style: object = Style(),
@@ -176,7 +176,7 @@ def stream_output(
176176
"""Stdout streaming response
177177
178178
Args:
179-
iterable (Iterator): Iterator containing contents to be stdout
179+
iterable (Iterable): Iterable containing contents to be stdout
180180
title (str, optional): Content title. Defaults to ''.
181181
is_markdown (bool, optional): Flag for markdown content. Defaults to True.
182182
style (object, optional): `rich.style` instance. Defaults to Style().

0 commit comments

Comments
 (0)