| import pymongo |
|
|
| def get_mongo_col(col="config_beta"): |
| """ |
| 获取操作mongo集合 |
| """ |
| mongo_3012 = "mongodb://dashboard:9qRV71M%25Trx1CI@m3012.hw.mongos.m.com:3012/dashboard?authSource=dashboard" |
| client = pymongo.MongoClient(mongo_3012, maxPoolSize=500) |
| db = client["dashboard"] |
| col = db[col] |
| return col |
|
|
| |
| collection = get_mongo_col() |
|
|
|
|
| doc = collection.find_one( |
| {"name": "txt2txt_config"}, |
| {"_id": 0, "data": 1} |
| ) |
| if not doc: |
| raise RuntimeError("找不到配置 document") |
|
|
| data = doc["data"] |
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-5', |
| 'value': 'gpt-5', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 1, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-5-chat', |
| 'value': 'gpt-5-chat', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 1, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-5-nano', |
| 'value': 'gpt-5-nano', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 1, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-5-mini', |
| 'value': 'gpt-5-mini', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 1, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-4.1', |
| 'value': 'gpt-4.1', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 0, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-4.1-mini', |
| 'value': 'gpt-4.1-mini', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 0, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'gpt-4.1-nano', |
| 'value': 'gpt-4.1-nano', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 0, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
| data.append({ |
| 'stream_selected': 0, |
| 'label': 'o3', |
| 'value': 'o3', |
| 'wechat_selected': 0, |
| 'wechat_label': 0, |
| 'selected': 0, |
| 'max_tokens': 4000, |
| 'is_think': 1, |
| 'web_label': 0, |
| 'stream_label': 0 |
| }) |
|
|
| |
| result = collection.update_one( |
| {"name": "txt2txt_config"}, |
| {"$set": {"data": data}} |
| ) |
| print(f"matched={result.matched_count}, modified={result.modified_count}") |
|
|
|
|
| query = {"name": "txt2txt_config"} |
| projection = {"_id": 0, "data": 1} |
|
|
| doc = collection.find_one(query, projection) |
|
|
|
|
| if doc: |
| data_value = doc.get("data") |
| print(data_value) |
| else: |
| print("未找到 name 等于 txt2txt_config 的记录") |
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
| |
|
|
| |