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

Add react hook to openai module #94

Merged
merged 10 commits into from
Oct 27, 2023
Merged

Add react hook to openai module #94

merged 10 commits into from
Oct 27, 2023

Conversation

SandersAaronD
Copy link
Contributor

This won't build, I think because of the react version, leaving it in a draft PR in case anyone else wants to repro or work on it.

Copy link
Contributor

@sd2k sd2k left a comment

Choose a reason for hiding this comment

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

The CI failure is just because v10.2.0 of @grafana/runtime requires Node >= 18. I'd suggest just downgrading back to v10.0.0 and commenting the logError line for now though, until we decide to upgrade all the @grafana packages to v10.2. Otherwise I think this should work!

src/llms/openai.ts Show resolved Hide resolved
src/llms/openai.ts Outdated Show resolved Hide resolved
@SandersAaronD SandersAaronD marked this pull request as ready for review October 25, 2023 15:19
@SandersAaronD
Copy link
Contributor Author

Thanks for your help @sd2k, I think this is ready to merge in. It will need to be tested as an import after next experimental release.

@sd2k
Copy link
Contributor

sd2k commented Oct 25, 2023

Could you revert the changes to package.json/yarn.lock? Just since they're not really relevant to this PR.

@SandersAaronD
Copy link
Contributor Author

Could you revert the changes to package.json/yarn.lock? Just since they're not really relevant to this PR.

This is done and it should be fine now

Comment on lines +420 to +435
/**
* A custom React hook for managing an OpenAI stream that communicates with the provided model.
*
* @param {string} [model=DEFAULT_OAI_MODEL] - The OpenAI model to use for communication.
* @param {number} [temperature=1] - The temperature value for text generation (default is 1).
* @param {function} [notifyError] - A callback function for handling errors.
*
* @returns {OpenAIStreamState} - An object containing the state of the OpenAI stream.
* @property {function} setMessages - A function to update the list of messages in the stream.
* @property {string} reply - The most recent reply received from the OpenAI stream.
* @property {StreamStatus} streamStatus - The status of the stream ("idle", "generating" or "completed").
* @property {Error|undefined} error - An error object if an error occurs, or undefined if no error.
* @property {object|undefined} value - The current value of the stream.
* @property {boolean|undefined} value.enabled - Indicates whether the stream is enabled (true or false).
* @property {Subscription|undefined} value.stream - The stream subscription object if the stream is active, or undefined if not.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how easy this will be but could you add a super minimal example to the JSDoc? It can be similar to the examples in the other exposed functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is feasible because there is so much handling to do, but once we have a working example elsewhere perhaps we can link it?

src/llms/openai.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@codeincarnate codeincarnate left a comment

Choose a reason for hiding this comment

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

Really clean code and a pleasure to review. LGTM!

@codeincarnate codeincarnate merged commit e31d556 into main Oct 27, 2023
2 checks passed
@edwardcqian edwardcqian deleted the add-openai-hook branch October 27, 2023 18:03
sd2k added a commit that referenced this pull request Dec 14, 2023
This was missing from #94 and causes local builds to break.
SandersAaronD pushed a commit that referenced this pull request Jan 10, 2024
Add react hook to openai module
SandersAaronD pushed a commit that referenced this pull request Jan 10, 2024
This was missing from #94 and causes local builds to break.
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.

3 participants