-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add cli auto-prompt analyze - prompt analyzer in cli #288
Conversation
log10/cli/autoprompt.py
Outdated
prompt = "\n\n".join([f'{m["role"]}: {m["content"]}' for m in prompt_json if m["role"] in ALLOWED_ROLES]) | ||
elif isinstance(prompt_json, dict) and "request" in prompt_json and "messages" in prompt_json["request"]: | ||
# prompt is a log10 completion | ||
prompt = "\n\n".join( | ||
[ | ||
f'{m["role"]}: {m["content"]}' | ||
for m in prompt_json["request"]["messages"] | ||
if m["role"] in ALLOWED_ROLES | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can extract the building prompt in its own function, wdyt?
log10/cli/autoprompt.py
Outdated
if isinstance(prompt_json, list) and all("role" in item and "content" in item for item in prompt_json): | ||
# prompt is a list of messages | ||
prompt = "\n\n".join([f'{m["role"]}: {m["content"]}' for m in prompt_json if m["role"] in ALLOWED_ROLES]) | ||
elif isinstance(prompt_json, dict) and "request" in prompt_json and "messages" in prompt_json["request"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
elif isinstance(prompt_json, dict) and "request" in prompt_json and "messages" in prompt_json["request"]: | |
elif isinstance(prompt_json, dict) and "messages" in prompt_json.get("request", {}): |
log10/cli/autoprompt.py
Outdated
from log10.prompt_analyzer import PromptAnalyzer, display_prompt_analyzer_suggestions | ||
|
||
|
||
# ignor "tool" and "funciton" roles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# ignor "tool" and "funciton" roles | |
# ignore "tool" and "function" roles |
Analyze a prompt or messages and provide suggestions on how to improve it. | ||
|
||
Options: | ||
-p, --prompt TEXT The prompt to analyze. Provide a string or a file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a separate flag for file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are checking the file internally and keeping the option simple for users. Similar to what we have for other cli option, like --ids for benchmark_models cli.
|
||
# try to parse the prompt as a json | ||
try: | ||
prompt_json = json.loads(prompt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if prompt
is empty after parsing the text or reading from the file, should we exit immediately?
* string * openai chat request messages * log10 completion format
ee52421
to
5f9bdb5
Compare
Three input format allowed:
[{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi"}]
Doc:
e.g.
log10 auto-prompt analyze -p "this is a test prompt for autoprompt cli"
or pass a file
log10 auto-prompt analyze -p test.prompt