feat: openai socks proxy support
This commit is contained in:
@@ -16,12 +16,14 @@ class OfferReplyGenerator:
|
|||||||
model: str,
|
model: str,
|
||||||
system_prompt_file: Path,
|
system_prompt_file: Path,
|
||||||
timeout_seconds: int,
|
timeout_seconds: int,
|
||||||
|
proxy_url: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._api_base_url = api_base_url.rstrip("/")
|
self._api_base_url = api_base_url.rstrip("/")
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self._model = model
|
self._model = model
|
||||||
self._system_prompt = system_prompt_file.read_text(encoding="utf-8").strip()
|
self._system_prompt = system_prompt_file.read_text(encoding="utf-8").strip()
|
||||||
self._timeout_seconds = timeout_seconds
|
self._timeout_seconds = timeout_seconds
|
||||||
|
self._proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
|
||||||
|
|
||||||
async def generate_reply(self, offer: Offer) -> str:
|
async def generate_reply(self, offer: Offer) -> str:
|
||||||
return await asyncio.to_thread(self._generate_reply_sync, offer)
|
return await asyncio.to_thread(self._generate_reply_sync, offer)
|
||||||
@@ -41,6 +43,7 @@ class OfferReplyGenerator:
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
timeout=self._timeout_seconds,
|
timeout=self._timeout_seconds,
|
||||||
|
proxies=self._proxies,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
payload = response.json()
|
payload = response.json()
|
||||||
|
|||||||
3
main.py
3
main.py
@@ -136,6 +136,7 @@ async def main() -> None:
|
|||||||
model=settings.openai_model,
|
model=settings.openai_model,
|
||||||
system_prompt_file=settings.openai_system_prompt_file,
|
system_prompt_file=settings.openai_system_prompt_file,
|
||||||
timeout_seconds=settings.requests_timeout_seconds,
|
timeout_seconds=settings.requests_timeout_seconds,
|
||||||
|
proxy_url=settings.telegram_proxy_url,
|
||||||
)
|
)
|
||||||
dispatcher = build_dispatcher(reply_generator, published_offers_store)
|
dispatcher = build_dispatcher(reply_generator, published_offers_store)
|
||||||
|
|
||||||
@@ -177,4 +178,4 @@ async def main() -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user