|
| 1 | +# Generated by Django 4.2.15 on 2025-03-13 07:21 |
| 2 | + |
| 3 | +from django.db import migrations, models |
| 4 | + |
| 5 | +function_template = ''' |
| 6 | +INSERT INTO function_lib (create_time, update_time, id, name, "desc", code, input_field_list, user_id, is_active, permission_type, function_type, icon, init_field_list, init_params, template_id) VALUES ('2025-03-10 06:20:35.945414 +00:00', '2025-03-10 09:19:23.608026 +00:00', 'c75cb48e-fd77-11ef-84d2-5618c4394482', '博查AI', '从博查搜索任何信息和网页URL', e'def bocha_search(query, apikey): |
| 7 | + import requests |
| 8 | + import json |
| 9 | + url = "https://api.bochaai.com/v1/web-search" |
| 10 | + payload = json.dumps({ |
| 11 | + "query": query, |
| 12 | + "Boolean": "true", |
| 13 | + "count": 8 |
| 14 | + }) |
| 15 | +
|
| 16 | + headers = { |
| 17 | + "Authorization": "Bearer " + apikey, #鉴权参数,示例:Bearer xxxxxx,API KEY请先前往博查AI开放平台(https://open.bochaai.com)> API KEY 管理中获取。 |
| 18 | + "Content-Type": "application/json" |
| 19 | + } |
| 20 | +
|
| 21 | + response = requests.request("POST", url, headers=headers, data=payload) |
| 22 | + if response.status_code == 200: |
| 23 | + return response.json() |
| 24 | + else: |
| 25 | + raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}") |
| 26 | + return (response.text)', '{"{\\"name\\": \\"query\\", \\"type\\": \\"string\\", \\"source\\": \\"reference\\", \\"is_required\\": true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', TRUE, 'PUBLIC', 'INTERNAL', '/src/assets/fx/bochaai/icon.png', '[{"attrs": {"type": "password", "maxlength": 200, "minlength": 1, "show-password": true, "show-word-limit": true}, "field": "apikey", "label": "apikey", "required": true, "input_type": "PasswordInput", "props_info": {"rules": [{"message": "apikey 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "apikey长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}]', '', NULL); |
| 27 | +INSERT INTO function_lib (create_time, update_time, id, name, "desc", code, input_field_list, user_id, is_active, permission_type, function_type, icon, init_field_list, init_params, template_id) VALUES ('2025-02-26 03:36:48.187286 +00:00', '2025-03-11 07:23:46.123972 +00:00', 'e89ad2ae-f3f2-11ef-ad09-0242ac110002', 'Google Search', 'Google Web Search', e'def google_search(query, apikey, cx): |
| 28 | + import requests |
| 29 | + import json |
| 30 | + url = "https://customsearch.googleapis.com/customsearch/v1" |
| 31 | + params = { |
| 32 | + "q": query, |
| 33 | + "key": apikey, |
| 34 | + "cx": cx, |
| 35 | + "num": 10, # 每次最多返回10条 |
| 36 | + } |
| 37 | +
|
| 38 | + response = requests.get(url, params=params) |
| 39 | + if response.status_code == 200: |
| 40 | + return response.json() |
| 41 | + else: |
| 42 | + raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}") |
| 43 | + return (response.text)', '{"{\\"name\\": \\"query\\", \\"type\\": \\"string\\", \\"source\\": \\"reference\\", \\"is_required\\": true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', TRUE, 'PUBLIC', 'INTERNAL', '/src/assets/fx/google_search/icon.png', '[{"attrs": {"type": "password", "maxlength": 200, "minlength": 1, "show-password": true, "show-word-limit": true}, "field": "apikey", "label": "apikey", "required": true, "input_type": "PasswordInput", "props_info": {"rules": [{"message": "apikey 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "apikey长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}, {"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "cx", "label": "cx", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "cx 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "cx长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}]', '', NULL); |
| 44 | +INSERT INTO function_lib (create_time, update_time, id, name, "desc", code, input_field_list, user_id, is_active, permission_type, function_type, icon, init_field_list, init_params, template_id) VALUES ('2025-02-25 07:44:40.141515 +00:00', '2025-03-11 06:33:53.248495 +00:00', '5e912f00-f34c-11ef-8a9c-5618c4394482', 'LangSearch API', e'A Web Search API supporting natural language search |
| 45 | +', e' |
| 46 | +def langsearch(query, apikey): |
| 47 | + import json |
| 48 | + import requests |
| 49 | + |
| 50 | + url = "https://api.langsearch.com/v1/web-search" |
| 51 | + payload = json.dumps({ |
| 52 | + "query": query, |
| 53 | + "summary": True, |
| 54 | + "freshness": "noLimit", |
| 55 | + "livecrawl": True, |
| 56 | + "count": 20 |
| 57 | + }) |
| 58 | + headers = { |
| 59 | + "Authorization": apikey, |
| 60 | + "Content-Type": "application/json" |
| 61 | + } |
| 62 | + # key从官网申请 https://langsearch.com/ |
| 63 | + response = requests.request("POST", url, headers=headers, data=payload) |
| 64 | + if response.status_code == 200: |
| 65 | + return response.json() |
| 66 | + else: |
| 67 | + raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}") |
| 68 | + return (response.text)', '{"{\\"name\\": \\"query\\", \\"type\\": \\"string\\", \\"source\\": \\"reference\\", \\"is_required\\": true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', TRUE, 'PUBLIC', 'INTERNAL', '/src/assets/fx/langsearch/icon.png', '[{"attrs": {"type": "password", "maxlength": 200, "minlength": 1, "show-password": true, "show-word-limit": true}, "field": "apikey", "label": "apikey", "required": true, "input_type": "PasswordInput", "props_info": {"rules": [{"message": "apikey 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "apikey长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}]', '', NULL); |
| 69 | +
|
| 70 | +''' |
| 71 | + |
| 72 | + |
| 73 | +class Migration(migrations.Migration): |
| 74 | + dependencies = [ |
| 75 | + ('function_lib', '0002_functionlib_is_active_functionlib_permission_type'), |
| 76 | + ] |
| 77 | + |
| 78 | + operations = [ |
| 79 | + migrations.AddField( |
| 80 | + model_name='functionlib', |
| 81 | + name='function_type', |
| 82 | + field=models.CharField(choices=[('INTERNAL', '内置'), ('PUBLIC', '公开')], |
| 83 | + default='PUBLIC', max_length=20, verbose_name='函数类型'), |
| 84 | + ), |
| 85 | + migrations.AddField( |
| 86 | + model_name='functionlib', |
| 87 | + name='icon', |
| 88 | + field=models.CharField(default='/ui/favicon.ico', max_length=256, |
| 89 | + verbose_name='函数库icon'), |
| 90 | + ), |
| 91 | + migrations.AddField( |
| 92 | + model_name='functionlib', |
| 93 | + name='init_field_list', |
| 94 | + field=models.JSONField(default=list, verbose_name='启动字段列表'), |
| 95 | + ), |
| 96 | + migrations.AddField( |
| 97 | + model_name='functionlib', |
| 98 | + name='init_params', |
| 99 | + field=models.CharField(max_length=102400, null=True, verbose_name='初始化参数'), |
| 100 | + ), |
| 101 | + migrations.AddField( |
| 102 | + model_name='functionlib', |
| 103 | + name='template_id', |
| 104 | + field=models.UUIDField(default=None, null=True, verbose_name='模版id'), |
| 105 | + ), |
| 106 | + migrations.RunSQL(function_template) |
| 107 | + ] |
0 commit comments