|
|
|
@ -306,7 +306,6 @@ class DouyinLiveWebReply:
|
|
|
|
|
def __init__(self, queue: PromptQueue):
|
|
|
|
|
self.queue = queue
|
|
|
|
|
self.system_text_list = []
|
|
|
|
|
self.session_id = 0
|
|
|
|
|
self.backend_token = ''
|
|
|
|
|
self.live_chat_config = LiveChatConfig()
|
|
|
|
|
self.punctuation = ",.!;:,。!?:;"
|
|
|
|
@ -328,9 +327,10 @@ class DouyinLiveWebReply:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _gen():
|
|
|
|
|
response = requests.post(f'{self.live_chat_config.ollama_address}/live-digital-avatar-manage/ollama/generate', json=payload,
|
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
|
stream=True)
|
|
|
|
|
response = requests.post(
|
|
|
|
|
f'{self.live_chat_config.ollama_address}/live-digital-avatar-manage/ollama/generate', json=payload,
|
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
|
stream=True)
|
|
|
|
|
buffer = ''
|
|
|
|
|
for line in response.iter_lines():
|
|
|
|
|
if not line:
|
|
|
|
@ -351,9 +351,10 @@ class DouyinLiveWebReply:
|
|
|
|
|
if stream:
|
|
|
|
|
return _gen()
|
|
|
|
|
else:
|
|
|
|
|
response = requests.post(f'{self.live_chat_config.ollama_address}/live-digital-avatar-manage/ollama/generate', json=payload,
|
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
|
timeout=10).content.decode()[5:]
|
|
|
|
|
response = requests.post(
|
|
|
|
|
f'{self.live_chat_config.ollama_address}/live-digital-avatar-manage/ollama/generate', json=payload,
|
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
|
timeout=10).content.decode()[5:]
|
|
|
|
|
response = json.loads(response)
|
|
|
|
|
return response['message']['content']
|
|
|
|
|
|
|
|
|
@ -370,7 +371,7 @@ class DouyinLiveWebReply:
|
|
|
|
|
f'{self.live_chat_config.livetalking_address}/human',
|
|
|
|
|
json={
|
|
|
|
|
"type": "echo",
|
|
|
|
|
"sessionid": self.session_id,
|
|
|
|
|
"sessionid": self.live_chat_config.livetalking_sessionid,
|
|
|
|
|
"text": text
|
|
|
|
|
},
|
|
|
|
|
timeout=5
|
|
|
|
@ -381,9 +382,12 @@ class DouyinLiveWebReply:
|
|
|
|
|
优先从用户交互队列中取提示词,如果没有用户交互的数据,则输出系统提示词
|
|
|
|
|
"""
|
|
|
|
|
live_chat_config.update_chat_enable_status()
|
|
|
|
|
logger.info(f'livetalking address -> {self.live_chat_config.livetalking_address}')
|
|
|
|
|
logger.info(f'ollama_address -> {self.live_chat_config.ollama_address}')
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
is_speaking = requests.post(f'{self.live_chat_config.livetalking_address}/is_speaking', json={'sessionid': self.session_id},
|
|
|
|
|
is_speaking = requests.post(f'{self.live_chat_config.livetalking_address}/is_speaking',
|
|
|
|
|
json={'sessionid': self.live_chat_config.livetalking_sessionid},
|
|
|
|
|
timeout=5).json()['data']
|
|
|
|
|
if is_speaking:
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
@ -391,23 +395,44 @@ class DouyinLiveWebReply:
|
|
|
|
|
|
|
|
|
|
prompt_data = self.queue.get(False)
|
|
|
|
|
if prompt_data is not None:
|
|
|
|
|
product_name, product_specification, product_description = self.live_chat_config.product_info
|
|
|
|
|
# live_chat: 弹幕
|
|
|
|
|
message_type, prompt, live_chat = prompt_data
|
|
|
|
|
if message_type == MessageType.ENTER_LIVE_ROOM.value and \
|
|
|
|
|
random.random() >= self.live_chat_config.enter_live_room_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
elif message_type == MessageType.FOLLOW.value and \
|
|
|
|
|
random.random() >= self.live_chat_config.follow_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
elif message_type == MessageType.LIKE.value and \
|
|
|
|
|
random.random() >= self.live_chat_config.like_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
elif message_type == MessageType.GIFT.value and \
|
|
|
|
|
random.random() >= self.live_chat_config.gift_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
elif message_type == MessageType.CHAT.value and \
|
|
|
|
|
random.random() >= self.live_chat_config.chat_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
if message_type == MessageType.ENTER_LIVE_ROOM.value:
|
|
|
|
|
if random.random() >= self.live_chat_config.enter_live_room_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
prompt = prompt.format(product_name=product_name,
|
|
|
|
|
product_specification=product_specification,
|
|
|
|
|
product_description=product_description)
|
|
|
|
|
elif message_type == MessageType.FOLLOW.value:
|
|
|
|
|
if random.random() >= self.live_chat_config.follow_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
prompt = prompt.format(product_name=product_name,
|
|
|
|
|
product_specification=product_specification,
|
|
|
|
|
product_description=product_description)
|
|
|
|
|
elif message_type == MessageType.LIKE.value:
|
|
|
|
|
if random.random() >= self.live_chat_config.like_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
prompt = prompt.format(product_name=product_name,
|
|
|
|
|
product_specification=product_specification,
|
|
|
|
|
product_description=product_description)
|
|
|
|
|
elif message_type == MessageType.GIFT.value:
|
|
|
|
|
if random.random() >= self.live_chat_config.gift_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
prompt = prompt.format(product_name=product_name,
|
|
|
|
|
product_specification=product_specification,
|
|
|
|
|
product_description=product_description)
|
|
|
|
|
elif message_type == MessageType.CHAT.value:
|
|
|
|
|
if random.random() >= self.live_chat_config.chat_prob / 100:
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
prompt = prompt.format(product_name=product_name,
|
|
|
|
|
product_specification=product_specification,
|
|
|
|
|
product_description=product_description)
|
|
|
|
|
if live_chat is not None:
|
|
|
|
|
logger.info(f'弹幕: {live_chat}')
|
|
|
|
|
llm_output = self._llm(self.live_chat_config.product_related_prompt.format(content=live_chat))
|
|
|
|
|