Update main.py
Browse files
main.py
CHANGED
@@ -21,7 +21,7 @@ MAX_TOKENS = 2000
|
|
21 |
TEMPERATURE = 0.7
|
22 |
TOP_P = 0.95
|
23 |
|
24 |
-
|
25 |
messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
26 |
|
27 |
for val in history:
|
@@ -32,7 +32,7 @@ async def respond(message, history: list[tuple[str, str]]):
|
|
32 |
|
33 |
messages.append({"role": "user", "content": message})
|
34 |
|
35 |
-
response =
|
36 |
messages,
|
37 |
max_tokens=MAX_TOKENS,
|
38 |
stream=True,
|
@@ -40,12 +40,8 @@ async def respond(message, history: list[tuple[str, str]]):
|
|
40 |
top_p=TOP_P,
|
41 |
)
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
yield message.choices[0].delta.content
|
46 |
-
else:
|
47 |
-
for message in response: # Handle regular iteration
|
48 |
-
yield message.choices[0].delta.content
|
49 |
|
50 |
@app.post("/generate/")
|
51 |
async def generate(request: Request):
|
@@ -58,7 +54,7 @@ async def generate(request: Request):
|
|
58 |
|
59 |
response_generator = respond(prompt, history)
|
60 |
final_response = ""
|
61 |
-
|
62 |
final_response += part
|
63 |
|
64 |
return JSONResponse(content={"response": final_response})
|
|
|
21 |
TEMPERATURE = 0.7
|
22 |
TOP_P = 0.95
|
23 |
|
24 |
+
def respond(message, history: list[tuple[str, str]]):
|
25 |
messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
26 |
|
27 |
for val in history:
|
|
|
32 |
|
33 |
messages.append({"role": "user", "content": message})
|
34 |
|
35 |
+
response = client.chat_completion(
|
36 |
messages,
|
37 |
max_tokens=MAX_TOKENS,
|
38 |
stream=True,
|
|
|
40 |
top_p=TOP_P,
|
41 |
)
|
42 |
|
43 |
+
for message in response: # Handle regular iteration
|
44 |
+
yield message.choices[0].delta.content
|
|
|
|
|
|
|
|
|
45 |
|
46 |
@app.post("/generate/")
|
47 |
async def generate(request: Request):
|
|
|
54 |
|
55 |
response_generator = respond(prompt, history)
|
56 |
final_response = ""
|
57 |
+
for part in response_generator:
|
58 |
final_response += part
|
59 |
|
60 |
return JSONResponse(content={"response": final_response})
|