Spaces:
Runtime error
Runtime error
satya dillikar
commited on
Commit
·
0832091
1
Parent(s):
3d00849
chatgpt plugin
Browse files- .env +6 -0
- Dockerfile +42 -0
- README.md +7 -9
- app/ai-plugin.json +17 -0
- app/ai-plugin.json.template +17 -0
- app/entrypoint.sh +14 -0
- app/main.py +49 -0
- app/openapi.yaml +21 -0
- app/openapi.yaml.template +21 -0
- archive/Makefile +40 -0
- archive/docker-compose.yaml +16 -0
- archive/dot_env_export +6 -0
- dot_env +6 -0
- requirements.txt +3 -0
- script.sh +12 -0
.env
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# .env
|
2 |
+
export FLASK_HOST=0.0.0.0
|
3 |
+
export FLASK_PORT=5085
|
4 |
+
export ALPHA_VANTAGE_API_KEY=1095SN3T01WJENIZ
|
5 |
+
export ALPHA_VANTAGE_BASE_URL="https://www.alphavantage.co/query"
|
6 |
+
export MY_API_DOMAIN_URL="http://192.168.1.235:5085"
|
Dockerfile
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# set base image (host OS)
|
2 |
+
FROM python:3.11-slim
|
3 |
+
|
4 |
+
# Install gettext for envsubst
|
5 |
+
RUN apt-get update && apt-get install -y gettext && rm -rf /var/lib/apt/lists/*
|
6 |
+
|
7 |
+
|
8 |
+
RUN pip install --upgrade pip
|
9 |
+
|
10 |
+
RUN adduser --disabled-password -q worker
|
11 |
+
USER worker
|
12 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
13 |
+
|
14 |
+
# set the working directory in the container
|
15 |
+
WORKDIR /code
|
16 |
+
|
17 |
+
# ENV PATH='/home/worker/.local/bin:$PATH'
|
18 |
+
RUN mkdir /code/app
|
19 |
+
|
20 |
+
COPY --chown=worker:worker app /code/app
|
21 |
+
|
22 |
+
# install dependencies
|
23 |
+
COPY --chown=worker:worker requirements.txt requirements.txt
|
24 |
+
RUN pip install --user -r requirements.txt
|
25 |
+
|
26 |
+
LABEL maintainer="Satya Dillikar <satya.dillikar@gmail.com>" \
|
27 |
+
version="1.0.0"
|
28 |
+
|
29 |
+
ARG FLASK_PORT
|
30 |
+
# Expose port for Flask
|
31 |
+
EXPOSE ${FLASK_PORT}
|
32 |
+
RUN echo FLASK_PORT $FLASK_PORT
|
33 |
+
|
34 |
+
# ARG MY_API_DOMAIN_URL
|
35 |
+
# ENV MY_API_DOMAIN_URL=${MY_API_DOMAIN_URL}
|
36 |
+
# RUN echo MY_API_DOMAIN_URL $MY_API_DOMAIN_URL
|
37 |
+
|
38 |
+
# Set the entrypoint
|
39 |
+
ENTRYPOINT ["app/entrypoint.sh"]
|
40 |
+
|
41 |
+
# command to run on container start
|
42 |
+
CMD ["python", "app/main.py" ]
|
README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
-
|
2 |
-
title: Chatgptplugins
|
3 |
-
emoji: 🐢
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: purple
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
---
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Project Summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
In this repo, you'll find the code files needed to create a simple ChatGPT plugin that retrieves information for a single stock.
|
4 |
+
- **main.py**: A simple Flask program written to retrieve stock informatiom from an external API (Alpha Vantage)
|
5 |
+
- **ai-plugin.json**: The plugin manifest file that contains plugin metadata (name, logo, etc.) and auth type
|
6 |
+
- **openapi.yaml**: The OpenAPI specification with details about your API so ChatGPT understands what it does
|
7 |
+
|
8 |
+
For a step-by-step walk-through of how to set up a development environment and install the plugin in ChatGPT, check out [this YouTube video](https://youtu.be/-GV7DAJ4dVU).
|
app/ai-plugin.json
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"schema_version": "v1",
|
3 |
+
"name_for_human": "Stock Quote",
|
4 |
+
"name_for_model": "StockQuote",
|
5 |
+
"description_for_human": "Get price and volume information for a given stock.",
|
6 |
+
"description_for_model": "Get price and volume information for a given stock. Always display results using markdown tables.",
|
7 |
+
"auth": {
|
8 |
+
"type": "none"
|
9 |
+
},
|
10 |
+
"api": {
|
11 |
+
"type": "openapi",
|
12 |
+
"url": "https://localhost.com/openapi.yaml"
|
13 |
+
},
|
14 |
+
"logo_url": "https://localhost.com/logo.png",
|
15 |
+
"contact_email": "support@example.com",
|
16 |
+
"legal_info_url": "https://localhost.com/legal"
|
17 |
+
}
|
app/ai-plugin.json.template
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"schema_version": "v1",
|
3 |
+
"name_for_human": "Stock Quote",
|
4 |
+
"name_for_model": "StockQuote",
|
5 |
+
"description_for_human": "Get price and volume information for a given stock.",
|
6 |
+
"description_for_model": "Get price and volume information for a given stock. Always display results using markdown tables.",
|
7 |
+
"auth": {
|
8 |
+
"type": "none"
|
9 |
+
},
|
10 |
+
"api": {
|
11 |
+
"type": "openapi",
|
12 |
+
"url": "${MY_API_DOMAIN_URL}/openapi.yaml"
|
13 |
+
},
|
14 |
+
"logo_url": "${MY_API_DOMAIN_URL}/logo.png",
|
15 |
+
"contact_email": "support@example.com",
|
16 |
+
"legal_info_url": "${MY_API_DOMAIN_URL}/legal"
|
17 |
+
}
|
app/entrypoint.sh
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Use envsubst to replace variables in the config file template
|
4 |
+
envsubst < app/openapi.yaml.template > app/openapi.yaml
|
5 |
+
envsubst < app/ai-plugin.json.template > app/ai-plugin.json
|
6 |
+
|
7 |
+
# Print substituted config for verification (optional)
|
8 |
+
echo "file openapi.yaml"
|
9 |
+
cat app/openapi.yaml
|
10 |
+
echo "file ai-plugin.json"
|
11 |
+
cat app/ai-plugin.json
|
12 |
+
|
13 |
+
# Execute the main application command
|
14 |
+
exec "$@"
|
app/main.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, send_from_directory
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
# Replace "YOUR_API_KEY_HERE" with your actual API key.
|
7 |
+
# API_KEY = "YOUR_API_KEY_HERE"
|
8 |
+
# BASE_URL = "https://www.alphavantage.co/query"
|
9 |
+
# Load environment variables from .env file
|
10 |
+
load_dotenv()
|
11 |
+
app = Flask(__name__)
|
12 |
+
|
13 |
+
|
14 |
+
@app.route("/")
|
15 |
+
def index():
|
16 |
+
return "Hello chatgptplugins! Your web application is working!"
|
17 |
+
|
18 |
+
|
19 |
+
@app.route('/stock', methods=['GET'])
|
20 |
+
def get_stock_data():
|
21 |
+
API_KEY = os.getenv("ALPHA_VANTAGE_API_KEY")
|
22 |
+
BASE_URL = os.getenv("ALPHA_VANTAGE_BASE_URL")
|
23 |
+
print("BASE_URL: ", BASE_URL)
|
24 |
+
symbol = request.args.get('symbol')
|
25 |
+
|
26 |
+
params = {"function": "GLOBAL_QUOTE", "symbol": symbol, "apikey": API_KEY}
|
27 |
+
|
28 |
+
response = requests.get(BASE_URL, params=params)
|
29 |
+
return response.json()
|
30 |
+
|
31 |
+
|
32 |
+
@app.route('/.well-known/ai-plugin.json')
|
33 |
+
def serve_ai_plugin():
|
34 |
+
return send_from_directory(".",
|
35 |
+
'ai-plugin.json',
|
36 |
+
mimetype='application/json')
|
37 |
+
|
38 |
+
|
39 |
+
@app.route('/openapi.yaml')
|
40 |
+
def serve_openapi_yaml():
|
41 |
+
return send_from_directory('.', 'openapi.yaml', mimetype='text/yaml')
|
42 |
+
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
host = os.getenv("FLASK_HOST", "0.0.0.0")
|
46 |
+
port = int(os.getenv("FLASK_PORT", 5000))
|
47 |
+
print("host: ", host)
|
48 |
+
print(" port: ", port)
|
49 |
+
app.run(host=host, port=port, debug=True)
|
app/openapi.yaml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openapi: 3.0.1
|
2 |
+
info:
|
3 |
+
title: Stock Quote
|
4 |
+
description: Get price and volume information for a given stock.
|
5 |
+
version: "v1"
|
6 |
+
servers:
|
7 |
+
- url: "https://localhost.com"
|
8 |
+
paths:
|
9 |
+
/stock:
|
10 |
+
get:
|
11 |
+
operationId: getStockData
|
12 |
+
summary: Retrieves the price and volume information for a given stock symbol.
|
13 |
+
parameters:
|
14 |
+
- in: query
|
15 |
+
name: symbol
|
16 |
+
schema:
|
17 |
+
type: string
|
18 |
+
description: The symbol of the stock to get a quote for. For example, the stock symbol MSFT represents the company Microsoft.
|
19 |
+
responses:
|
20 |
+
"200":
|
21 |
+
description: OK
|
app/openapi.yaml.template
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openapi: 3.0.1
|
2 |
+
info:
|
3 |
+
title: Stock Quote
|
4 |
+
description: Get price and volume information for a given stock.
|
5 |
+
version: "v1"
|
6 |
+
servers:
|
7 |
+
- url: "${MY_API_DOMAIN_URL}"
|
8 |
+
paths:
|
9 |
+
/stock:
|
10 |
+
get:
|
11 |
+
operationId: getStockData
|
12 |
+
summary: Retrieves the price and volume information for a given stock symbol.
|
13 |
+
parameters:
|
14 |
+
- in: query
|
15 |
+
name: symbol
|
16 |
+
schema:
|
17 |
+
type: string
|
18 |
+
description: The symbol of the stock to get a quote for. For example, the stock symbol MSFT represents the company Microsoft.
|
19 |
+
responses:
|
20 |
+
"200":
|
21 |
+
description: OK
|
archive/Makefile
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
NAME:=chatgptplugins
|
2 |
+
DOCKER_REPOSITORY:=dsatya6
|
3 |
+
VERSION:=v1
|
4 |
+
DOCKER_IMAGE_NAME:=$(DOCKER_REPOSITORY)/$(NAME):$(VERSION)
|
5 |
+
|
6 |
+
.PHONY: build clean test build-container push-container test-container
|
7 |
+
|
8 |
+
build :
|
9 |
+
python app/main.py
|
10 |
+
|
11 |
+
clean :
|
12 |
+
@echo ""
|
13 |
+
|
14 |
+
test:
|
15 |
+
python app/main.py
|
16 |
+
|
17 |
+
|
18 |
+
build-container :
|
19 |
+
@docker build $(grep -v '^#' dot_env | sed 's/^/--build-arg /') -t $(DOCKER_IMAGE_NAME) --no-cache --progress plain .
|
20 |
+
|
21 |
+
push-container :
|
22 |
+
@docker push $(DOCKER_IMAGE_NAME)
|
23 |
+
|
24 |
+
test-container :
|
25 |
+
@docker rm -f $(DOCKER_IMAGE_NAME) || true
|
26 |
+
# python server is running a 5000, map to docker 5000
|
27 |
+
@docker run -dp 5082:5082 --name=$(NAME) $(DOCKER_IMAGE_NAME)
|
28 |
+
@docker ps
|
29 |
+
@sleep 5
|
30 |
+
@curl http://localhost:5082/
|
31 |
+
@echo ""
|
32 |
+
@sleep 2
|
33 |
+
@curl http://localhost:5082/openapi.yaml
|
34 |
+
@echo ""
|
35 |
+
@sleep 2
|
36 |
+
@curl http://localhost:5082/.well-known/ai-plugin.json
|
37 |
+
@echo ""
|
38 |
+
@sleep 2
|
39 |
+
@docker stop $(NAME) || true
|
40 |
+
@docker rm -f $(NAME) || true%
|
archive/docker-compose.yaml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
services:
|
2 |
+
web:
|
3 |
+
build:
|
4 |
+
context: .
|
5 |
+
dockerfile: Dockerfile
|
6 |
+
args:
|
7 |
+
FLASK_HOST: ${FLASK_HOST}
|
8 |
+
FLASK_PORT: ${FLASK_PORT}
|
9 |
+
MY_API_DOMAIN_URL: ${MY_API_DOMAIN_URL}
|
10 |
+
ports:
|
11 |
+
- "${FLASK_PORT}:${FLASK_PORT}"
|
12 |
+
env_file:
|
13 |
+
- .env # Load environment variables from .env file
|
14 |
+
environment:
|
15 |
+
FLASK_HOST: ${FLASK_HOST}
|
16 |
+
FLASK_PORT: ${FLASK_PORT}
|
archive/dot_env_export
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# .env
|
2 |
+
export FLASK_HOST=0.0.0.0
|
3 |
+
export FLASK_PORT=5085
|
4 |
+
export ALPHA_VANTAGE_API_KEY=1095SN3T01WJENIZ
|
5 |
+
export ALPHA_VANTAGE_BASE_URL="https://www.alphavantage.co/query"
|
6 |
+
export MY_API_DOMAIN_URL="http://192.168.1.235:5085"
|
dot_env
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# .env
|
2 |
+
FLASK_HOST=0.0.0.0
|
3 |
+
FLASK_PORT=5085
|
4 |
+
ALPHA_VANTAGE_API_KEY=1095SN3T01WJENIZ
|
5 |
+
ALPHA_VANTAGE_BASE_URL="https://www.alphavantage.co/query"
|
6 |
+
MY_API_DOMAIN_URL="http://192.168.1.235:5085"
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Flask==2.3.3
|
2 |
+
requests==2.32.2
|
3 |
+
python-dotenv==1.0.0
|
script.sh
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
docker build $(grep -v '^#' dot_env | sed 's/^/--build-arg /') -t dsatya6/chatgptplugins:v1 .
|
2 |
+
|
3 |
+
docker run -p 5082:5082 --name=chatgptplugins --env-file dot_env dsatya6/chatgptplugins:v1
|
4 |
+
docker stop chatgptplugins
|
5 |
+
docker rm chatgptplugins
|
6 |
+
|
7 |
+
curl http://172.17.0.2:5085
|
8 |
+
curl http://172.17.0.2:5085/openapi.yaml
|
9 |
+
curl http://172.17.0.2:5085/.well-known/ai-plugin.json
|
10 |
+
|
11 |
+
|
12 |
+
docker rmi dsatya6/chatgptplugins:v1
|