Abhaykoul commited on
Commit
064358f
·
verified ·
1 Parent(s): d123808

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import openai
4
+ from dotenv import load_dotenv
5
+ import requests
6
+ import schedule
7
+ from rich import print
8
+
9
+ load_dotenv()
10
+
11
+ # Load environment variables
12
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
13
+ OPENAI_BASE_URL = os.getenv("OPENAI_BASE_URL", "https://api.helpingai.co/v1")
14
+
15
+ if not OPENAI_API_KEY:
16
+ raise ValueError("OPENAI_API_KEY must be set in .env file")
17
+
18
+
19
+ # Initialize OpenAI client
20
+ client = openai.OpenAI(
21
+ api_key=OPENAI_API_KEY,
22
+ base_url=OPENAI_BASE_URL
23
+ )
24
+
25
+
26
+ # Hardcoded list of models
27
+ MODELS = [
28
+ "HelpingAI2.5-10B",
29
+ "HelpingAI2.5-2B",
30
+ "HelpingAI2.5-5B",
31
+ "HelpingAI-flash",
32
+ "HelpingAI2-9B",
33
+ "HelpingAI2-6B",
34
+ "HelpingAI-15B",
35
+ "HELVETE",
36
+ "HELVETE-X",
37
+ "Priya-3B",
38
+ "HelpingAI2.5-10B-1M",
39
+ "Cipher-20B",
40
+ "HelpingAI2-3B"
41
+ ]
42
+
43
+
44
+ # Function to make a request to a model with retry mechanism
45
+ def make_request(model_name):
46
+ max_retries = 3
47
+ retry_delay = 10 # seconds
48
+ for attempt in range(max_retries):
49
+ try:
50
+ print(f"Requesting model: {model_name}")
51
+ response = client.chat.completions.create(
52
+ model=model_name,
53
+ messages=[{"role": "user", "content": "Hello, how are you?"}]
54
+ )
55
+ print(f"Response from {model_name}: {response.choices[0].message.content}\n")
56
+ break # Break if successful
57
+ except Exception as e:
58
+ print(f"Error with model {model_name}: {e}")
59
+ if attempt < max_retries - 1:
60
+ print(f"Retrying in {retry_delay} seconds...")
61
+ time.sleep(retry_delay)
62
+ else:
63
+ print("Max retries reached. Could not get a response.")
64
+
65
+
66
+ def job():
67
+ for model in MODELS:
68
+ make_request(model)
69
+
70
+
71
+ if __name__ == "__main__":
72
+ schedule.every(5).minutes.do(job)
73
+ while True:
74
+ schedule.run_pending()
75
+ time.sleep(1)