33 lines
987 B
Python
33 lines
987 B
Python
import os
|
|
import json
|
|
import urllib.request
|
|
|
|
_env_path = os.path.join(os.path.dirname(__file__), '.env')
|
|
if os.path.exists(_env_path):
|
|
with open(_env_path) as f:
|
|
for line in f:
|
|
if '=' in line and not line.startswith('#'):
|
|
k, v = line.strip().split('=', 1)
|
|
os.environ.setdefault(k, v)
|
|
|
|
SARVAM_API_KEY = os.getenv("SARVAM_API_KEY", "")
|
|
|
|
payload = json.dumps({
|
|
"model": "sarvam-2b", # let's test sarvam-2b vs sarvam-105b
|
|
"temperature": 0.1,
|
|
"max_tokens": 1000,
|
|
"messages": [
|
|
{"role": "user", "content": "Doctor: Hello. Patient: Hi. Split into turns."}
|
|
]
|
|
}).encode('utf-8')
|
|
|
|
req = urllib.request.Request(
|
|
'https://api.sarvam.ai/v1/chat/completions',
|
|
data=payload,
|
|
headers={'Content-Type': 'application/json', 'api-subscription-key': SARVAM_API_KEY}
|
|
)
|
|
|
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
data = json.loads(resp.read().decode('utf-8'))
|
|
print(json.dumps(data, indent=2))
|