Add Grok bot integration for Jupyter notebooks - #666
Open
hakan263774-web wants to merge 1 commit into
Open
Conversation
Adds grok_bot package with GrokClient and IPython magic. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements a complete Grok bot integration for the Codespaces Jupyter environment, enabling users to leverage XAI's Grok conversational AI model directly within notebooks.
Implementation Details
Package Structure
api.py:GrokClientclass for API communication with configurable endpoints and authmagic.py: IPython magic commands (%grokand%%grok) for notebook integration__init__.py: Safe imports that gracefully handle missing IPython in non-notebook contextsFeatures
IPython Magic Commands:
%grok <prompt>for single-line queries%%grokfor multi-line cell promptsAuthentication & Configuration:
GROK_API_KEYfrom environment (Codespaces secret or shell)GROK_API_URLfor alternative endpointsError Handling:
Files Changed
grok_bot/: New package (3 modules)requirements.txt: Addedrequests>=2.30.0GROK_INTEGRATION.md: Comprehensive usage and auth documentation.devcontainer/devcontainer.json: AddedcontainerEnvmapping for GROK_API_KEYREADME.md: Added Grok bot quick-start sectionnotebooks/grok-example.ipynb: Example notebook demonstrating all featurestest_grok_bot.py: 11 comprehensive unit tests (all passing)Testing
All tests pass:
Tests cover:
Usage Example
Security Notes
devcontainer.jsonuses${localEnv:GROK_API_KEY}to forward local secretsVerification
✅ All 11 unit tests passing
✅ Package imports work correctly
✅ GrokClient initializes and validates configuration
✅ IPython extension loads without errors
✅ Example notebook provided with comprehensive examples
✅ Documentation complete and clear
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com