Skip to content

Commit

Permalink
feat: Update Makefile targets and add new test commands
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Simatwa committed Oct 30, 2024
1 parent 45b75d4 commit fbdfed1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define targets
.PHONY: install install-minimal test test_tgpt build build-deb build-minimal-deb clean
.PHONY: install install-minimal test test-tgpt test-api test-utils build build-deb build-minimal-deb clean

# Define variables
PYTHON := python3
Expand All @@ -15,22 +15,30 @@ default: install test build
# Target to install dependencies
install: clean
$(PI) install -r requirements.txt
$(PI) install .
$(PI) install -e .
$(PI) install --upgrade g4f[all]

# Target to install minimal dependencies
install-minimal: clean
$(PI) install -r requirements.txt
$(PI) install .
$(PI) install -e .

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

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

# Target to run REST-api test
test-api: install
$(PYTHON) -m unittest discover -s tests -p 'test_api.py' -f -v

# Target to run pytgpt utils test
test-utils: install
$(PYTHON) -m unittest discover -s tests -p 'test_utils.py' -f -v

# Target to create an executable using PyInstaller
build: install
$(PI) install --upgrade pyinstaller
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ poe-api-wrapper==1.3.6
python-dotenv==1.0.0
brotli==1.1.0
Helpingai_T2-fork==0.3.2
fastapi[all]==0.110.1
fastapi[all]==0.115.4
python-vlc>=3.0.20
httpx==0.27.0
httpx==0.27.2
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"g4f>=0.2.6.1",
"Helpingai_T2-fork==0.3.2",
"python-vlc>=3.0.20",
"httpx==0.27.0",
"httpx==0.27.2",
]

cli_reqs = [
Expand All @@ -30,7 +30,7 @@
]

api = [
"fastapi[all]==0.110.1",
"fastapi[all]==0.115.4",
]

termux = [
Expand All @@ -56,7 +56,7 @@

setup(
name="python-tgpt",
version="0.7.5",
version="0.7.6",
license="MIT",
author="Smartwa",
maintainer="Smartwa",
Expand Down Expand Up @@ -110,7 +110,6 @@
classifiers=[
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
"Intended Audience :: Developers",
"Natural Language :: English",
"License :: Free For Home Use",
"Intended Audience :: Customer Service",
Expand Down
1 change: 0 additions & 1 deletion src/pytgpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pytgpt.utils import appdir
import g4f
from importlib import metadata
import logging
Expand Down
4 changes: 2 additions & 2 deletions src/pytgpt/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytgpt import __version__
from pytgpt.utils import api_static_dir
from pydantic import BaseModel
from datetime import datetime
from datetime import datetime, UTC
from . import v1

app = FastAPI(
Expand Down Expand Up @@ -51,7 +51,7 @@ async def server_status() -> ServerStatus:
- `is_alive` : status
- `as_at` : Time checked.
"""
return ServerStatus(as_at=datetime.utcnow())
return ServerStatus(as_at=datetime.now(UTC))


app.include_router(v1.app, prefix="/v1", tags=["v1"])
Expand Down
16 changes: 8 additions & 8 deletions src/pytgpt/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from fastapi.responses import Response, StreamingResponse, RedirectResponse
from fastapi.encoders import jsonable_encoder
from json import dumps
from pydantic import BaseModel, validator, PositiveInt
from typing import Union, Any, Generator
from pydantic import BaseModel, field_validator, PositiveInt
from typing import Union, Any, AsyncGenerator
from pytgpt import gpt4free_providers
from uuid import uuid4
from .utils import api_exception_handler
Expand Down Expand Up @@ -77,7 +77,7 @@ class TextGenerationPayload(BaseModel):
}
}

@validator("provider")
@field_validator("provider")
def validate_provider(provider: str) -> object:
if provider not in supported_providers:
raise HTTPException(
Expand Down Expand Up @@ -162,7 +162,7 @@ class ImagePayload(BaseModel):
}
}

@validator("amount")
@field_validator("amount")
def validate_amount(amount: int) -> PositiveInt:
if amount > 10:
raise HTTPException(
Expand All @@ -173,7 +173,7 @@ def validate_amount(amount: int) -> PositiveInt:
)
return amount

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

if provider is not None and not provider in image_providers:
Expand Down Expand Up @@ -209,7 +209,7 @@ class ImageBytesPayload(BaseModel):
}
}

@validator("provider")
@field_validator("provider")
def validate_provider(provider: Union[str, None]) -> str:
if provider is not None and not provider in image_providers:
raise HTTPException(
Expand Down Expand Up @@ -265,7 +265,7 @@ class TextToAudioPayload(BaseModel):
}
}

@validator("voice")
@field_validator("voice")
def validate_voice(voice) -> str:
if not voice in Audio.all_voices:
raise HTTPException(
Expand Down Expand Up @@ -345,7 +345,7 @@ async def non_stream(payload: TextGenerationPayload) -> ProviderResponse:
)


async def generate_streaming_response(payload: TextGenerationPayload) -> Generator:
async def generate_streaming_response(payload: TextGenerationPayload) -> AsyncGenerator:
provider_obj = await init_provider(payload)
async_chat = await provider_obj.chat(payload.prompt, stream=True)
async for text in async_chat:
Expand Down
6 changes: 3 additions & 3 deletions src/pytgpt/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from rich.table import Table
from rich.prompt import Prompt
from rich.progress import Progress
from typing import Iterator
from typing import Iterable
from pytgpt.utils import Optimizers
from pytgpt.utils import default_path
from pytgpt.utils import AwesomePrompts
Expand Down Expand Up @@ -163,7 +163,7 @@ def sanitize_provider(provider: object):

@staticmethod
def stream_output(
iterable: Iterator,
iterable: Iterable,
title: str = "",
is_markdown: bool = True,
style: object = Style(),
Expand All @@ -176,7 +176,7 @@ def stream_output(
"""Stdout streaming response
Args:
iterable (Iterator): Iterator containing contents to be stdout
iterable (Iterable): Iterable containing contents to be stdout
title (str, optional): Content title. Defaults to ''.
is_markdown (bool, optional): Flag for markdown content. Defaults to True.
style (object, optional): `rich.style` instance. Defaults to Style().
Expand Down

0 comments on commit fbdfed1

Please sign in to comment.