Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
API_URL = "https://api.typegpt.net/v1/chat/completions"
|
4 |
+
API_KEY = "sk-XzS5hhsa3vpIcRLz3prQirBQXOx2hPydPzSpzdRcE1YddnNm"
|
5 |
+
BACKEND_MODEL = "pixtral-large-latest"
|
6 |
+
|
7 |
+
# Define virtual models with system prompts
|
8 |
+
SYSTEM_PROMPTS = {
|
9 |
+
"gpt-3.5": "You are ChatGPT, a helpful assistant.",
|
10 |
+
"claude": "You are Claude, known for being careful, ethical, and thoughtful.",
|
11 |
+
"mistral": "You are Mistral, known for giving concise and smart answers.",
|
12 |
+
"bard": "You are Bard, a friendly and knowledgeable Google AI assistant."
|
13 |
+
}
|
14 |
+
|
15 |
+
def generate_response(model_label: str, user_prompt: str):
|
16 |
+
if model_label not in SYSTEM_PROMPTS:
|
17 |
+
raise ValueError(f"Unknown model label '{model_label}'. Valid options: {', '.join(SYSTEM_PROMPTS.keys())}")
|
18 |
+
|
19 |
+
system_prompt = SYSTEM_PROMPTS[model_label]
|
20 |
+
|
21 |
+
headers = {
|
22 |
+
"Authorization": f"Bearer {API_KEY}",
|
23 |
+
"Content-Type": "application/json"
|
24 |
+
}
|
25 |
+
|
26 |
+
payload = {
|
27 |
+
"model": BACKEND_MODEL,
|
28 |
+
"messages": [
|
29 |
+
{"role": "system", "content": system_prompt},
|
30 |
+
{"role": "user", "content": user_prompt}
|
31 |
+
]
|
32 |
+
}
|
33 |
+
|
34 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
35 |
+
|
36 |
+
if response.status_code == 200:
|
37 |
+
result = response.json()
|
38 |
+
return result["choices"][0]["message"]["content"]
|
39 |
+
else:
|
40 |
+
raise Exception(f"API error {response.status_code}: {response.text}")
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
print("🧠 Choose a virtual model:")
|
44 |
+
for name in SYSTEM_PROMPTS:
|
45 |
+
print(f" - {name}")
|
46 |
+
model = input("Model: ").strip()
|
47 |
+
|
48 |
+
print("\n👤 Enter your message:")
|
49 |
+
user_prompt = input("> ").strip()
|
50 |
+
|
51 |
+
try:
|
52 |
+
print("\n🤖 AI Response:")
|
53 |
+
print(generate_response(model, user_prompt))
|
54 |
+
except Exception as e:
|
55 |
+
print(f"❌ Error: {e}")
|