-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathai_ml_client.py
43 lines (37 loc) · 1.43 KB
/
ai_ml_client.py
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
37
38
39
40
41
42
43
import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
class AIMLClient:
def __init__(self):
self.api = OpenAI(
api_key=os.getenv("AI_ML_API_KEY"),
base_url="https://api.aimlapi.com/v1"
)
def generate_response(self, prompt, model="o1-preview", max_tokens=1000):
try:
completion = self.api.chat.completions.create(
model=model, # Placeholder, replace with actual model name when available
messages=[
{"role": "system", "content": "You are an AI assistant specialized in web development and project management."},
{"role": "user", "content": prompt}
],
max_tokens=max_tokens,
temperature=0.7
)
return completion.choices[0].message.content
except Exception as e:
print(f"Error generating response: {str(e)}")
return None
def choose_model(self, task_complexity):
if task_complexity == "high":
return "o1-preview" # Placeholder
else:
return "o1-mini" # Placeholder
ai_ml_client = AIMLClient()
# Example usage
if __name__ == "__main__":
prompt = "Explain the key components of a modern web application architecture."
model = ai_ml_client.choose_model("high")
response = ai_ml_client.generate_response(prompt, model)
print(response)