-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from pynput.keyboard import Key, Controller | ||
from dotenv import load_dotenv | ||
import os | ||
import openai | ||
|
||
load_dotenv() | ||
|
||
openai.api_key = os.getenv("API_KEY") | ||
|
||
params = { | ||
'engine': 'text-davinci-003', | ||
'prompt': '', | ||
'max_tokens': 496, | ||
'temperature': 0.7, | ||
} | ||
|
||
endpoint = "localhost:3333" | ||
|
||
keyboard = Controller() | ||
|
||
def sendkeys(args): | ||
# open sublime in new terminal window | ||
os.system("open /Applications/Sublime\ Text.app") | ||
|
||
params.update({"prompt": args}) | ||
response = openai.Completion.create(**params) | ||
|
||
print("Sending keys: ", response["choices"][0]["text"]) | ||
keyboard.type(response["choices"][0]["text"]) | ||
return 200 | ||
|
||
def test(): | ||
a = sendkeys("Hello, world!") | ||
if a == 200: | ||
print("Success!") | ||
|
||
if __name__ == "__main__": | ||
print("api key: ", os.getenv("API_KEY")) | ||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"schema_version": "v1", | ||
"name_for_human": "puterbot plugin", | ||
"name_for_model": "openadapt-puterbot", | ||
"description_for_human": "Connect to ChatGPT", | ||
"description_for_model": "Utilize puterbot for process automation, be precise.", | ||
"auth": { | ||
"type": "none" | ||
}, | ||
"api": { | ||
"type": "openapi", | ||
"url": "http://localhost:3333/.well-known/openapi.yaml", | ||
"is_user_authenticated": false | ||
}, | ||
"logo_url": "https://avatars.githubusercontent.com/u/67930343?s=200&v=4", | ||
"contact_email": "[email protected]", | ||
"legal_info_url": "todo.todo" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import uvicorn | ||
from typing import List, Dict | ||
from fastapi import FastAPI, File, Form, HTTPException, Body | ||
from starlette.responses import FileResponse | ||
from fastapi.middleware.cors import CORSMiddleware | ||
# import datetime, maybe for timestamps? | ||
from data.demo import ( | ||
sendkeys | ||
) | ||
|
||
|
||
# USEFUL : https://github.com/NextWordDev/chatgpt-plugins/tree/main | ||
|
||
app = FastAPI() | ||
|
||
PORT = 3333 | ||
|
||
origins = [ | ||
f"http://localhost:{PORT}", | ||
"https://chat.openai.com", | ||
] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
|
||
def _automate_helper(data): | ||
out = sendkeys(data) | ||
return out | ||
|
||
|
||
#@app.post("/automate", response_model=Dict) | ||
@app.post("/") | ||
async def automate(data: str): | ||
return _automate_helper(data) | ||
|
||
|
||
@app.route("/.well-known/ai-plugin.json") | ||
async def get_manifest(request): | ||
file_path = "./server/ai-plugin.json" | ||
return FileResponse(file_path, media_type="text/json", headers={"Cache-Control": "no-store"}) | ||
|
||
|
||
@app.route("/.well-known/logo.png") | ||
async def get_logo(request): | ||
file_path = "./server/logo.png" | ||
return FileResponse(file_path, media_type="text/json", headers={"Cache-Control": "no-store"}) | ||
|
||
|
||
@app.route("/.well-known/openapi.yaml") | ||
async def get_openapi(request): | ||
file_path = "./server/openapi.yaml" | ||
return FileResponse(file_path, media_type="text/json", headers={"Cache-Control": "no-store"}) | ||
|
||
|
||
@app.on_event("startup") | ||
async def startup(): | ||
print("Starting up...") | ||
|
||
|
||
def start(): | ||
uvicorn.run("server.main:app", host="localhost", port=PORT, reload=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
openapi: 3.0.2 | ||
info: | ||
title: FastAPI | ||
version: 0.1.0 | ||
paths: | ||
"/automate": | ||
post: | ||
summary: Integrate with puterbot. | ||
operationId: automate_automate_post | ||
description: Integrate with puterbot. | ||
parameters: | ||
- required: true | ||
schema: | ||
title: Data | ||
type: string | ||
name: data | ||
in: query | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
$ref: '#/components/schemas/getOutputResponse' | ||
'422': | ||
description: Validation Error | ||
content: | ||
application/json: | ||
schema: | ||
"$ref": "#/components/schemas/HTTPValidationError" | ||
components: | ||
schemas: | ||
HTTPValidationError: | ||
title: HTTPValidationError | ||
type: object | ||
properties: | ||
detail: | ||
title: Detail | ||
type: array | ||
items: | ||
"$ref": "#/components/schemas/ValidationError" | ||
ValidationError: | ||
title: ValidationError | ||
required: | ||
- loc | ||
- msg | ||
- type | ||
type: object | ||
properties: | ||
loc: | ||
title: Location | ||
type: array | ||
items: | ||
anyOf: | ||
- type: string | ||
- type: integer | ||
msg: | ||
title: Message | ||
type: string | ||
type: | ||
title: Error Type | ||
type: string | ||
getOutputResponse: | ||
type: object | ||
properties: | ||
data: | ||
type: string | ||
message: | ||
type: string | ||
status: | ||
type: string | ||
timestamp: | ||
type: string | ||
description: response model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters