├── README-zh.md ├── README.md ├── api ├── .DS_Store ├── .gitignore ├── getCurrentWeather.js ├── getExchangeRate.js ├── getTopHackerNews.js └── utils │ └── authorizeRequest.js ├── descriptions └── function_desc.json ├── info ├── create_story.md ├── find_teachers.md ├── get_coordinates.md ├── get_current_weather.md ├── get_exchange_rate.md ├── get_top_hackers_news.md ├── get_video_summary_transcribe.md └── midjourney_prompt_generator.md └── package.json /README-zh.md: -------------------------------------------------------------------------------- 1 | # Awesome LLM functions 2 | 3 |
English | 中文
4 | 5 | ## 目标 6 | 7 | 大语言模型的函数调用机制(Function calling)对于开发AI Agents来说非常重要,但函数的开发和调试都比较麻烦,互联网也缺少这方面的工具和资源。 8 | 9 | 本项目旨在创建一个“开箱即用”的共享函数集,并提供一些函数开发相关的资源和技术框架,让开发者可以更容易地将外部函数与大语言模型的API集成起来,实现自己想要的功能。 10 | 11 | ## 函数列表 12 | 13 | 点击以下函数查看详情,并复制函数的定义,就可以通过 [ConsoleX.ai](https://console.evalsone.com/)轻松测试函数的调用。 14 | 15 | * [天气查询 (get_current_weather)](info/get_current_weather.md) 16 | * [汇率查询 (get_exchange_rate)](info/get_exchange_rate.md) 17 | * [获取Hacker news最新内容 (get_top_hacker_news)](info/get_top_hacker_news.md) 18 | * [生成MidJourney提示语]((info/midjourney_prompt_generator.md)** ) 19 | * [快速获取视频内容摘要](info/get_video_summary_transcribe.md) 20 | * [读取PDF文档信息 (get_read_url)](info/read_url.md) 21 | * [查找语言老师 (get_find_teachers)](info/find_teachers.md) 22 | * [获取地理位置坐标 (get_get_coordinates)](info/get_coordinates.md) 23 | * [睡前故事 (get_create_story)](info/create_story.md) 24 | 25 | > **Note** 26 | > 以上函数部分通过[Plug2Func](https://consolex.ai/plugins)生成 27 | 28 | ## 函数开发 29 | * [OpenAI function boilerplate](https://github.com/quentinzhang/OpenAI-function-boilerplate) 30 | 31 | ## 社区讨论 32 | 如果你喜欢OpenFunction项目,并希望为它贡献一份力量,丰富OpenFunction的函数库,可以 [加入Discord服务器](https://discord.gg/z9KtFM62F2) 一起讨论。 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Awesome LLM Functions 2 | 3 | 4 | 5 | ## Objective 6 | 7 | The function calling mechanism of LLMs from OpenAI and Anthropic is crucial for building AI Agents, but the development and debugging of functions are quite cumbersome. Tools and resources for function implementing are also very rare on Internet. 8 | 9 | This project aims to create a "plug and play" shared function set and provide some resources and technical frameworks related to function development, allowing developers to easily integrate external functions with the LLM's API to achieve the desired functions. 10 | 11 | ## Function List 12 | 13 | Click on the titles of functions for details, and copy the function definition to easily invoke function calls by [ConsoleX.ai](https://consolex.ai). 14 | 15 | * **[Weather inquiry](info/get_current_weather.md)** - Get the current weather in a given location by latitude and longitude 16 | * **[Exchange rate inquiry](info/get_exchange_rate.md)** - Convert currency from one type to another and get the exchange rate 17 | * **[Get top Hackers News](info/get_top_hackers_news.md)** - Fetch the top 5 news articles from Hackers News 18 | * **[MidJourney prompts generator](info/midjourney_prompt_generator.md)** - Generate Photorealistic prompts for Midjourney 19 | * **[Youtube video summary generator](info/get_video_summary_transcribe.md)** - Summarize video highlights from YouTube video URLs. 20 | * **[Read PDF URL link](info/read_url.md)** - Read the contents of an PDF URL link 21 | * **[Find language teachers](info/find_teachers.md)** - Elevate your language learning at any level with personalized 1-on-1 online lessons from tutors across the world. 22 | * **[Get coordinates of any places](info/get_coordinates.md)** - Obtain latitude and longitude based on the address and generate map link. 23 | * **[Create a bedtime story](info/create_story.md)** - Create bedtime stories that instill a love for reading, spark creativity, and build important life skills. 24 | 25 | The list of the functions will be updated continuously, and some of the functions are generated by [PlugNFunc](https://consolex.ai/plugins). 26 | 27 | ## Function Development 28 | * **[OpenAI function boilerplate](https://github.com/quentinzhang/OpenAI-function-boilerplate)** 29 | Develop your first OpenAI function with Node.js and Vercel 30 | 31 | ## Community Discussion 32 | If you feel interested in or want to contribute to this project, feel free to [join our Discord server](https://discord.gg/z9KtFM62F2) for discussions. 33 | -------------------------------------------------------------------------------- /api/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quentinzhang/Awesome-LLM-functions/1d0bc15e0fd396669b7201c2a582a5833414d839/api/.DS_Store -------------------------------------------------------------------------------- /api/.gitignore: -------------------------------------------------------------------------------- 1 | .vercel 2 | -------------------------------------------------------------------------------- /api/getCurrentWeather.js: -------------------------------------------------------------------------------- 1 | const authorizeRequest = require('./utils/authorizeRequest'); 2 | 3 | module.exports = async (req, res) => { 4 | // API Key checking 5 | if (!authorizeRequest(req, res)) { 6 | return; 7 | } 8 | 9 | let axios; 10 | await import('axios').then(importedAxios => { 11 | axios = importedAxios.default; 12 | }); 13 | 14 | if (!axios) { 15 | return res.status(500).send('Axios is not initialized'); 16 | } 17 | 18 | const OPEN_WEATHER_API_KEY = process.env.OPEN_WEATHER_API_KEY 19 | 20 | const { lat } = req.body || req.query; 21 | const { lon } = req.body || req.query; 22 | const { units = 'standard' } = req.body || req.query; 23 | 24 | const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&units=${units}&appid=${OPEN_WEATHER_API_KEY}`; 25 | try { 26 | const response = await axios.get(url); 27 | const data = response.data; 28 | if (response.status === 200) { 29 | const weatherInfo = { 30 | temperature: data.main.temp, 31 | weather: data.weather[0].description, 32 | }; 33 | res.status(200).json(weatherInfo); 34 | } else { 35 | res.status(500).send('Could not fetch weather'); 36 | } 37 | } catch (error) { 38 | console.error('An error occurred:', error); 39 | res.status(500).send('Internal Server Error'); 40 | } 41 | }; -------------------------------------------------------------------------------- /api/getExchangeRate.js: -------------------------------------------------------------------------------- 1 | const authorizeRequest = require('./utils/authorizeRequest'); 2 | 3 | module.exports = async (req, res) => { 4 | // API Key checking 5 | if (!authorizeRequest(req, res)) { 6 | return; 7 | } 8 | 9 | let axios; 10 | await import('axios').then(importedAxios => { 11 | axios = importedAxios.default; 12 | }); 13 | 14 | if (!axios) { 15 | return res.status(500).send('Axios is not initialized'); 16 | } 17 | 18 | const EXCHANGE_RATE_API_KEY = process.env.EXCHANGE_RATE_API_KEY; 19 | 20 | const { fromCurrency, toCurrency, amount } = req.body || req.query; 21 | 22 | let url = `https://v6.exchangerate-api.com/v6/${EXCHANGE_RATE_API_KEY}/pair/${fromCurrency}/${toCurrency}`; 23 | if (amount) { 24 | url += `/${amount}`; 25 | } 26 | 27 | try { 28 | const response = await axios.get(url); 29 | const data = response.data; 30 | 31 | if (data.result === 'success') { 32 | const exchangeInfo = { 33 | conversion_rate: data.conversion_rate, 34 | }; 35 | if (data.conversion_result) { 36 | exchangeInfo.conversion_result = data.conversion_result; 37 | } 38 | res.status(200).json(exchangeInfo); 39 | } else { 40 | res.status(500).send('Could not fetch exchange rates'); 41 | } 42 | } catch (error) { 43 | console.error('An error occurred:', error); 44 | res.status(500).send('Internal Server Error'); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /api/getTopHackerNews.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import authorizeRequest from './utils/authorizeRequest'; 3 | 4 | const fetchTop5HackerNews = async (req, res) => { 5 | // API Key checking 6 | if (!authorizeRequest(req, res)) { 7 | return; 8 | } 9 | 10 | const HN_TOP_STORIES_URL = 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'; 11 | const HN_ITEM_URL = 'https://hacker-news.firebaseio.com/v0/item/'; 12 | 13 | try { 14 | // Fetch top story IDs 15 | const topStoryResponse = await axios.get(HN_TOP_STORIES_URL); 16 | const topStoryIDs = topStoryResponse.data; 17 | 18 | if (!Array.isArray(topStoryIDs)) { 19 | return res.status(500).send('Could not fetch top stories'); 20 | } 21 | 22 | // Fetch details for the top 5 stories 23 | const top5IDs = topStoryIDs.slice(0, 5); 24 | const storyPromises = top5IDs.map(id => axios.get(`${HN_ITEM_URL}${id}.json?print=pretty`)); 25 | const storyResponses = await Promise.all(storyPromises); 26 | 27 | // Extract relevant info from each story 28 | const top5Stories = storyResponses.map(response => { 29 | const data = response.data; 30 | return { 31 | title: data.title, 32 | url: data.url, 33 | score: data.score, 34 | }; 35 | }); 36 | 37 | res.status(200).json(top5Stories); 38 | 39 | } catch (error) { 40 | console.error("Error Details:", error); // Add this line 41 | console.error('An error occurred:', error.message); 42 | res.status(500).send('Internal Server Error'); 43 | } 44 | }; 45 | 46 | export default fetchTop5HackerNews; 47 | -------------------------------------------------------------------------------- /api/utils/authorizeRequest.js: -------------------------------------------------------------------------------- 1 | const authorizeRequest = (req, res) => { 2 | const headerValue = req.headers['authorization']; 3 | const expectedApiKey = process.env.EXPECTED_API_KEY; 4 | 5 | // if EXPECTED_API_KEY was not set, then bypasses the verification step 6 | if (!expectedApiKey || expectedApiKey.trim() === "") { 7 | return true; 8 | } 9 | 10 | if (headerValue && headerValue.startsWith('Bearer ')) { 11 | const apiKey = headerValue.slice(7); 12 | 13 | if (!apiKey || apiKey !== expectedApiKey) { 14 | return res.status(401).json({ error: "Unauthorized, invalid API key" }); 15 | } 16 | } else { 17 | return res.status(401).json({ error: "No API key provided" }); 18 | } 19 | 20 | return true; 21 | }; 22 | 23 | module.exports = authorizeRequest; -------------------------------------------------------------------------------- /descriptions/function_desc.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "getCurrentWeather", 4 | "description": "Get the current weather in a given location by latitude and longitude", 5 | "parameters": { 6 | "type": "object", 7 | "properties": { 8 | "lat": { 9 | "type": "string", 10 | "description": "Latitude of the location" 11 | }, 12 | "lon": { 13 | "type": "string", 14 | "description": "Longitude of the location" 15 | }, 16 | "units": { 17 | "type": "string", 18 | "enum": ["standard", "imperial", "metric"] 19 | } 20 | }, 21 | "required": ["lat", "lon"] 22 | } 23 | }, 24 | { 25 | "name": "getExchangeRate", 26 | "description": "Convert currency from one type to another and get the exchange rate", 27 | "parameters": { 28 | "type": "object", 29 | "properties": { 30 | "fromCurrency": { 31 | "type": "string", 32 | "description": "The currency you want to convert from (ISO 4217 code)" 33 | }, 34 | "toCurrency": { 35 | "type": "string", 36 | "description": "The currency you want to convert to (ISO 4217 code)" 37 | }, 38 | "amount": { 39 | "type": "number", 40 | "description": "The amount you want to convert (optional)" 41 | } 42 | }, 43 | "required": ["fromCurrency", "toCurrency"] 44 | } 45 | }, 46 | { 47 | "name": "getTopHackerNews", 48 | "description": "Fetch the top 5 news articles from Hacker News", 49 | "parameters": { 50 | "type": "object", 51 | "properties": {}, 52 | "required": [] 53 | } 54 | } 55 | ] 56 | -------------------------------------------------------------------------------- /info/create_story.md: -------------------------------------------------------------------------------- 1 | # Bedtime Story Generator 2 | 3 | ## Function Objective 4 | Create bedtime stories that instill a love for reading, spark creativity, and build important life skills. 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | { 11 | "name": "create_story", 12 | "description": "Create a bedtime story", 13 | "extraInfo": { 14 | "method": "post", 15 | "functionUrl": "https://gpt.storybooks.app/createStory", 16 | "systemHint": "", 17 | "apiKey": "" 18 | }, 19 | "parameters": { 20 | "type": "object", 21 | "properties": { 22 | "prompt": { 23 | "type": "string", 24 | "description": "The prompt of the bedtime story." 25 | } 26 | }, 27 | "required": [ 28 | "prompt" 29 | ] 30 | } 31 | } 32 | } 33 | ``` 34 | 35 | ## Sample Question 36 | ``` 37 | I want to hear a bedtime story about courage 38 | ``` 39 | 40 | -------------------------------------------------------------------------------- /info/find_teachers.md: -------------------------------------------------------------------------------- 1 | # Find Lauage Teachers 2 | 3 | ## Function Objective 4 | Elevate your language learning at any level with personalized 1-on-1 online lessons from tutors across the world. 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | { 11 | "name": "find_language_teachers", 12 | "description": "Get the list of teachers, dirctly show teacher image user can see", 13 | "extraInfo": { 14 | "method": "get", 15 | "functionUrl": "https://en.amazingtalker.com/v1/pages/teachers", 16 | "systemHint": "", 17 | "apiKey": "" 18 | }, 19 | "parameters": { 20 | "type": "object", 21 | "properties": { 22 | "teach_subject": { 23 | "type": "string", 24 | "description": "The subject the teacher teaches, only English alphabets are accepted, e.g. english, math." 25 | }, 26 | "price_preference": { 27 | "type": "string", 28 | "description": "The user's course price preference, in order 0~10, 11~15, 16~20, 21~25, 26~30, 30+" 29 | }, 30 | "tag_url_name": { 31 | "type": "string", 32 | "description": "Learning needs, only English alphabets are accepted, e.g. certification, conversation" 33 | }, 34 | "auxiliary_language": { 35 | "type": "string", 36 | "description": "Language a student would like to use in class besides the language being taught if it is a language lesson. Only English alphabets are accepted, e.g. english, chinese, japanese." 37 | }, 38 | "teacher_location": { 39 | "type": "string", 40 | "description": "The user's preference for the teacher's nationality, indicated by a 2-letter country code (ISO 3166-1 alpha-2), e.g. TW for Taiwan, US for United States." 41 | }, 42 | "other": { 43 | "type": "string", 44 | "description": "For searches not covered by the other options, use the 'other' parameter to input any string you wish to search for." 45 | } 46 | }, 47 | "required": [ 48 | "teach_subject" 49 | ] 50 | } 51 | } 52 | } 53 | ``` 54 | 55 | ## Sample Question 56 | ``` 57 | I want to learn British English, please help me find a suitable English teacher 58 | ``` 59 | 60 | -------------------------------------------------------------------------------- /info/get_coordinates.md: -------------------------------------------------------------------------------- 1 | # Get Coordinates of Any Places 2 | 3 | ## Function Objective 4 | Obtain latitude and longitude based on the address and generate map link. 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | { 11 | "name": "get_coordinates", 12 | "description": "Get coordinates from a location string", 13 | "extraInfo": { 14 | "method": "post", 15 | "functionUrl": "https://api.earth-plugin.com/get-coordinates", 16 | "systemHint": "", 17 | "apiKey": "" 18 | }, 19 | "parameters": { 20 | "type": "object", 21 | "properties": { 22 | "location": { 23 | "type": "string", 24 | "description": "location" 25 | } 26 | }, 27 | "required": [] 28 | } 29 | } 30 | } 31 | ``` 32 | 33 | ## Sample Question 34 | ``` 35 | Please tell me the coordinates of the Forbidden City in Beijing 36 | ``` 37 | 38 | -------------------------------------------------------------------------------- /info/get_current_weather.md: -------------------------------------------------------------------------------- 1 | # Weather inquiry 2 | 3 | ## Function Objective 4 | Get the current weather in a given location by latitude and longitude 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | "name": "get_current_weather", 11 | "description": "Get the current weather in a given location by latitude and longitude", 12 | "parameters": { 13 | "type": "object", 14 | "properties": { 15 | "lat": { 16 | "type": "string", 17 | "description": "Latitude of the location" 18 | }, 19 | "lon": { 20 | "type": "string", 21 | "description": "Longitude of the location" 22 | }, 23 | "units": { 24 | "type": "string", 25 | "enum": ["standard", "imperial", "metric"] 26 | } 27 | }, 28 | "required": ["lat", "lon"] 29 | }, 30 | "extraInfo": { 31 | "method": "get", 32 | "functionUrl": "https://openfunctions.consolex.ai/api/get_current_weather" 33 | } 34 | } 35 | ``` 36 | > **Note** 37 | > According to the official example of OpenAI, using latitude and longitude as parameters can effectively reduce the function call exception caused by inconsistent place names. The large language model can convert the location in the problem into a latitude and longitude parameter. 38 | 39 | ## Sample Question 40 | ``` 41 | What is London's weather like for today? 42 | ``` 43 | 44 | > **Note** 45 | > This function is using openweathermap.org's free API for weather inquiry,and maybe the API call will fail if the API call limit is exceeded. 46 | -------------------------------------------------------------------------------- /info/get_exchange_rate.md: -------------------------------------------------------------------------------- 1 | # Exchange rate inquiry 2 | 3 | ## Function objective 4 | Convert currency from one type to another and get the exchange rate 5 | 6 | ## Function definition 7 | 8 | ```json 9 | { 10 | "name": "get_exchange_rate", 11 | "description": "Convert currency from one type to another and get the exchange rate", 12 | "parameters": { 13 | "type": "object", 14 | "properties": { 15 | "fromCurrency": { 16 | "type": "string", 17 | "description": "The currency you want to convert from (ISO 4217 code)" 18 | }, 19 | "toCurrency": { 20 | "type": "string", 21 | "description": "The currency you want to convert to (ISO 4217 code)" 22 | }, 23 | "amount": { 24 | "type": "number", 25 | "description": "The amount you want to convert (optional)" 26 | } 27 | }, 28 | "required": ["fromCurrency", "toCurrency"] 29 | }, 30 | "extraInfo": { 31 | "method": "post", 32 | "functionUrl": "https://openfunctions.consolex.ai/api/get_exchange_rate" 33 | } 34 | } 35 | ``` 36 | 37 | ## Sample Question 38 | ``` 39 | how much is 100 dollars in pounds? 40 | ``` 41 | 42 | > **Note** 43 | > This function is using exchangerate-api.com's free API for exchange rate inquiry,and maybe the API call will fail if the API call limit is exceeded. -------------------------------------------------------------------------------- /info/get_top_hackers_news.md: -------------------------------------------------------------------------------- 1 | # Get Top Hacker News 2 | 3 | ## Function Objective 4 | Fetch the top 5 news articles from Hacker News 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | "name": "get_top_hackers_news", 11 | "description": "Fetch the top 5 news articles from Hacker News", 12 | "parameters": { 13 | "type": "object", 14 | "properties": {}, 15 | "required": [] 16 | }, 17 | "extraInfo": { 18 | "method": "get", 19 | "functionUrl": "https://openfunctions.consolex.ai/api/get_top_hackers_news" 20 | } 21 | } 22 | ``` 23 | 24 | ## Sample Question 25 | ``` 26 | What is the top hacker news for today? 27 | ``` -------------------------------------------------------------------------------- /info/get_video_summary_transcribe.md: -------------------------------------------------------------------------------- 1 | # Youtube Video Summary Generator 2 | 3 | ## Function Objective 4 | Summarize video highlights from YouTube video URLs. 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | "name": "get_video_summary_transcribe", 11 | "description": "Get YouTube video transcriptions", 12 | "extraInfo": { 13 | "method": "get", 14 | "functionUrl": "https://glarity.app/api/youtube", 15 | "systemHint": "", 16 | "apiKey": "" 17 | }, 18 | "parameters": { 19 | "type": "object", 20 | "properties": { 21 | "url": { 22 | "type": "string", 23 | "description": "YouTube video URL" 24 | } 25 | }, 26 | "required": [ 27 | "url" 28 | ] 29 | } 30 | } 31 | ``` 32 | 33 | ## Sample Question 34 | ``` 35 | What is the following video talking about? 36 | https://www.youtube.com/watch?v=iWT0kl1k32M 37 | ``` -------------------------------------------------------------------------------- /info/midjourney_prompt_generator.md: -------------------------------------------------------------------------------- 1 | # Midjourney Prompt Generator 2 | 3 | ## Function Objective 4 | Generate Photorealistic prompts for Midjourney 5 | 6 | ## Function Definition 7 | 8 | ```json 9 | { 10 | "name": "midjourney_prompt_generator", 11 | "description": "Generate Photorealistic prompts for Midjourney", 12 | "extraInfo": { 13 | "method": "get", 14 | "functionUrl": "https://midjourney-ruddy.vercel.app/gen", 15 | "systemHint": "", 16 | "apiKey": "" 17 | }, 18 | "parameters": { 19 | "type": "object", 20 | "properties": { 21 | "number": { 22 | "type": "number", 23 | "description": "the number of prompts" 24 | } 25 | }, 26 | "required": [] 27 | } 28 | } 29 | ``` 30 | ## Sample Question 31 | ``` 32 | Please generate a Midjourney prompt about a cozy dog in the backyard. 33 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "funcs_api", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "axios": "^1.5.0", 14 | "node-fetch": "^3.3.2" 15 | } 16 | } 17 | --------------------------------------------------------------------------------