MingDoan's picture
feat: Big Update
3a63794
raw
history blame
960 Bytes
import time
from services.api_service import post_data
from controllers.fw import get_fw_query_params
def format_response(message: str):
return message.replace("\\n", "\n")
def chat_controller(prompt: str, histories: list[list], fw_option: str = 'none'):
# Format histories
f_histories = []
for history in histories:
f_histories.append({
"role": "user",
"content": history[0]
})
f_histories.append({
"role": "assistant",
"content": history[1]
})
# Send request
request_data = {
"prompt": prompt,
"histories": f_histories
}
response = post_data(
f"/api/chats/{get_fw_query_params(fw_option)}", json=request_data)
if response is None:
return None
message = format_response(response['message'])
# Yielding response
for i in range(len(message)):
time.sleep(0.03)
yield message[: i+1]