Reuse client and use client factory

This commit is contained in:
PeachyDelight 2022-06-19 04:04:14 +02:00
parent 5e50bccd53
commit 970903c3c0
1 changed files with 12 additions and 10 deletions

View File

@ -4,6 +4,8 @@ import sqlite3
from random import expovariate
import typing
import aiohttp
from utils import http_session_factory
async def make_sentence(cfg):
# set default
@ -81,8 +83,8 @@ async def make_sentence(cfg):
# using aiohttp
post = None
async with http_session_factory() as session:
while post is None:
async with aiohttp.ClientSession() as session:
async with session.post(
"https://api.textsynth.com/v1/engines/{}/completions".format(cfg["textsynth_engine_id"]),
headers={