chat todo plugin
1.0.0
TODO 목록 관리를위한 ChatGpt 플러그인
[plugin-repo]
| - main.py
| - manifest.json
| - openapi.yaml
| - logo.png
` - ... # other
플러그인-관리 : 모든 플러그인에는 AI-Plugin.json 파일이 필요하며 API 도메인에서 호스팅해야합니다.
{
"schema_version" : " v1 " ,
"name_for_human" : " TODO Plugin (service http) " ,
"name_for_model" : " todo " ,
"description_for_human" : " Plugin for managing a TODO list, you can add, remove and view your TODOs. " ,
"description_for_model" : " Plugin for managing a TODO list, you can add, remove and view your TODOs. " ,
"auth" : {
"type" : " service_http " ,
"authorization_type" : " bearer " ,
"verification_tokens" : {
"openai" : " <YOUR_OPENAI_KEY> "
}
},
"api" : {
"type" : " openapi " ,
"url" : " https://<YOUR_REPO>.<YOUR_OWNER>.repl.co/openapi.yaml " ,
"is_user_authenticated" : false
},
"logo_url" : " https://<YOUR_REPO>.<YOUR_OWNER>.repl.co/logo.png " ,
"contact_email" : " <YOUR_EMAIL> " ,
"legal_info_url" : " http://www.example.com/legal "
}
<YOUR_OPENAI_KEY>
: 당신의 OpenAi API 키<YOUR_REPO>
: replit 앱 이름입니다<YOUR_OWNER>
: replit username입니다<YOUR_EMAIL>
: 이메일OpenApi-definition : API를 문서화하려면 OpenApi 사양입니다. Chatgpt의 모델은 OpenAPI 사양 및 매니페스트 파일에 정의 된 것 외에 API에 대해 아무것도 알지 못합니다. 즉, 광범위한 API가있는 경우 모든 기능을 모델에 노출시킬 필요가 없으며 특정 엔드 포인트를 선택할 수 있습니다.
openapi : 3.0.1
info :
title : TODO Plugin
description : A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user's username, ask them first before making queries to the plugin. Otherwise, use the username "global".
version : ' v1 '
servers :
# product: http://www.example.com
- url : http://localhost:5002
paths :
/todos/{username} :
get :
operationId : getTodos
summary : Get the list of todos
parameters :
- in : path
name : username
schema :
type : string
required : true
description : The name of the user.
responses :
" 200 " :
description : OK
content :
application/json :
schema :
$ref : ' #/components/schemas/getTodosResponse '
# ...
import os
import quart
import quart_cors
from quart import Quart , jsonify , request
PORT = 5002
TODOS = {}
# Get authentication key from environment variable
SERVICE_AUTH_KEY = os . environ . get ( "SERVICE_AUTH_KEY" )
# Create a Quart app and enable CORS
app = quart_cors . cors (
Quart ( __name__ ),
allow_origin = [
f"http://localhost: { PORT } " ,
"https://chat.openai.com" ,
]
)
# Add a before_request hook to check for authorization header
@ app . before_request
def assert_auth_header ():
auth_header = request . headers . get ( "Authorization" )
print ( auth_header )
# check if the header is missing or incorrect, and return an error if needed
if not auth_header or auth_header != f"Bearer { SERVICE_AUTH_KEY } " :
return jsonify ({ "error" : "Unauthorized" }), 401
# Add a route to get all todos
@ app . route ( "/todos" , methods = [ "GET" ])
async def get_todos ():
return jsonify ( TODOS )
# Add a route to get all todos for a specific user
@ app . route ( "/todos/<string:username>" , methods = [ "GET" ])
async def get_todo_user ( username ):
todos = TODOS . get ( username , [])
return jsonify ( todos )
# Add a route to add a todo for a specific user
@ app . route ( "/todos/<string:username>" , methods = [ "POST" ])
async def add_todo ( username ):
request_data = await request . get_json ()
todo = request_data . get ( "todo" , "" )
TODOS . setdefault ( username , []). append ( todo )
return jsonify ({ "status" : "success" })
# Add a route to delete a todo for a specific user
@ app . route ( "/todos/<string:username>" , methods = [ "DELETE" ])
async def delete_todo ( username ):
request_data = await request . get_json ()
todo_idx = request_data . get ( "todo_idx" , - 1 )
if 0 <= todo_idx < len ( TODOS . get ( username , [])):
TODOS [ username ]. pop ( todo_idx )
return jsonify ({ "status" : "success" })
@ app . get ( "/logo.png" )
async def plugin_logo ():
filename = 'logo.png'
return await quart . send_file ( filename , mimetype = 'image/png' )
@ app . get ( "/.well-known/ai-plugin.json" )
async def plugin_manifest ():
host = request . headers [ 'Host' ]
with open ( "manifest.json" ) as f :
text = f . read ()
text = text . replace ( "PLUGIN_HOSTNAME" , f"https:// { host } " )
return quart . Response ( text , mimetype = "text/json" )
@ app . get ( "/openapi.yaml" )
async def openapi_spec ():
host = request . headers [ 'Host' ]
with open ( "openapi.yaml" ) as f :
text = f . read ()
text = text . replace ( "PLUGIN_HOSTNAME" , f"https:// { host } " )
return quart . Response ( text , mimetype = "text/yaml" )
def main ():
app . run ( debug = True , host = "0.0.0.0" , port = PORT )
if __name__ == "__main__" :
main ()
Create Repl
버튼을 클릭하십시오.Import from GitHub
클릭하십시오.https://github.com/lencx/chat-todo-plugin
입력하고 Python
언어로 선택하십시오.Import from GitHub
클릭하고 초기화가 완료 될 때까지 기다립니다.Run
버튼을 클릭하고 실행이 완료 될 때까지 기다립니다. curl -X GET http://0.0.0.0:5002/todos
-H ' Content-Type: application/json '
-H ' Authorization: Bearer $SERVICE_AUTH_KEY '
curl -X GET http://0.0.0.0:5002/todos/lencx
-H ' Content-Type: application/json '
-H ' Authorization: Bearer $SERVICE_AUTH_KEY '
curl -X POST http://0.0.0.0:5002/todos/lencx
-H ' Content-Type: application/json '
-H ' Authorization: Bearer $SERVICE_AUTH_KEY '
-d ' { "todo": "hello" } '
curl -X DELETE http://0.0.0.0:5002/todos/lencx
-H ' Content-Type: application/json '
-H ' Authorization: Bearer $SERVICE_AUTH_KEY '
-d ' { "todo_idx": 0 } '