Update app.py
Browse files
app.py
CHANGED
|
@@ -13,15 +13,15 @@ main.add_middleware(
|
|
| 13 |
allow_headers=["*"],
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
MODEL_ID = "google/gemma-3-1b-it"
|
| 18 |
-
print(f"🔱 Specialist, Upgrading to {MODEL_ID}...")
|
| 19 |
|
|
|
|
| 20 |
pipe = pipeline(
|
| 21 |
"text-generation",
|
| 22 |
model=MODEL_ID,
|
| 23 |
device_map="cpu",
|
| 24 |
-
torch_dtype=torch.
|
|
|
|
| 25 |
trust_remote_code=True
|
| 26 |
)
|
| 27 |
|
|
@@ -32,26 +32,18 @@ class ChatRequest(BaseModel):
|
|
| 32 |
async def chat(request_data: ChatRequest):
|
| 33 |
user_query = request_data.message.strip()
|
| 34 |
|
| 35 |
-
# Gemma 3 Chat Format
|
| 36 |
messages = [
|
| 37 |
{"role": "user", "content": user_query},
|
| 38 |
]
|
| 39 |
|
| 40 |
-
#
|
| 41 |
results = pipe(
|
| 42 |
messages,
|
| 43 |
-
max_new_tokens=
|
| 44 |
-
do_sample=
|
| 45 |
-
temperature=0.
|
| 46 |
-
|
| 47 |
)
|
| 48 |
|
| 49 |
-
# 🔱 පිළිතුර පමණක් වෙන් කර ගැනීම
|
| 50 |
reply = results[0]['generated_text'][-1]['content']
|
| 51 |
-
|
| 52 |
-
print(f"🔱 Inachi Response: {reply}")
|
| 53 |
-
return {"reply": reply}
|
| 54 |
-
|
| 55 |
-
@main.get("/")
|
| 56 |
-
def health():
|
| 57 |
-
return {"status": "Gemma-3 Powered Inachi Online"}
|
|
|
|
| 13 |
allow_headers=["*"],
|
| 14 |
)
|
| 15 |
|
| 16 |
+
MODEL_ID = "google/gemma-3-1b-it"
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# 🔱 Optimization 1: KV Cache භාවිතය (වේගය වැඩි කිරීමට)
|
| 19 |
pipe = pipeline(
|
| 20 |
"text-generation",
|
| 21 |
model=MODEL_ID,
|
| 22 |
device_map="cpu",
|
| 23 |
+
torch_dtype=torch.bfloat16, # CPU එක bfloat16 වලට කැමතියි
|
| 24 |
+
use_cache=True, # කලින් ජෙනරේට් කරපු ටෝකන් මතක තබා ගනී
|
| 25 |
trust_remote_code=True
|
| 26 |
)
|
| 27 |
|
|
|
|
| 32 |
async def chat(request_data: ChatRequest):
|
| 33 |
user_query = request_data.message.strip()
|
| 34 |
|
|
|
|
| 35 |
messages = [
|
| 36 |
{"role": "user", "content": user_query},
|
| 37 |
]
|
| 38 |
|
| 39 |
+
# 🔱 Optimization 2: Coding සඳහා ප්රමාණවත් ඉඩක් ලබා දීම
|
| 40 |
results = pipe(
|
| 41 |
messages,
|
| 42 |
+
max_new_tokens=1024, # 🔱 දැන් ඔයාට දිග කෝඩ් එකක් වුණත් ගන්න පුළුවන්
|
| 43 |
+
do_sample=False, # Coding වලට sample ඕනේ නැහැ, Greedy search එක වේගවත්
|
| 44 |
+
temperature=0.0, # වඩාත් නිවැරදි කෝඩ් එකක් සඳහා (Zero randomness)
|
| 45 |
+
pad_token_id=50256
|
| 46 |
)
|
| 47 |
|
|
|
|
| 48 |
reply = results[0]['generated_text'][-1]['content']
|
| 49 |
+
return {"reply": reply}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|