-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Support Internal Function #2554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
apps/function_lib/migrations/0003_functionlib_function_type_functionlib_icon_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Generated by Django 4.2.15 on 2025-03-13 07:21 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
| function_template = ''' | ||
| 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): | ||
| import requests | ||
| import json | ||
| url = "https://api.bochaai.com/v1/web-search" | ||
| payload = json.dumps({ | ||
| "query": query, | ||
| "Boolean": "true", | ||
| "count": 8 | ||
| }) | ||
|
|
||
| headers = { | ||
| "Authorization": "Bearer " + apikey, #鉴权参数,示例:Bearer xxxxxx,API KEY请先前往博查AI开放平台(https://open.bochaai.com)> API KEY 管理中获取。 | ||
| "Content-Type": "application/json" | ||
| } | ||
|
|
||
| response = requests.request("POST", url, headers=headers, data=payload) | ||
| if response.status_code == 200: | ||
| return response.json() | ||
| else: | ||
| raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}") | ||
| 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); | ||
| 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): | ||
| import requests | ||
| import json | ||
| url = "https://customsearch.googleapis.com/customsearch/v1" | ||
| params = { | ||
| "q": query, | ||
| "key": apikey, | ||
| "cx": cx, | ||
| "num": 10, # 每次最多返回10条 | ||
| } | ||
|
|
||
| response = requests.get(url, params=params) | ||
| if response.status_code == 200: | ||
| return response.json() | ||
| else: | ||
| raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}") | ||
| 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); | ||
| 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 | ||
| ', e' | ||
| def langsearch(query, apikey): | ||
| import json | ||
| import requests | ||
|
|
||
| url = "https://api.langsearch.com/v1/web-search" | ||
| payload = json.dumps({ | ||
| "query": query, | ||
| "summary": True, | ||
| "freshness": "noLimit", | ||
| "livecrawl": True, | ||
| "count": 20 | ||
| }) | ||
| headers = { | ||
| "Authorization": apikey, | ||
| "Content-Type": "application/json" | ||
| } | ||
| # key从官网申请 https://langsearch.com/ | ||
| response = requests.request("POST", url, headers=headers, data=payload) | ||
| if response.status_code == 200: | ||
| return response.json() | ||
| else: | ||
| raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}") | ||
| 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); | ||
|
|
||
| ''' | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ('function_lib', '0002_functionlib_is_active_functionlib_permission_type'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='functionlib', | ||
| name='function_type', | ||
| field=models.CharField(choices=[('INTERNAL', '内置'), ('PUBLIC', '公开')], | ||
| default='PUBLIC', max_length=20, verbose_name='函数类型'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='functionlib', | ||
| name='icon', | ||
| field=models.CharField(default='/ui/favicon.ico', max_length=256, | ||
| verbose_name='函数库icon'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='functionlib', | ||
| name='init_field_list', | ||
| field=models.JSONField(default=list, verbose_name='启动字段列表'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='functionlib', | ||
| name='init_params', | ||
| field=models.CharField(max_length=102400, null=True, verbose_name='初始化参数'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='functionlib', | ||
| name='template_id', | ||
| field=models.UUIDField(default=None, null=True, verbose_name='模版id'), | ||
| ), | ||
| migrations.RunSQL(function_template) | ||
| ] | ||
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # coding=utf-8 | ||
| """ | ||
| @project: MaxKB | ||
| @Author:虎 | ||
| @file: __init__.py.py | ||
| @date:2024/8/2 14:55 | ||
| @desc: | ||
| """ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.