41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
import asyncio
|
|
import os
|
|
import httpx
|
|
from openai import AsyncOpenAI
|
|
|
|
async def test_openai():
|
|
proxy_url = os.environ.get("http_proxy")
|
|
print(f"Using proxy: {proxy_url}")
|
|
|
|
http_client = httpx.AsyncClient(
|
|
proxy=proxy_url,
|
|
timeout=30.0,
|
|
follow_redirects=True
|
|
)
|
|
|
|
client = AsyncOpenAI(
|
|
base_url="https://api.gpt.ge/v1",
|
|
api_key=os.environ.get("V3_API_KEY"),
|
|
http_client=http_client
|
|
)
|
|
|
|
print("Sending request...")
|
|
try:
|
|
response = await client.chat.completions.create(
|
|
model="gpt-3.5-turbo",
|
|
messages=[{"role": "user", "content": "Hello"}],
|
|
max_tokens=5
|
|
)
|
|
print(f"Response: {response.choices[0].message.content}")
|
|
except Exception as e:
|
|
import traceback
|
|
traceback.print_exc()
|
|
print(f"Error: {e}")
|
|
finally:
|
|
await http_client.aclose()
|
|
|
|
if __name__ == "__main__":
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
asyncio.run(test_openai())
|