mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 19:04:47 +00:00
21 lines
526 B
Python
21 lines
526 B
Python
import os
|
|
|
|
import httpx
|
|
from openai import OpenAI
|
|
|
|
# Requires `pip install "httpx[socks]"` and a running Tor proxy on port 9050
|
|
client = OpenAI(
|
|
api_key=os.environ.get("TOKEN"),
|
|
base_url=os.environ.get("ONION_URL", "http://roustrjfsdgfiueghsklchg.onion/v1"),
|
|
http_client=httpx.Client(proxies="socks5://localhost:9050"),
|
|
)
|
|
|
|
print(
|
|
client.chat.completions.create(
|
|
model="openai/gpt-4o-mini",
|
|
messages=[{"role": "user", "content": "Hello from Tor!"}],
|
|
)
|
|
.choices[0]
|
|
.message.content
|
|
)
|