Hivra commited on
Commit
b8c5c95
·
verified ·
1 Parent(s): 11d279c

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +35 -0
main.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, time, uuid
2
+ from fastapi import FastAPI, HTTPException
3
+ from meta_ai_api import MetaAI
4
+
5
+ app = FastAPI()
6
+ # Read model name from env
7
+ MODEL = os.getenv("MODEL_NAME", "llama-3-70b")
8
+
9
+ # Init the MetaAI wrapper
10
+ meta = MetaAI()
11
+
12
+ @app.post("/v1/chat/completions")
13
+ async def chat_completions(body: dict):
14
+ msgs = body.get("messages")
15
+ if not msgs:
16
+ raise HTTPException(400, "messages field is required")
17
+
18
+ # Build a single prompt
19
+ prompt = "\n".join(f"{m['role']}: {m['content']}" for m in msgs)
20
+ resp = meta.prompt(message=prompt)
21
+
22
+ return {
23
+ "id": f"meta-{uuid.uuid4()}",
24
+ "object": "chat.completion",
25
+ "created": int(time.time()),
26
+ "model": MODEL,
27
+ "choices": [
28
+ {
29
+ "index": 0,
30
+ "message": {"role": "assistant", "content": resp["message"]},
31
+ "finish_reason": "stop"
32
+ }
33
+ ],
34
+ "usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0}
35
+ }