You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
6.3 KiB
147 lines
6.3 KiB
#dc
|
|
import time
|
|
import json
|
|
import random
|
|
import requests
|
|
|
|
from openai import (
|
|
OpenAI,
|
|
RateLimitError,
|
|
APIConnectionError,
|
|
AuthenticationError,
|
|
OpenAIError,
|
|
)
|
|
|
|
from config.model_config import *
|
|
from conversation_cache import conversation_cache
|
|
|
|
def generate_filter_description(filter, index):
|
|
filter_type = filter['type']
|
|
description = None
|
|
|
|
if filter_type == 'date': # 时间类
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:"], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.DatePickerRange(
|
|
id=f'date-picker-range-{filter["id"]}',
|
|
start_date=filter['default_value']['start_date'],
|
|
end_date=filter['default_value']['end_date'],
|
|
display_format='YYYY-MM-DD',
|
|
className="date-picker-range"
|
|
)
|
|
], className="filter-item", style={'fontSize': '14px', 'marginTop': '8px', 'position': 'relative', 'zIndex': 1000})
|
|
return description
|
|
|
|
elif filter_type == 'number': # 数值类
|
|
if 'equal' in filter['default_value'] and filter['default_value']['equal'] is not None:
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:{filter['name']} = "], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.Input(
|
|
id=f'number-input-equal-{filter["id"]}',
|
|
type='number',
|
|
value=filter['default_value']['equal'],
|
|
style={'width': '60px', 'marginRight': '5px'}
|
|
)
|
|
], className="filter-item", style={'display': 'inline-flex', 'alignItems': 'center', 'fontSize': '14px', 'marginTop': '8px'})
|
|
else:
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:"], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.Input(
|
|
id=f'number-input-min-{filter["id"]}',
|
|
type='number',
|
|
value=filter['default_value']['min'],
|
|
style={'width': '60px', 'marginRight': '5px'}
|
|
),
|
|
html.Span([f"<= {filter['name']} <="], style={'fontSize': '14px', 'margin': '0 5px'}),
|
|
dcc.Input(
|
|
id=f'number-input-max-{filter["id"]}',
|
|
type='number',
|
|
value=filter['default_value']['max'],
|
|
style={'width': '60px', 'marginLeft': '5px'}
|
|
)
|
|
], className="filter-item", style={'display': 'inline-flex', 'alignItems': 'center', 'fontSize': '14px', 'marginTop': '8px'})
|
|
return description
|
|
|
|
elif filter_type == 'enum': # 枚举类
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:"], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.Dropdown(
|
|
id=f'enum-dropdown-{filter["id"]}',
|
|
options=[{'label': opt, 'value': opt} for opt in filter['options']],
|
|
value=filter['default_value'],
|
|
multi=True,
|
|
className="enum-dropdown",
|
|
style={'width': 'auto', 'display': 'inline-block', 'paddingLeft': '5px', 'paddingRight': '5px'}
|
|
)
|
|
], className="filter-item", style={'fontSize': '14px', 'marginTop': '8px'})
|
|
return description
|
|
|
|
elif filter_type == 'text': # 文本类
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:"], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.Dropdown(
|
|
id=f'text-dropdown-{filter["id"]}',
|
|
options=[{'label': opt, 'value': opt} for opt in filter['options']],
|
|
value=filter['default_value'],
|
|
multi=True,
|
|
className="text-dropdown",
|
|
style={'width': 'auto', 'display': 'inline-block', 'paddingLeft': '5px', 'paddingRight': '5px'}
|
|
)
|
|
], className="filter-item", style={'fontSize': '14px', 'marginTop': '8px'})
|
|
return description
|
|
|
|
elif filter_type == 'indicator': # 指示器类
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:"], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.RadioItems(
|
|
id=f'indicator-radio-{filter["id"]}',
|
|
options=[
|
|
{'label': '是', 'value': '是'},
|
|
{'label': '否', 'value': '否'}
|
|
],
|
|
value=filter['default_value'],
|
|
className="radio-horizontal-inline",
|
|
labelStyle={'display': 'inline-block', 'fontSize': '14px', 'verticalAlign': 'middle', 'marginRight': '10px'}
|
|
)
|
|
], className="filter-item", style={'fontSize': '14px', 'marginTop': '8px', 'display': 'inline-flex', 'alignItems': 'center', 'marginRight': '20px'})
|
|
return description
|
|
|
|
elif filter_type == 'index': # 指标类
|
|
description = html.Div([
|
|
html.Span([f"{index}、{filter['name']}:"], style={'fontSize': '14px', 'fontWeight': 'bold'}),
|
|
dcc.Dropdown(
|
|
id=f'index-dropdown-{filter["id"]}',
|
|
options=[{'label': opt, 'value': opt} for opt in filter['options']],
|
|
value=[],
|
|
multi=True,
|
|
className="index-dropdown",
|
|
style={'width': '200px', 'display': 'inline-block', 'paddingLeft': '5px', 'paddingRight': '5px'}
|
|
)
|
|
], className="filter-item", style={'fontSize': '14px', 'marginTop': '8px'})
|
|
return description
|
|
|
|
return None
|
|
|
|
def sk_data_request(
|
|
question: str,
|
|
model_name: str,
|
|
sub_model_name: str,
|
|
temperature: float,
|
|
max_tokens: int,
|
|
conversation_id: str,
|
|
message_id: str,
|
|
):
|
|
# 其他情况均视作“演示用模拟接口”进行处理
|
|
print("********11")
|
|
# response = requests.post("http://localhost:5000/get_filters", json={"message": question})
|
|
response = requests.post("https://u171185-90da-6ce9e383.westc.gpuhub.com:8443/chat/nl2sql_client_chat", json={"query": question})
|
|
|
|
json_str = response.json()
|
|
print("********2")
|
|
# print(filters)
|
|
return json_str
|
|
# demo_response = "这是一段流式回复示例,所以我说话结结巴巴的^_^"
|
|
# key_str = "response_text"
|
|
|
|
# return json.dumps({"response_text": demo_response})
|
|
|
|
|