-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from agn-7/async
- Loading branch information
Showing
17 changed files
with
283 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
# basic | ||
target: auto | ||
threshold: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, AsyncEngine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from .config import settings | ||
|
||
engine = create_engine( | ||
settings.SQLALCHEMY_DATABASE_URI.unicode_string(), pool_pre_ping=True | ||
engine: AsyncEngine = create_async_engine( | ||
settings.SQLALCHEMY_DATABASE_URI.unicode_string() | ||
) | ||
async_session = sessionmaker( | ||
autocommit=False, | ||
autoflush=False, | ||
future=True, | ||
bind=engine, | ||
class_=AsyncSession, | ||
expire_on_commit=False, | ||
) | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, future=True, bind=engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import g4f | ||
import traceback | ||
|
||
g4f.debug.logging = True | ||
g4f.check_version = False | ||
|
||
|
||
def generate_ai_response( | ||
content: str, model: str = "GPT4" | ||
) -> str: # TODO: use async version for future | ||
return g4f.ChatCompletion.create( | ||
model=g4f.models.gpt_4 if model == "GPT4" else g4f.models.gpt_35_turbo, | ||
messages=[{"role": "human", "content": content}], | ||
) | ||
async def generate_ai_response( | ||
content: str, model: g4f.Model = g4f.models.default | ||
) -> str: | ||
try: | ||
response = await g4f.ChatCompletion.create_async( | ||
model=model, | ||
messages=[{"role": "human", "content": content}], | ||
) | ||
return response | ||
except Exception: | ||
traceback.print_exc() | ||
return "error!" |
Oops, something went wrong.