ferrislucas / promptr Goto Github PK
View Code? Open in Web Editor NEWPromptr is a CLI tool that lets you use plain English to instruct GPT3 or GPT4 to make changes to your codebase.
License: MIT License
Promptr is a CLI tool that lets you use plain English to instruct GPT3 or GPT4 to make changes to your codebase.
License: MIT License
It would be nice if relative paths worked. I’d like to be able to use ~/something/whatever.txt
When running promptr -m gpt4 -p "Clean up the code in this file" foo.js
I get:
data: {
error: {
message: 'The model: `gpt-4` does not exist',
type: 'invalid_request_error',
param: null,
code: 'model_not_found'
}
}
Whenever I run promptr
I get an error along the lines of
Execution time: 7194ms
undefined:1
--BEGIN-FILE: test.rb
^
SyntaxError: No number after minus sign in JSON at position 1
Is there any way to fix the gateway timeout error?
data: {
error: {
code: 524,
message: 'Gateway timeout.',
param: null,
type: 'cf_gateway_timeout'
}
}
},
isAxiosError: true,
toJSON: [Function: toJSON]
}
It’s not super convenient having to specify each file to send separated by a space. It would be more ergonomic to be able to pass paths with wildcards.
Example:
Something like this would pass all files that end in .rb or .js. The ‘-r’ would make it recursive:
promptr *.rb *.js -r -p “summarize how this code works”
The -t option takes a string, path, or url. If the user passes a path or url that isn’t valid then the user should see a friendly error message.
I have GPT4 access, but I'm getting a 404 response, without any clues as to the where or why even with -v
.
OPENAI_API_KEY=[key here] promptr -m gpt4 -x -t refactor $(git ls-tree -r --name-only HEAD | grep ".js" | tr '\n' ' ') -p "Remove any unused methods -v"
Prompt token count: 322002
(node:58364) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
at createError (/Users/glenn/.nvm/versions/node/v14.19.0/lib/node_modules/@ifnotnowwhen/promptr/node_modules/axios/lib/core/createError.js:16:15)
at settle (/Users/glenn/.nvm/versions/node/v14.19.0/lib/node_modules/@ifnotnowwhen/promptr/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/Users/glenn/.nvm/versions/node/v14.19.0/lib/node_modules/@ifnotnowwhen/promptr/node_modules/axios/lib/adapters/http.js:322:11)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1334:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:58364) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:58364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Add the ability to change the openai endpoint (baseURL) as per OpenAI SDK to be able to leverage self hosted LLM.
Attached zip contains a modified packages.json for windows (basically the cp command and path needed to be modified for win).
I followed the command in the readme:
$ promptr -m gpt4 -p "Cleanup the code in these files" app/index.js
and get the below error:
data: {
error: {
message: 'The model: `gpt-4` does not exist',
type: 'invalid_request_error',
param: null,
code: 'model_not_found'
}
}
The prompt templates don’t use the suggested strings to separate instructions from context. See point 2 here: https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api
Right now, ‘context’ is a hash with keys that are file paths.
Hi, Thanks for your repo. I don't know why the below not works:
it is a minimal code to reproduce :
package main
import (
"crypto/md5"
"encoding/hex"
)
type Input struct {
Types string `json:"types"` // comments!
Json string `json:"json"`
Check_str string `json:"check_str"`
}
func validateInput(input Input) bool {
expected := getCheckStr(input)
return expected == input.Check_str
}
func getCheckStr(input Input) string {
str := input.Types + input.Json
hash := md5.Sum([]byte(str))
expected := hex.EncodeToString(hash[:])[0:10]
return expected
}
prompt: Make sample.go more efficient.
(node:19804) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `promptr --trace-warnings ...` to show where the warning was created)
Execution time: 14615ms
There was an error parsing the model's output:
{
"operations": [
{
"crudOperation": "update",
"filePath": "sample.go",
"fileContents": "package main\n\nimport (\n\t"crypto/md5"\n\t"encoding/hex"\n)\n\ntype Input struct {\n\tTypes string `json:\"types\"` // comments!\n\tJson string `json:\"json\"`\n\tCheck_str string `json:\"check_str\"`\n}\n\nfunc validateInput(input Input) bool {\n\texpected := getCheckStr(input)\n\n\treturn expected == input.Check_str\n}\n\nfunc getCheckStr(input Input) string {\n\tstr := input.Types + input.Json\n\thash := md5.Sum([]byte(str))\n\texpected := hex.EncodeToString(hash[:])[0:10]\n\treturn expected\n}\n"
}
]
}
Attemping to extract json:
{
"operations": [
{
"crudOperation": "update",
"filePath": "sample.go",
"fileContents": "package main\n\nimport (\n\t"crypto/md5"\n\t"encoding/hex"\n)\n\ntype Input struct {\n\tTypes string `json:\"types\"` // comments!\n\tJson string `json:\"json\"`\n\tCheck_str string `json:\"check_str\"`\n}\n\nfunc validateInput(input Input) bool {\n\texpected := getCheckStr(input)\n\n\treturn expected == input.Check_str\n}\n\nfunc getCheckStr(input Input) string {\n\tstr := input.Types + input.Json\n\thash := md5.Sum([]byte(str))\n\texpected := hex.EncodeToString(hash[:])[0:10]\n\treturn expected\n}\n"
}
]
}
SyntaxError: Unexpected token c in JSON at position 142
at JSON.parse (<anonymous>)
at /snapshot/promptr/dist/index.js
at w.call (/snapshot/promptr/dist/index.js)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async v.call (/snapshot/promptr/dist/index.js)
at async /snapshot/promptr/dist/index.js
node:internal/process/task_queues:95
runMicrotasks();
^
TypeError: Cannot read properties of null (reading 'operations')
at h.call (/snapshot/promptr/dist/index.js)
at w.call (/snapshot/promptr/dist/index.js)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async v.call (/snapshot/promptr/dist/index.js)
at async /snapshot/promptr/dist/index.js
Node.js v18.5.0
Btw, I read [a post today]https://github.com/minimaxir/simpleaichat/blob/main/examples/notebooks/simpleaichat_coding.ipynb). maybe we can use tricks in it, like "stop": ["``` ", "```\n"]
etc.
install:
# npm install -g @ifnotnowwhen/promptr
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '[email protected]',
npm WARN EBADENGINE required: { node: '>=14' },
npm WARN EBADENGINE current: { node: 'v12.22.12', npm: '7.5.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '[email protected]',
npm WARN EBADENGINE required: { node: '>=14' },
npm WARN EBADENGINE current: { node: 'v12.22.12', npm: '7.5.2' }
npm WARN EBADENGINE }
added 16 packages, and audited 17 packages in 2s
2 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
$sb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
$ promptr
file:///usr/local/lib/node_modules/@ifnotnowwhen/promptr/bin/index.js:3
await MainService.call()
^^^^^
SyntaxError: Unexpected reserved word
at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)
at async link (internal/modules/esm/module_job.js:42:21)
See the example below where the file /abc/test.txt
is referenced from inside a liquid comment block. The contents of the file are sent to the LLM, but I wouldn't expect them to be because the file reference is not part of the prompt.
Example:
Instructions here
{% comment %}
// this file shouldn't be included in the prompt sent to the LLM
See file /abc/test.txt
{% endcomment %}
It seems that sometimes GPT-4 doesn't return valid JSON, using """
as some kind of string delimiter:
"fileContents": """
import os
import json
... etc ...
"""
Does it need a stricter prompt?
Here's a full failed run:
promptr my-script.py -p "fix all the FIX comments in this Python script"
Execution time: 23615ms
There was an error parsing the model's output:
{
"operations": [
{
"crudOperation": "update",
"filePath": "my-script.py",
"fileContents": """
import os
import json
...
"""
}
]
}
Attemping to extract json:
{
"operations": [
{
"crudOperation": "update",
"filePath": "my-script.py",
"fileContents": """
import os
import json
...
"""
}
]
}
SyntaxError: Unexpected string in JSON at position 147
at JSON.parse (<anonymous>)
at extractOperationsFromOutput (file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/services/ExtractOperationsFromOutput.js:14:29)
at Function.call (file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/services/PromptrService.js:57:26)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Function.call (file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/Main.js:38:12)
at async file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/bin/index.js:4:18
file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/services/RefactorResultProcessor.js:6
data.operations.forEach((operation) => {
^
TypeError: Cannot read properties of null (reading 'operations')
at Function.call (file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/services/RefactorResultProcessor.js:6:10)
at Function.call (file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/services/PromptrService.js:62:37)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Function.call (file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/src/Main.js:38:12)
at async file:///home/myuser/.nvm/versions/node/v16.19.0/lib/node_modules/@ifnotnowwhen/promptr/bin/index.js:4:18
The -p option takes a string , path , or url. If the value is a path or url, and the prompt isn’t found (because the path or url don’t exist) then the user should see a friendly error message.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.