Skip to content

Commit c8f9ce4

Browse files
committed
feat: add gpt3 function example
1 parent 31ec5ce commit c8f9ce4

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# 🧶 Priceloop NoCode Python External Functions Templates
1+
# 🧶 Priceloop NoCode Python Custom Functions Templates
22

33
You can create your own functions and then call them inside our [NoCode table](https://priceloop.ai/nocode), just like a built-in function. Here are some easy examples that you can use to write your own functions. Some of them are also deployed on our platform.
44

5-
https://user-images.githubusercontent.com/3866530/200024328-ea5cad88-c930-4544-a9d4-9838437978f0.mp4
5+
<https://user-images.githubusercontent.com/3866530/200024328-ea5cad88-c930-4544-a9d4-9838437978f0.mp4>
66

77
### Getting Started
88

@@ -13,7 +13,7 @@ conda create -n my_example python=3.8
1313
source activate my_example
1414
```
1515

16-
The easiest way to deploy our external functions is via our cli:
16+
The easiest way to deploy our custom functions is via our cli:
1717

1818
```bash
1919
npm install -g @priceloop/cli
@@ -36,7 +36,7 @@ After these steps, your new function will be available inside the specified work
3636

3737
Go to the app and type a new formula: `\my_example('World')`. It should return “Hello World”.
3838

39-
More information on how to deploy it to our platform please also go to our [documentation](https://priceloopai.notion.site/External-Functions-f78d153ab7b94a5f8a2f2cc5baa5e9d3).
39+
More information on how to deploy it to our platform please also go to our [documentation](https://docs.priceloop.ai/custom_functions).
4040

4141
### Testing
4242

gpt3/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# GPT3 Example
2+
3+
## Testing locally
4+
5+
1. Go to <https://openai.com/api/> and register an account
6+
2. Get the API key and replace the `<openai-key>` in the `event.json` with your key
7+
3. Run this to test:
8+
9+
```
10+
python-lambda-local function.py event.json -t 900
11+
```

gpt3/event.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"BatchedArgs": [["Extract name from email: [email protected]", "<openai-key>"], ["Extract name from email: [email protected]", "<openai-key>"]]
3+
}

gpt3/function.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import requests
3+
4+
def return_gpt3_results(input, api_key):
5+
headers = {
6+
"Authorization": "Bearer {}".format(api_key),
7+
}
8+
9+
json_data = {
10+
"model": "text-davinci-002",
11+
"prompt": input,
12+
"temperature": 0.8,
13+
"max_tokens": 60,
14+
"top_p": 1,
15+
"frequency_penalty": 0,
16+
"presence_penalty": 0,
17+
}
18+
response = requests.post("https://api.openai.com/v1/completions", headers=headers, json=json_data)
19+
return json.loads(response.content.decode("utf-8"))["choices"][0]["text"]
20+
21+
def handler(event, context):
22+
api_key = list(map(lambda row: row[1], event["BatchedArgs"]))[0]
23+
return list(map(lambda row: return_gpt3_results(row[0], api_key), event["BatchedArgs"]))

gpt3/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

0 commit comments

Comments
 (0)