-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
80 lines (64 loc) · 3.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Learn chatgpt plugins: https://platform.openai.com/docs/plugins/introduction
*/
import ResponseBuilder from "../../../edge-src/common/ResponseBuilder";
// 100 character max
const descriptionForHuman = "The best podcast search engine and database. All podcasts and episodes. " +
"Built with PodcastAPI.com."
// 8,000 character max
// Instruct the model on how to use your plugin generally
// Use natural language, preferably in a concise yet descriptive and objective tone.
// We suggest starting the description_for_model with “Plugin for …”
// and then enumerating all of the functionality that your API provides.
// Best practices: https://platform.openai.com/docs/plugins/getting-started/best-practices
const descriptionForModel = 'Plugin for discovering podcasts and episodes.\n ' +
'- When asked for searching podcasts, use the `searchPodcasts` endpoint\n ' +
'- when asked for searching episodes or interviews, use the `searchEpisodes` endpoint\n ' +
'- When asked for top podcasts or best podcasts or podcast recommendations, ' +
'use the `getBestPodcasts` endpoint first; if no results, then try the `searchPodcasts` endpoint\n ' +
'- When you need category or genres id, use the `getGenres` endpoint to ' +
'find the closet genre name then get the id\n ' +
'Instructions for displaying results:\n ' +
"- Always use `listennotes_url` from the response data for the link of a podcast or an episode. " +
"Don't make up your own link.\n " +
'- Display at most 5 results, where each result is a podcast or an episode.\n ' +
'- Summarize the description of each result to at most 150 characters.'
const pluginSpec = (params) => ({
"schema_version": "v1",
// Human-readable name, such as the full company name. 20 character max.
"name_for_human": "Listen Notes",
// Name the model will use to target the plugin (no spaces allowed, only letters and numbers). 50 character max.
"name_for_model": "PodcastDatabase",
// Human-readable description of the plugin. 100 character max.
"description_for_human": descriptionForHuman,
// Description better tailored to the model, such as token context length considerations or keyword usage for
// improved plugin prompting. 8,000 character max.
"description_for_model": descriptionForModel,
"auth": {
"type": "service_http",
"authorization_type": "bearer",
"verification_tokens": {
"openai": params.chatgptVerificationToken,
}
},
"api": {
"type": "openapi",
"url": `${params.baseUrl}/chatgpt-plugin/openapi.json`
},
// URL used to fetch the logo. Suggested size: 512 x 512. Transparent backgrounds are supported.
// Must be an image, no GIFs are allowed.
"logo_url": `${params.baseUrl}/assets/android-chrome-512x512.png`,
// Email contact for safety/moderation, support, and deactivation
"contact_email": "[email protected]",
// Redirect URL for users to view plugin information
"legal_info_url": `${params.baseUrl}/chatgpt-plugin/legal.txt`
})
export async function onRequestGet(context) {
const {env, data} = context
const params = {
chatgptVerificationToken: env.CHATGPT_VERIFICATION_TOKEN,
baseUrl: data.baseUrl,
}
const responseBuilder = new ResponseBuilder(context)
return responseBuilder.getJsonResponse(pluginSpec(params))
}