omkar56 commited on
Commit
dba144a
1 Parent(s): 9cc9a40

Update main.py

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