-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (24 loc) · 954 Bytes
/
Copy pathmain.py
File metadata and controls
36 lines (24 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import argparse
import os
import sys
from openai import OpenAI
API_KEY = os.getenv("OPENROUTER_API_KEY")
BASE_URL = os.getenv("OPENROUTER_BASE_URL", default="https://openrouter.ai/api/v1")
def main():
p = argparse.ArgumentParser()
p.add_argument("-p", required=True)
args = p.parse_args()
if not API_KEY:
raise RuntimeError("OPENROUTER_API_KEY is not set")
client = OpenAI(api_key=API_KEY, base_url=BASE_URL)
chat = client.chat.completions.create(
model="anthropic/claude-haiku-4.5",
messages=[{"role": "user", "content": args.p}],
)
if not chat.choices or len(chat.choices) == 0:
raise RuntimeError("no choices in response")
# You can use print statements as follows for debugging, they'll be visible when running tests.
print("Logs from your program will appear here!", file=sys.stderr)
print(chat.choices[0].message.content)
if __name__ == "__main__":
main()