-
Notifications
You must be signed in to change notification settings - Fork 2k
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 node to use OpenAI's GPT-3 for QA #2605
Conversation
Hey @tholor this would be super-cool to have in master! Shall we take over or you think you'll be able to keep working in this? I'll merge master in here in the meantime to get the new CI working here too. |
@ZanSara Would be amazing if you could take over! |
# Conflicts: # haystack/json-schemas/haystack-pipeline-master.schema.json
As the |
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.
Looks very good to me already. 👍 I would recommend two small changes in docstrings: 1) explicitly mention that an API key is needed and explain how to get one and 2) small typo (see my comment below).
|
||
def _build_prompt(self, query: str, documents: List[Document]) -> Tuple[str, List[Document]]: | ||
""" | ||
Builds the prompt for the GPT-3 model in order for ir to generate an answer. |
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.
typo "ir" -> "it"
|
||
class OpenAIAnswerGenerator(BaseGenerator): | ||
""" | ||
Uses the GPT-3 models from the OpenAI API to generate answers based on supplied documents (e.g. from any retriever in Haystack). |
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.
The docstring should mention that there is an API key needed and should also link to a web page with a description how to get an API key.
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.
Added this to the doc strings.
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.
LGTM! 👍
* first draft of openai node for QA * Update Documentation & Code Style * fix mypy. add node to inits * Update Documentation & Code Style * fix linter * Adapt OpenAIGenerator to completions endpoint * Update Documentation & Code Style * Fix pylint * Fix doc strings * Make use of temperature * Make use of api key in tests * Adapt doc strings Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ZanSara <[email protected]> Co-authored-by: bogdankostic <[email protected]>
Proposed changes:
Integrating OpenAI's GPT-3 model via their API.
The node can take documents as input and generates
top_k
answers by calling the remote API from OpenAI.Users will need to signup at OpenAI and supply their
api_key
to the node.Example:
Limitations:
OpenAI's API doesn't return scores for the answers
Open tasks:
predict_batch()
(implemented inBaseGenerator
)Status (please check what you already did):
closes: #2344