|
|
|
|
@ -6,6 +6,7 @@ from ai.utils.basic_func import * |
|
|
|
|
import datetime |
|
|
|
|
from django_redis import get_redis_connection |
|
|
|
|
from django.db.models import Q |
|
|
|
|
from ai.models import TestCinema |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -53,7 +54,7 @@ def show_main_process(zz_code=None, day_delta=None): |
|
|
|
|
|
|
|
|
|
# 获取排片数据 |
|
|
|
|
print('result:', result) |
|
|
|
|
if model.config_name in ['lmstudio_qwen3.6_35b','company_qwen3.5_35b']: |
|
|
|
|
if model.config_name in ['lmstudio_qwen3.6_35b', 'company_qwen3.5_35b']: |
|
|
|
|
result_obj = json.loads(result.replace('```json', '').replace('}\n```', '}').strip()) |
|
|
|
|
else: |
|
|
|
|
result_obj = json.loads(result.strip()) |
|
|
|
|
@ -71,6 +72,7 @@ def show_main_process(zz_code=None, day_delta=None): |
|
|
|
|
zz_code=cinema.zz_code, |
|
|
|
|
show_date=show_date, |
|
|
|
|
is_ai_show=True, |
|
|
|
|
is_manual_test=False, |
|
|
|
|
ai_model=model.config_name, |
|
|
|
|
template=template_show, |
|
|
|
|
temp_date=template_date, |
|
|
|
|
@ -88,6 +90,65 @@ def show_main_process(zz_code=None, day_delta=None): |
|
|
|
|
print(e) |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_manual_process(zz_code: str, show_date: str, prompt: str): |
|
|
|
|
cinema = TestCinema.objects.filter(zz_code=zz_code).first() |
|
|
|
|
ai = ShowAI(cinema, show_date) |
|
|
|
|
|
|
|
|
|
start = datetime.datetime.now() # 开始计时 |
|
|
|
|
result, message, tokens = ai.get_show_result_ai(prompt) |
|
|
|
|
end = datetime.datetime.now() # 结束计时 |
|
|
|
|
print('prompt:', prompt) |
|
|
|
|
print('result:', result) |
|
|
|
|
print('message:', message) |
|
|
|
|
print('tokens:', tokens) |
|
|
|
|
|
|
|
|
|
# 获取排片数据 |
|
|
|
|
print('result:', result) |
|
|
|
|
# 获取当前模型 |
|
|
|
|
model = AiModel.objects.filter(current_used=True).first() |
|
|
|
|
if model.config_name in ['lmstudio_qwen3.6_35b', 'company_qwen3.5_35b']: |
|
|
|
|
result_obj = json.loads(result.replace('```json', '').replace('}\n```', '}').strip()) |
|
|
|
|
else: |
|
|
|
|
result_obj = json.loads(result.strip()) |
|
|
|
|
|
|
|
|
|
# 预测排片数据 |
|
|
|
|
_show = result_obj['show'].replace('```', '').replace('csv', '').strip() |
|
|
|
|
|
|
|
|
|
# 预测销售数据 |
|
|
|
|
_sales = str(result_obj['income']).strip() |
|
|
|
|
|
|
|
|
|
ai_data = AiShow.objects.filter(Q(is_ai_show=True) & |
|
|
|
|
Q(is_manual_test=False) & |
|
|
|
|
Q(zz_code=zz_code) & |
|
|
|
|
Q(show_date=show_date)).order_by('-id').first() |
|
|
|
|
print(ai_data) |
|
|
|
|
# 处理返回结果 |
|
|
|
|
try: |
|
|
|
|
AiShow.objects.create( |
|
|
|
|
cinema=cinema.name, |
|
|
|
|
zz_code=cinema.zz_code, |
|
|
|
|
show_date=show_date, |
|
|
|
|
is_ai_show=True, |
|
|
|
|
is_manual_test=True, |
|
|
|
|
ai_model=model.config_name, |
|
|
|
|
template=ai_data.template if ai_data is not None else '', |
|
|
|
|
temp_date=ai_data.temp_date if ai_data is not None else '', |
|
|
|
|
target=ai_data.target if ai_data is not None else '', |
|
|
|
|
show=data_cleansing(_show), |
|
|
|
|
sales=_sales, |
|
|
|
|
prompt=prompt, |
|
|
|
|
result=result, |
|
|
|
|
message=message, |
|
|
|
|
take_times=int((end - start).seconds), |
|
|
|
|
take_tokens=tokens, |
|
|
|
|
prompt_version=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), |
|
|
|
|
) |
|
|
|
|
except Exception as e: |
|
|
|
|
print(e) |
|
|
|
|
return e |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
# # 方式一 |
|
|
|
|
# _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '') |
|
|
|
|
# _show = _show.strip() |
|
|
|
|
|