Skip to content

Commit

Permalink
πŸš€ Python 3.12 Support (#1343)
Browse files Browse the repository at this point in the history
* πŸš€ Upgrade to python 3.12

* ♻️ Sort imports

* ♻️ Sort imports
  • Loading branch information
awtkns authored Oct 27, 2023
1 parent fa03984 commit a96f66c
Show file tree
Hide file tree
Showing 25 changed files with 1,066 additions and 1,341 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Testing Platform
on:
# push:
# branches: [ "main" ]
# paths:
# - 'platform/**'
pull_request:
branches: [ "main" ]
paths:
- 'platform/**'

env:
PYTHON_VERSION: "3.11"

jobs:
black:
runs-on: ubuntu-latest
Expand All @@ -21,7 +20,7 @@ jobs:
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
- run: poetry install
- name: Run black check
Expand All @@ -38,7 +37,7 @@ jobs:
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
- run: poetry install
- name: Run mypy check
Expand Down Expand Up @@ -70,7 +69,7 @@ jobs:
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
- run: poetry install
- name: Run pytest check
Expand Down
2,305 changes: 1,019 additions & 1,286 deletions platform/poetry.lock

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions platform/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ name = "reworkd_platform"
version = "0.1.0"
description = ""
authors = [

"awtkns",
"asim-shrestha"
]
maintainers = [

maintainers = [
"reworkd"
]

readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.11"
fastapi = "^0.98.0"
boto3 = "^1.28.51"
uvicorn = { version = "^0.22.0", extras = ["standard"] }
pydantic = { version = "<2.0", extras = ["dotenv"] }
yarl = "^1.9.2"
ujson = "^5.8.0"
sqlalchemy = { version = "^2.0.21", extras = ["mypy", "asyncio"] }
aiomysql = "^0.1.1"
mysqlclient = "^2.2.0"
httptools = "^0.5.0"
sentry-sdk = "^1.31.0"
loguru = "^0.7.2"
aiokafka = "^0.8.1"
Expand All @@ -33,12 +34,12 @@ replicate = "^0.8.4"
lanarky = "^0.7.15"
tiktoken = "^0.5.1"
grpcio = "^1.58.0"
pinecone-client = "^2.2.4"
python-multipart = "^0.0.6"
aws-secretsmanager-caching = "^1.1.1.5"
botocore = "^1.31.51"
stripe = "^5.5.0"
cryptography = "^41.0.4"
httpx = "^0.25.0"


[tool.poetry.dev-dependencies]
Expand All @@ -58,6 +59,7 @@ pytest-env = "^0.8.2"
[tool.poetry.group.dev.dependencies]
dotmap = "^1.3.30"
pytest-mock = "^3.10.0"
httpx = "^0.24.1"
pytest-asyncio = "^0.21.0"
mypy = "^1.4.1"
types-requests = "^2.31.0.1"
Expand All @@ -66,7 +68,7 @@ types-pytz = "^2023.3.0.0"
[tool.isort]
profile = "black"
multi_line_output = 3
src_paths = ["reworkd_platform", ]
src_paths = ["reworkd_platform"]

[tool.mypy]
strict = true
Expand Down Expand Up @@ -96,3 +98,4 @@ env = [
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

4 changes: 2 additions & 2 deletions platform/reworkd_platform/db/crud/oauth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import secrets
from typing import Optional, Dict
from typing import Dict, Optional

from fastapi import Depends
from sqlalchemy import select, func
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession

from reworkd_platform.db.crud.base import BaseCrud
Expand Down
4 changes: 2 additions & 2 deletions platform/reworkd_platform/db/crud/organization.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# from
from typing import Optional, List
from typing import List, Optional

from fastapi import Depends
from pydantic import BaseModel
from sqlalchemy import select, and_
from sqlalchemy import and_, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import aliased

Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/db/crud/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from sqlalchemy import select, and_
from sqlalchemy import and_, select
from sqlalchemy.orm import selectinload

from reworkd_platform.db.crud.base import BaseCrud
Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/db/models/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import String, Text, func, DateTime
from sqlalchemy import DateTime, String, Text, func
from sqlalchemy.orm import mapped_column

from reworkd_platform.db.base import Base
Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/db/models/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import String, DateTime
from sqlalchemy import DateTime, String
from sqlalchemy.orm import mapped_column

from reworkd_platform.db.base import TrackedModel
Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/db/models/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

from sqlalchemy import DateTime, ForeignKey, Index, String, text
from sqlalchemy.orm import Mapped, relationship, mapped_column
from sqlalchemy.orm import Mapped, mapped_column, relationship

from reworkd_platform.db.base import Base

Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/schemas/agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Literal, Dict, Optional, Any, List
from typing import Any, Dict, List, Literal, Optional

from pydantic import BaseModel, Field, validator

Expand Down
4 changes: 1 addition & 3 deletions platform/reworkd_platform/services/pinecone/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

from langchain.embeddings import OpenAIEmbeddings
from langchain.embeddings.base import Embeddings
from langchain.document_loaders import PyPDFLoader
from pinecone import Index # import doesnt work on plane wifi
from pydantic import BaseModel
from langchain.text_splitter import RecursiveCharacterTextSplitter

from reworkd_platform.settings import settings
from reworkd_platform.timer import timed_function
from reworkd_platform.web.api.memory.memory import AgentMemory
import os

OPENAI_EMBEDDING_DIM = 1536

Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/services/serp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Any, Dict
from typing import Any, Dict, Optional

import requests

Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/services/ssl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ssl import create_default_context, SSLContext
from ssl import SSLContext, create_default_context
from typing import List, Optional

from reworkd_platform.settings import Settings
Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import platform
from pathlib import Path
from tempfile import gettempdir
from typing import List, Optional, Literal, Union
from typing import List, Literal, Optional, Union

from pydantic import BaseSettings
from yarl import URL
Expand Down
6 changes: 3 additions & 3 deletions platform/reworkd_platform/tests/agent/test_model_factory.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import itertools

import pytest
from langchain.chat_models import ChatOpenAI, AzureChatOpenAI
from langchain.chat_models import AzureChatOpenAI, ChatOpenAI

from reworkd_platform.schemas import ModelSettings, UserBase
from reworkd_platform.settings import Settings
from reworkd_platform.web.api.agent.model_factory import (
get_base_and_headers,
WrappedAzureChatOpenAI,
create_model,
WrappedChatOpenAI,
create_model,
get_base_and_headers,
)


Expand Down
5 changes: 1 addition & 4 deletions platform/reworkd_platform/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest
from openai.error import (
ServiceUnavailableError,
InvalidRequestError,
)
from openai.error import InvalidRequestError, ServiceUnavailableError

from reworkd_platform.schemas.agent import ModelSettings
from reworkd_platform.web.api.agent.helpers import openai_error_handler
Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Any
from typing import Any, Dict

import pytest

Expand Down
4 changes: 2 additions & 2 deletions platform/reworkd_platform/web/api/agent/helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Any, Callable, TypeVar, Dict
from typing import Any, Callable, Dict, TypeVar

from langchain import BasePromptTemplate, LLMChain
from langchain.chat_models.base import BaseChatModel
from langchain.schema import BaseOutputParser, OutputParserException
from openai.error import (
AuthenticationError,
InvalidRequestError,
RateLimitError,
ServiceUnavailableError,
InvalidRequestError,
)

from reworkd_platform.schemas.agent import ModelSettings
Expand Down
4 changes: 2 additions & 2 deletions platform/reworkd_platform/web/api/agent/model_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, Tuple, Optional, Union, Type
from typing import Any, Dict, Optional, Tuple, Type, Union

from langchain.chat_models import ChatOpenAI, AzureChatOpenAI
from langchain.chat_models import AzureChatOpenAI, ChatOpenAI
from pydantic import Field

from reworkd_platform.schemas.agent import LLM_Model, ModelSettings
Expand Down
1 change: 0 additions & 1 deletion platform/reworkd_platform/web/api/agent/tools/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
summarize_with_sources,
)


# Search google via serper.dev. Adapted from LangChain
# https://github.com/hwchase17/langchain/blob/master/langchain/utilities

Expand Down
5 changes: 1 addition & 4 deletions platform/reworkd_platform/web/api/agent/tools/sidsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
from reworkd_platform.settings import settings
from reworkd_platform.web.api.agent.stream_mock import stream_string
from reworkd_platform.web.api.agent.tools.tool import Tool
from reworkd_platform.web.api.agent.tools.utils import (
Snippet,
summarize_sid,
)
from reworkd_platform.web.api.agent.tools.utils import Snippet, summarize_sid


async def _sid_search_results(
Expand Down
5 changes: 2 additions & 3 deletions platform/reworkd_platform/web/api/agent/tools/tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List, Type

from reworkd_platform.db.crud.oauth import OAuthCrud
from reworkd_platform.schemas.user import UserBase
from reworkd_platform.web.api.agent.tools.code import Code
from reworkd_platform.web.api.agent.tools.conclude import Conclude
from reworkd_platform.web.api.agent.tools.image import Image
Expand All @@ -8,9 +10,6 @@
from reworkd_platform.web.api.agent.tools.sidsearch import SID
from reworkd_platform.web.api.agent.tools.tool import Tool

from reworkd_platform.db.crud.oauth import OAuthCrud
from reworkd_platform.schemas.user import UserBase


async def get_user_tools(
tool_names: List[str], user: UserBase, crud: OAuthCrud
Expand Down
6 changes: 3 additions & 3 deletions platform/reworkd_platform/web/api/agent/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from pydantic import BaseModel

from reworkd_platform.schemas.agent import (
AgentChat,
AgentRun,
AgentSummarize,
AgentTaskAnalyze,
AgentTaskExecute,
AgentTaskCreate,
AgentSummarize,
AgentChat,
AgentTaskExecute,
NewTasksResponse,
)
from reworkd_platform.web.api.agent.agent_service.agent_service import AgentService
Expand Down
4 changes: 2 additions & 2 deletions platform/reworkd_platform/web/api/metadata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Optional
from urllib.parse import urlparse, urljoin
from urllib.parse import urljoin, urlparse

from bs4 import BeautifulSoup
from fastapi import APIRouter
from httpx import AsyncClient, RequestError, HTTPStatusError
from httpx import AsyncClient, HTTPStatusError, RequestError
from pydantic import BaseModel, Field

from reworkd_platform.web.api.errors import PlatformaticError
Expand Down
2 changes: 1 addition & 1 deletion platform/reworkd_platform/web/api/router.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.routing import APIRouter

from reworkd_platform.web.api import agent, auth, models, monitoring, metadata
from reworkd_platform.web.api import agent, auth, metadata, models, monitoring

api_router = APIRouter()
api_router.include_router(monitoring.router, prefix="/monitoring", tags=["monitoring"])
Expand Down

0 comments on commit a96f66c

Please sign in to comment.