ysharma HF staff commited on
Commit
bd9076a
·
1 Parent(s): 4357e54

added steps for adding plugins

Browse files
Files changed (1) hide show
  1. README.md +71 -0
README.md CHANGED
@@ -11,3 +11,74 @@ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ ## Steps to add new Plugins to your Langchain-Gradio ChatGPT PLUGIN WebUI
16
+
17
+ 1. **Acquire the API Endpoint**
18
+ - You need an API which you can query, and for this example let's consider using a The Bored API.
19
+ - **API Endpoint**: [https://www.boredapi.com/api/activity/?type=](https://www.boredapi.com/api/activity/?type=)
20
+
21
+ 2. **Create a Function to Query the API**
22
+ - You can access any Gradio demo as an API via the Gradio Python Client.
23
+ ```python
24
+ def bored_api(activity_type) -> str:
25
+ '''
26
+ Get a random activity to do based on the activity type.
27
+ '''
28
+ activity_type_list = ["education", "recreational", "social", "diy", "charity", "cooking", "relaxation", "music", "busywork"]
29
+ activity_type = activity_type.lower()
30
+ if activity_type not in activity_type_list:
31
+ activity_type = random.choice(activity_type_list)
32
+
33
+ api_url = "https://www.boredapi.com/api/activity/?type=" + activity_type
34
+ response = requests.get(
35
+ api_url
36
+ )
37
+ return response.json()['activity']
38
+ ```
39
+
40
+ 3. **Add Function definitions**
41
+ - Add the function definition to the `gpt_function_definitions.py` file (simply copy and paste). Don't forget to add function description in docstring.
42
+ - Add required imports
43
+ ```python
44
+ from gpt_function_definitions import generate_image, generate_caption, get_news, bored_api
45
+
46
+ ```
47
+
48
+ 4. **Add the function to the Tools list**
49
+ - Add a description - describe what your function does. Models like GPT3.5/4 support Function Calling. The OpenAI Functions Agent from Langchain is designed to work with these functions and models.
50
+ - Name - add a name of your function, don't include spaces
51
+
52
+ ```python
53
+ tools = [
54
+ #image generation
55
+ ...
56
+
57
+ # Describe an image
58
+ ...
59
+
60
+ # Get lattest top news
61
+ ...
62
+
63
+ # Bored Api
64
+ Tool.from_function(
65
+ func=bored_api,
66
+ name="bored_api",
67
+ description="Get a random activity to do based on the activity type"
68
+ # coroutine= ... <- you can specify an async method if desired as well
69
+ ),
70
+ ]
71
+ ```
72
+
73
+ 5. **Update the Chatbot Layout**
74
+ - Go to the Blocks Chatbot layout and add a new checkbox for your plugin as:
75
+ ```python
76
+ bored = gr.Checkbox(label="🙄bored", value=False)
77
+ ```
78
+ - Add the new checkbox component (example - <i>bored</i>) to your submit and click events for your chatbot and to the predict function accordingly.
79
+ - And also to the `plugins` list in `predict`
80
+ ```python
81
+ plugins = [stable_diff, image_cap, top_news, search, bored]
82
+ ```
83
+
84
+ **Thats it! you have added your own brand new CHATGPT Plugin for yourself. Go PLAY!!**