DevNumb commited on
Commit
cedc7b1
·
verified ·
1 Parent(s): 885bdb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -1,16 +1,26 @@
1
- from openai import OpenAI
2
  import os
3
 
4
- client = OpenAI(
5
- base_url="https://openrouter.ai/api/v1",
6
- api_key=os.getenv("OPENROUTER_API_KEY"),
7
- )
8
 
9
- resp = client.chat.completions.create(
10
- model="kwaipilot/kat-coder-pro:free",
11
- messages=[
12
- {"role": "user", "content": "What is the meaning of life?"}
13
- ]
 
 
 
 
 
 
 
 
 
14
  )
15
 
16
- print(resp.choices[0].message.content)
 
 
 
 
 
1
+ import requests
2
  import os
3
 
4
+ API_KEY = os.getenv("OPENROUTER_API_KEY")
 
 
 
5
 
6
+ response = requests.post(
7
+ "https://openrouter.ai/api/v1/chat/completions",
8
+ headers={
9
+ "Authorization": f"Bearer {API_KEY}",
10
+ "Content-Type": "application/json",
11
+ "HTTP-Referer": "https://example.com", # optional
12
+ "X-Title": "MyApp", # optional
13
+ },
14
+ json={
15
+ "model": "kwaipilot/kat-coder-pro:free",
16
+ "messages": [
17
+ {"role": "user", "content": "What is the meaning of life?"}
18
+ ]
19
+ }
20
  )
21
 
22
+ # Parse JSON
23
+ data = response.json()
24
+
25
+ # Extract reply text
26
+ print(data["choices"][0]["message"]["content"])