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

Use system messages to shape the model output #38

Merged
merged 22 commits into from
May 11, 2023
Merged

Conversation

ferrislucas
Copy link
Owner

@ferrislucas ferrislucas commented May 4, 2023

This PR modifies the way the prompt is sent to the OpenAI API. The "system" role is now used for messages related to model response formatting.

The bulk of this PR was implemented using Promptr. Take a look at the following commits to get a sense of what's possible. The commit messages include the prompt that was used to apply the changes:

Prompt:
Modify the Gpt4Service class.
Add a new static method called systemMessages to Gpt4Service.
The systemMessages method should return [{role: "system", content: "system" }]

Modify the Gpt4Service.call method so that it appends the messages returned by Gpt4Service.systemMessages() in the call to openai.createChatCompletion
Add tests for the changes to the Gpt4Service.call method in test/gpt4Service.test.js.
Prompt:
Modify the Gpt4Service class.
Add a second argument to Gpt4Service.call called "model".
In Gpt4Service.call, pass the model argument to openai.createChatCompletion in place of the hardcoded string "gpt-4".
Add tests for your changes in test/gpt4Service.test.js
Prompt:
Modify the PluginService class.
In the PluginService.executeMode() method, call Gpt4Service.call(prompt, model) if model equals "gpt4" or "gpt3" - don't use Gpt3Service.
Add tests for your changes in test/pluginService.test.js
…API model param values

Prompt:
Modify the OpenAiGptService class.
In the call() method, if model == "gpt3" then set model to "gpt-3.5-turbo"
In the call() method, if model == "gpt4" then set model to "gpt-4"
Add tests for your changes in test/OpenAiGptService.test.js
Use sinon to assert that openai.createChatCompletion receives the correct model value
Prompt:
Make the following changes to the OpenAiGptService.call() method:
Add an argument called requestJsonOutput.
The requestJsonOutput argument should have a default value of true.
If requestJsonOutput is false then don't pass SystemMessage.systemMessages() into the call to openai.createChatCompletion
Add tests for your changes in test/OpenAiGptService.test.js
@ferrislucas ferrislucas merged commit 36a5383 into main May 11, 2023
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.

1 participant