Skip to content
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

AAP-30426: Lightspeed API playbook generation and explanation to accept a new custom_prompt field #1322

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

manstis
Copy link
Contributor

@manstis manstis commented Sep 23, 2024

Jira Issue: https://issues.redhat.com/browse/AAP-30426

Description

Support customPrompt JSON field for both Playbook Generation and Explanation.

Playbook Generation

  • The backend expects {goal} or both {goal} and {outline} keywords to be present in the custom_prompt
  • Depending on if Goal or both Goal and Outline are provided

Playbook Explanation

  • The backend expects {playbook} keyword to be present in the custom_prompt

Testing

Steps to test

  1. Pull down the PR
  2. make start-backends
  3. make create-application
  4. Run server
  5. Create User API token:
  • Login into Lightspeed as somebody
  • Login to http://localhost:8000/admin as Django admin
  • Create an Access Token for the User you logged into Lightspeed as
  1. Run generation tests:
  • Valid "custom prompt"
curl -X 'POST' \
'http://localhost:8000/api/v0/ai/generations/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token_created_above>' \
-d '{
"text": "Install apache",
"customPrompt": "You are an Ansible Expert. Generate a playbook to do {goal}"
}'

Response should be OK.

curl -X 'POST' \
'http://localhost:8000/api/v0/ai/generations/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token_created_above>' \
-d '{
"text": "Install apache",
"outline": "1. Install apache",
"customPrompt": "You are an Ansible Expert. Generate a playbook to do {goal} along the lines of {outline}"
}'

Response should be OK.

  • Invalid "custom prompt"
curl -X 'POST' \
'http://localhost:8000/api/v0/ai/generations/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token_created_above>' \
-d '{
"text": "Install apache",
"customPrompt": "You are an Ansible Expert. Generate a playbook to do something"
}'

Response should represent:

{"customPrompt":["'{goal}' placeholder expected."]}
curl -X 'POST' \
'http://localhost:8000/api/v0/ai/generations/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token_created_above>' \
-d '{
"text": "Install apache",
"outline": "1. Install apache",
"customPrompt": "You are an Ansible Expert. Generate a playbook to do {goal} along the lines of something"
}'

Response should represent:

{"customPrompt":["'{outline}' placeholder expected when 'outline' provided."]}
  1. Run explanation tests:
  • Valid "custom prompt"
curl -X 'POST' \
'http://localhost:8000/api/v0/ai/explanations/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token_created_above>' \
-d '{
"content": "---\n- name: Install apache\n  hosts: all\n  tasks:\n    - name: Install apache\n      ansible.builtin.package:\n        name: httpd\n        state: present\n    - name: Start apache\n      ansible.builtin.service:\n        name: httpd\n        state: started\n",
"customPrompt": "You are an Ansible Expert. Explain playbook {playbook}"
}'

Response should be OK.

  • Invalid "custom prompt"
curl -X 'POST' \
'http://localhost:8000/api/v0/ai/explanations/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token_created_above>' \
-d '{
"content": "---\n- name: Install apache\n  hosts: all\n  tasks:\n    - name: Install apache\n      ansible.builtin.package:\n        name: httpd\n        state: present\n    - name: Start apache\n      ansible.builtin.service:\n        name: httpd\n        state: started\n",
"customPrompt": "You are an Ansible Expert. Explain playbook something"
}'

Response should represent:

{"customPrompt":["'{playbook}' placeholder expected."]}

Scenarios tested

As above.

Production deployment

  • This code change is ready for production on its own
  • This code change requires the following considerations before going to production:

See ansible/vscode-ansible#1545

@manstis manstis force-pushed the AAP-30426 branch 2 times, most recently from 4cb8c9d to 75b7426 Compare September 24, 2024 08:43
@manstis manstis changed the title [DRAFT] AAP-30426: Lightspeed API playbook generation and explanation to accept a new custom_prompt field AAP-30426: Lightspeed API playbook generation and explanation to accept a new custom_prompt field Sep 24, 2024
@manstis manstis marked this pull request as ready for review September 24, 2024 09:03
@manstis
Copy link
Contributor Author

manstis commented Sep 24, 2024

I believe @TamiTakamiya may be changing the MODEL_ID/SPACE_ID used for Playbook Generation/Explanation.

That however does not affect the changes made here.

goneri
goneri previously approved these changes Sep 25, 2024
@TamiTakamiya
Copy link
Contributor

I believe @TamiTakamiya may be #1324 the MODEL_ID/SPACE_ID used for Playbook Generation/Explanation.

My change is specifically for fixing AAP-30690, i.e. not to send the granite-3b model_id to WCA Playbook Explanation/Generation APIs. It should not break this.

TamiTakamiya
TamiTakamiya previously approved these changes Sep 25, 2024
jameswnl
jameswnl previously approved these changes Sep 26, 2024
@manstis manstis dismissed stale reviews from jameswnl, TamiTakamiya, and goneri via 8905721 September 26, 2024 14:57
Copy link

Copy link
Contributor

@TamiTakamiya TamiTakamiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@manstis manstis merged commit 27cfad8 into main Sep 26, 2024
12 checks passed
@manstis manstis deleted the AAP-30426 branch September 26, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants