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.m.com:3012/dashboard?authSource=dashboard"
|
| 8 |
+
client = pymongo.MongoClient(mongo_3012, maxPoolSize=500)
|
| 9 |
+
db = client["dashboard"]
|
| 10 |
+
col = db[col] # data_package(7234543961263854561) goods_feature("7234800834201014260")
|
| 11 |
+
return col
|
| 12 |
+
|
| 13 |
+
# 拿到 collection 对象
|
| 14 |
+
collection = get_mongo_col() # 默认 col="config_beta"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
doc = collection.find_one(
|
| 18 |
+
{"name": "txt2txt_config"},
|
| 19 |
+
{"_id": 0, "data": 1}
|
| 20 |
+
)
|
| 21 |
+
if not doc:
|
| 22 |
+
raise RuntimeError("找不到配置 document")
|
| 23 |
+
|
| 24 |
+
data = doc["data"]
|
| 25 |
+
|
| 26 |
+
data.append({
|
| 27 |
+
'stream_selected': 0,
|
| 28 |
+
'label': 'us.anthropic.claude-3-7-sonnet-20250219-v1:0',
|
| 29 |
+
'value': 'us.anthropic.claude-3-7-sonnet-20250219-v1:0',
|
| 30 |
+
'wechat_selected': 0,
|
| 31 |
+
'wechat_label': 0,
|
| 32 |
+
'selected': 0,
|
| 33 |
+
'max_tokens': 4000,
|
| 34 |
+
'is_think': 0,
|
| 35 |
+
'web_label': 0,
|
| 36 |
+
'stream_label': 0
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
data.append({
|
| 40 |
+
'stream_selected': 0,
|
| 41 |
+
'label': 'us.anthropic.claude-sonnet-4-20250514-v1:0',
|
| 42 |
+
'value': 'us.anthropic.claude-sonnet-4-20250514-v1:0',
|
| 43 |
+
'wechat_selected': 0,
|
| 44 |
+
'wechat_label': 0,
|
| 45 |
+
'selected': 0,
|
| 46 |
+
'max_tokens': 4000,
|
| 47 |
+
'is_think': 0,
|
| 48 |
+
'web_label': 0,
|
| 49 |
+
'stream_label': 0
|
| 50 |
+
})
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
data.append({
|
| 54 |
+
'stream_selected': 0,
|
| 55 |
+
'label': 'qwen-turbo',
|
| 56 |
+
'value': 'qwen-turbo',
|
| 57 |
+
'wechat_selected': 0,
|
| 58 |
+
'wechat_label': 0,
|
| 59 |
+
'selected': 0,
|
| 60 |
+
'max_tokens': 4000,
|
| 61 |
+
'is_think': 1,
|
| 62 |
+
'web_label': 0,
|
| 63 |
+
'stream_label': 0
|
| 64 |
+
})
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# # 2. 在本地 dict 里插入/修改
|
| 70 |
+
# data["us.anthropic.claude-3-7-sonnet-20250219-v1:0"] = {
|
| 71 |
+
# "completion_price": 0.0006,
|
| 72 |
+
# "prompt_price": 0.003,
|
| 73 |
+
# "currency": "$"
|
| 74 |
+
# }
|
| 75 |
+
|
| 76 |
+
# # 2. 在本地 dict 里插入/修改
|
| 77 |
+
# data["us.anthropic.claude-sonnet-4-20250514-v1:0"] = {
|
| 78 |
+
# "completion_price": 0.0006,
|
| 79 |
+
# "prompt_price": 0.003,
|
| 80 |
+
# "currency": "$"
|
| 81 |
+
# }
|
| 82 |
+
|
| 83 |
+
# # 2. 在本地 dict 里插入/修改
|
| 84 |
+
# data["qwen-turbo"] = {
|
| 85 |
+
# "completion_price": 0.0006,
|
| 86 |
+
# "prompt_price": 0.0003,
|
| 87 |
+
# "currency": "¥"
|
| 88 |
+
# }
|
| 89 |
+
|
| 90 |
+
# 3. 一次性把整个 data 写回去
|
| 91 |
+
result = collection.update_one(
|
| 92 |
+
{"name": "txt2txt_price_config"},
|
| 93 |
+
{"$set": {"data": data}}
|
| 94 |
+
)
|
| 95 |
+
print(f"matched={result.matched_count}, modified={result.modified_count}")
|
| 96 |
+
|
| 97 |
+
# service_name = "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
|
| 98 |
+
# service_data = {
|
| 99 |
+
# "completion_price": 0.015,
|
| 100 |
+
# "prompt_price": 0.003,
|
| 101 |
+
# "currency": "$"
|
| 102 |
+
# }
|
| 103 |
+
|
| 104 |
+
# result = collection.update_one(
|
| 105 |
+
# {"name": "txt2txt_price_config"},
|
| 106 |
+
# {"$set": {f"data.{service_name}": service_data}}
|
| 107 |
+
# )
|
| 108 |
+
|
| 109 |
+
# print(f"matched={result.matched_count}, modified={result.modified_count}")
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
query = {"name": "txt2txt_config"}
|
| 113 |
+
projection = {"_id": 0, "data": 1}
|
| 114 |
+
|
| 115 |
+
doc = collection.find_one(query, projection)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if doc:
|
| 119 |
+
data_value = doc.get("data")
|
| 120 |
+
print(data_value)
|
| 121 |
+
else:
|
| 122 |
+
print("未找到 name 等于 txt2txt_price_config 的记录")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
# 查询单条文档
|
| 126 |
+
# doc = collection.find_one(query, projection)
|
| 127 |
+
|
| 128 |
+
# db = col.database # 或者直接用 client["dashboard"]
|
| 129 |
+
|
| 130 |
+
# # 列出所有集合名
|
| 131 |
+
# collections = db.list_collection_names()
|
| 132 |
+
# print("当前 database 下的集合:", collections)
|
| 133 |
+
|
| 134 |
+
# ['mp_collection', 'system.profile', 'mtxx_odz_aimr_im_chat_order_label_aggregate', 'xx_expose_history', 'aibeauty_trigger', 'mtxx_odz_aimr_im_chat_order', 'my_music_history', 'aibeauty_data_beta', 'my_music_history_count14', 'xx_area_mapping', 'aibeauty_trigger_beta', 'aibeauty_feedback', 'counters', 'xx_music_history', 'aibeauty_directive_beta', 'gd_history', 'message_spark_list_beta', 'my_expose', 'aibeauty_directive', 'xx_material_history', 'message_tongyi_list', 'aibeauty_im_msg', 'xx_formula_save_top100', 'aibeauty_title_stat', 'aibeauty_data', 'config', 'message_wenxin_list_beta', 'im_chat_msg_type', 'mp_neg_feedback', 'my_click', 'my_material_use_info', 'message_list_beta', 'message_pangu_list', 'aibeauty_data_history', 'my_search_history', 'mp_live', 'aibeauty_feedback_beta', 'aibeauty_top_data', 'message_wenxin_list', 'mp_expose', 'aibeauty_title_beta', 'aibeauty_data_history_beta', 'mtxx_odz_aimr_im_chat_order_label', 'related_history', 'xx_new_user', 'mht_rec_path', 'xx_feed_count', 'sdk_adz_aigc_chatgpt_info', 'aibeauty_top_data_gid_room_id', 'video_4k_transcoder', 'my_material_info', 'xx_music_material_category', 'mp_click', 'my_banner_history', 'webui_task_beta', 'config_beta', 'mht_dynamic_info', 'aibeauty_top_data_prompt_roomlist', 'my_search_history_count14', 'my_material_info_30', 'webui_record_beta', 'my_material_history', 'message_list', 'my_tmpl_history', 'aibeauty_title_stat_beta', 'message_pangu_list_beta', 'xx_dislike', 'my_music_history_count30', 'my_recommend_view', 'nlp_timeliness', 'blackflow_history', 'aibeauty_title', 'aibeauty_top_data_beta', 'message_spark_list', 'message_tongyi_list_beta', 'click_history']
|