minzo456 commited on
Commit
58a70b2
·
verified ·
1 Parent(s): f0c6677

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -36
app.py CHANGED
@@ -1,51 +1,32 @@
1
  from fastapi import FastAPI, Request
2
- import requests
3
- import json
4
  from fastapi.middleware.cors import CORSMiddleware
5
- import uvicorn
6
 
7
  app = FastAPI()
8
- app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
9
 
10
- # 🔱 GLM-5.1 CONFIGURATION
 
 
 
 
 
 
 
11
  API_URL = "https://api.us-west-2.modal.direct/v1/chat/completions"
12
  API_KEY = "modalresearch_0yKf_z9azDFpOXr-W1N1WsmBUgXf6Ux-yvpVsFQWzks"
13
- MODEL_ID = "zai-org/GLM-5.1-FP8"
14
 
15
  @app.post("/generate")
16
  async def generate(request: Request):
17
  try:
18
  data = await request.json()
19
- user_prompt = data.get("prompt")
20
-
21
- # 🔱 Payload for GLM-5.1
22
  payload = {
23
- "model": MODEL_ID,
24
- "messages": [
25
- {"role": "system", "content": "You are Elephant AI Pro, a master-level coding assistant built by MINZO-PRIME. Provide highly detailed and functional code."},
26
- {"role": "user", "content": user_prompt}
27
- ],
28
- "max_tokens": 1024,
29
- "temperature": 0.6
30
- }
31
-
32
- headers = {
33
- "Authorization": f"Bearer {API_KEY}",
34
- "Content-Type": "application/json"
35
  }
36
-
37
- # 🔱 Fast-Inference Request
38
- response = requests.post(API_URL, headers=headers, json=payload, timeout=60)
39
- result = response.json()
40
-
41
- if "choices" in result:
42
- ai_response = result["choices"][0]["message"]["content"]
43
- return {"response": ai_response}
44
- else:
45
- return {"response": "SYSTEM ERROR: API Node non-responsive. Check Token status."}
46
-
47
  except Exception as e:
48
- return {"error": str(e)}
49
-
50
- if __name__ == "__main__":
51
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  from fastapi import FastAPI, Request
 
 
2
  from fastapi.middleware.cors import CORSMiddleware
3
+ import requests
4
 
5
  app = FastAPI()
 
6
 
7
+ # 🔱 සියලුම සන්නිවේදන බාධක ඉවත් කිරීම
8
+ app.add_middleware(
9
+ CORSMiddleware,
10
+ allow_origins=["*"],
11
+ allow_methods=["*"],
12
+ allow_headers=["*"],
13
+ )
14
+
15
  API_URL = "https://api.us-west-2.modal.direct/v1/chat/completions"
16
  API_KEY = "modalresearch_0yKf_z9azDFpOXr-W1N1WsmBUgXf6Ux-yvpVsFQWzks"
 
17
 
18
  @app.post("/generate")
19
  async def generate(request: Request):
20
  try:
21
  data = await request.json()
22
+ headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
 
 
23
  payload = {
24
+ "model": "zai-org/GLM-5.1-FP8",
25
+ "messages": [{"role": "user", "content": data.get("prompt")}],
26
+ "max_tokens": 1024
 
 
 
 
 
 
 
 
 
27
  }
28
+ # සර්වර් එක හරහා යන නිසා බ්‍රවුසරයට බාධා කළ නොහැක
29
+ response = requests.post(API_URL, headers=headers, json=payload)
30
+ return response.json()
 
 
 
 
 
 
 
 
31
  except Exception as e:
32
+ return {"error": str(e)}