Feat/assistant app (#2086)

Co-authored-by: chenhe <guchenhe@gmail.com>
Co-authored-by: Pascal M <11357019+perzeuss@users.noreply.github.com>
This commit is contained in:
Yeuoly
2024-01-23 19:58:23 +08:00
committed by GitHub
parent 7bbe12b2bd
commit 86286e1ac8
175 changed files with 11619 additions and 1235 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -0,0 +1,66 @@
from core.tools.tool.builtin_tool import BuiltinTool
from core.tools.entities.tool_entities import ToolInvokeMessage
from typing import Any, Dict, List, Union
from datetime import datetime
from googleapiclient.discovery import build
class YoutubeVideosAnalyticsTool(BuiltinTool):
def _invoke(self, user_id: str, tool_paramters: Dict[str, Any]) \
-> Union[ToolInvokeMessage, List[ToolInvokeMessage]]:
"""
invoke tools
"""
channel = tool_paramters.get('channel', '')
if not channel:
return self.create_text_message('Please input symbol')
time_range = [None, None]
start_date = tool_paramters.get('start_date', '')
if start_date:
time_range[0] = start_date
else:
time_range[0] = '1800-01-01'
end_date = tool_paramters.get('end_date', '')
if end_date:
time_range[1] = end_date
else:
time_range[1] = datetime.now().strftime('%Y-%m-%d')
if 'google_api_key' not in self.runtime.credentials or not self.runtime.credentials['google_api_key']:
return self.create_text_message('Please input api key')
youtube = build('youtube', 'v3', developerKey=self.runtime.credentials['google_api_key'])
# try to get channel id
search_results = youtube.search().list(q='mrbeast', type='channel', order='relevance', part='id').execute()
channel_id = search_results['items'][0]['id']['channelId']
start_date, end_date = time_range
start_date = datetime.strptime(start_date, '%Y-%m-%d').strftime('%Y-%m-%dT%H:%M:%SZ')
end_date = datetime.strptime(end_date, '%Y-%m-%d').strftime('%Y-%m-%dT%H:%M:%SZ')
# get videos
time_range_videos = youtube.search().list(
part='snippet', channelId=channel_id, order='date', type='video',
publishedAfter=start_date,
publishedBefore=end_date
).execute()
def extract_video_data(video_list):
data = []
for video in video_list['items']:
video_id = video['id']['videoId']
video_info = youtube.videos().list(part='snippet,statistics', id=video_id).execute()
title = video_info['items'][0]['snippet']['title']
views = video_info['items'][0]['statistics']['viewCount']
data.append({'Title': title, 'Views': views})
return data
summary = extract_video_data(time_range_videos)
return self.create_text_message(str(summary))

View File

@@ -0,0 +1,46 @@
identity:
name: youtube_video_statistics
author: Dify
label:
en_US: Video statistics
zh_Hans: 视频统计
icon: icon.svg
description:
human:
en_US: A tool for get statistics about a channel's videos.
zh_Hans: 一个用于获取油管频道视频统计数据的工具。
llm: A tool for get statistics about a channel's videos. Input should be the name of the channel like PewDiePie.
parameters:
- name: channel
type: string
required: true
label:
en_US: Channel name
zh_Hans: 频道名
human_description:
en_US: The name of the channel you want to search.
zh_Hans: 你想要搜索的油管频道名。
llm_description: The name of the channel you want to search.
form: llm
- name: start_date
type: string
required: false
label:
en_US: Start date
zh_Hans: 开始日期
human_description:
en_US: The start date of the analytics.
zh_Hans: 分析的开始日期。
llm_description: The start date of the analytics, the format of the date must be YYYY-MM-DD like 2020-01-01.
form: llm
- name: end_date
type: string
required: false
label:
en_US: End date
zh_Hans: 结束日期
human_description:
en_US: The end date of the analytics.
zh_Hans: 分析的结束日期。
llm_description: The end date of the analytics, the format of the date must be YYYY-MM-DD like 2024-01-01.
form: llm

View File

@@ -0,0 +1,22 @@
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
from core.tools.errors import ToolProviderCredentialValidationError
from core.tools.provider.builtin.youtube.tools.videos import YoutubeVideosAnalyticsTool
class YahooFinanceProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict) -> None:
try:
YoutubeVideosAnalyticsTool().fork_tool_runtime(
meta={
"credentials": credentials,
}
).invoke(
user_id='',
tool_paramters={
"channel": "TOKYO GIRLS COLLECTION",
"start_date": "2020-01-01",
"end_date": "2024-12-31",
},
)
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))

View File

@@ -0,0 +1,24 @@
identity:
author: Dify
name: youtube
label:
en_US: Youtube
zh_Hans: Youtube
description:
en_US: Youtube
zh_Hans: Youtube油管是全球最大的视频分享网站用户可以在上面上传、观看和分享视频。
icon: icon.png
credentails_for_provider:
google_api_key:
type: secret-input
required: true
label:
en_US: Google API key
zh_Hans: Google API key
placeholder:
en_US: Please input your Google API key
zh_Hans: 请输入你的 Google API key
help:
en_US: Get your Google API key from Google
zh_Hans: 从 Google 获取您的 Google API key
url: https://console.developers.google.com/apis/credentials