Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -33,29 +33,34 @@ def generate_text(
|
|
33 |
body: dict = Body(...),
|
34 |
api_key: str = Depends(get_api_key)
|
35 |
):
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
33 |
body: dict = Body(...),
|
34 |
api_key: str = Depends(get_api_key)
|
35 |
):
|
36 |
+
try:
|
37 |
+
print("[request]",request)
|
38 |
+
print("[body]",body)
|
39 |
+
prompt = body.get("prompt", "")
|
40 |
+
system_prompt = body.get("sysPrompt", "")
|
41 |
+
temperature = body.get("temperature", 0.5)
|
42 |
+
top_p = body.get("top_p", 0.95)
|
43 |
+
max_new_tokens = body.get("max_new_tokens",512)
|
44 |
+
repetition_penalty = body.get("repetition_penalty", 1.0)
|
45 |
+
print(f"temperature + {temperature}")
|
46 |
+
history = [] # You might need to handle this based on your actual usage
|
47 |
+
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
48 |
+
|
49 |
+
stream = client.text_generation(
|
50 |
+
formatted_prompt,
|
51 |
+
temperature=temperature,
|
52 |
+
max_new_tokens=max_new_tokens,
|
53 |
+
top_p=top_p,
|
54 |
+
repetition_penalty=repetition_penalty,
|
55 |
+
do_sample=True,
|
56 |
+
seed=random.randint(0, 10**7),
|
57 |
+
stream=False,
|
58 |
+
details=False,
|
59 |
+
return_full_text=False
|
60 |
+
)
|
61 |
+
|
62 |
+
return {"generated_text": stream}
|
63 |
+
except error:
|
64 |
+
print("[error Request]", request)
|
65 |
+
return {error}
|
66 |
+
|