Skip to content

Support Anura API #3

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

Merged
merged 23 commits into from
Mar 2, 2025
Merged

Support Anura API #3

merged 23 commits into from
Mar 2, 2025

Conversation

DevlinRocha
Copy link
Owner

@DevlinRocha DevlinRocha commented Mar 2, 2025

Summary

  • Chores

    • Updated the package version to v0.0.38.
  • Documentation

    • Revised module instructions with a structured JSON request format and updated parameter descriptions.
    • Updated help text to reflect new terminology.
  • New Features

    • Enhanced user interaction by prompting for essential configuration during module execution.
    • Added support for a shorthand flag to simplify local builds.
    • Introduced a new parameter, "stop," for specifying stop sequences in requests.
  • Refactor

    • Streamlined the request processing for a simpler and more robust experience, including changes to input handling and error management.

Summary by CodeRabbit

  • Chores
    • Incremented the package version.
    • Enhanced the build process with additional flag support and adjusted version update timing.
  • Documentation
    • Updated instructions and usage examples for running the module.
    • Refined parameter descriptions by replacing "input" with "request" and introducing a new stop parameter.
  • New Features
    • Streamlined command input handling with a structured JSON format.
    • Improved user interaction through simplified request processing and clearer output messages.

@DevlinRocha DevlinRocha added the enhancement New feature or request label Mar 2, 2025
@DevlinRocha DevlinRocha self-assigned this Mar 2, 2025
Copy link

coderabbitai bot commented Mar 2, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes include a version bump in the package, updates to Docker configuration comments and parameters, revised documentation with updated terminology and a new parameter, and significant modifications to several scripts. The build and run scripts now feature enhanced argument handling and JSON request processing, while the run_model script has been simplified for input decoding.

Changes

Files Change Summary
package.json Version updated from "0.0.32" to "0.0.38".
src/.../Dockerfile
src/.../lilypad_module.json.tmpl
Docker configuration updated: Dockerfile comment changed; JSON template removes "WorkingDirectory", updates "Entrypoint" from {{ .input }} to {{ .request }}, and changes the image reference from a versioned tag to a tagless format.
src/.../README.md
src/.../help
Documentation revised: terminology changed from "input" to "request"; the README now presents a structured JSON example with a new stop parameter and updated header; help text updated accordingly.
src/.../scripts/build
src/.../scripts/run
src/.../src/run_model
Script modifications: build script extends local flag checking (--local and -l) and repositions version updating; run script now sources the .env, prompts for a wallet key if absent, and constructs a JSON request; run_model simplifies Base64 decoding and removes detailed parameter extraction.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RunScript as "scripts/run"
    participant Env as ".env File"
    participant RequestFunc as "Request Handler"
    participant RunModel as "run_model Script"
    
    User->>RunScript: Execute command
    RunScript->>Env: Check if .env exists
    alt .env is present
        Env-->>RunScript: Load configuration
    else .env missing
        RunScript->>User: Prompt for wallet private key
        User-->>RunScript: Provide key
    end
    RunScript->>RequestFunc: Construct structured JSON request
    RequestFunc-->>RunScript: Return JSON request
    RunScript->>RunScript: Base64-encode the request
    RunScript->>RunModel: Pass encoded request
    RunModel->>RunModel: Decode Base64 into JSON
    RunModel-->>RunScript: Process request and return output
    RunScript->>User: Display result
Loading

Poem

In code I hop with joy so grand,
Each update a treat as I nibble and stand.
From version bumps to JSON so bright,
Docker whispers and scripts take flight.
I’m a coding rabbit, quick and keen—
Leaping through changes in fields unseen!
🐰💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DevlinRocha
Copy link
Owner Author

@CodeRabbit review

@DevlinRocha
Copy link
Owner Author

@CodeRabbit summary

Copy link

coderabbitai bot commented Mar 2, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Mar 2, 2025

✅ Actions performed

Summary regeneration triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (2)
src/create_lilypad_module/templates/src/run_model (1)

8-8: Add basic error handling for request decoding

The script doesn't verify if the base64 decoding was successful or if the request contains the required structure. This could lead to cryptic errors when the API call is made.

Consider adding basic validation:

echo "Raw request (Base64): $1" >&2
request=$(echo "$1" | base64 -d)
+if [ $? -ne 0 ]; then
+  echo "Error: Failed to decode base64 request" >&2
+  exit 1
+fi
+
+# Verify request is valid JSON
+if ! echo "$request" | jq . >/dev/null 2>&1; then
+  echo "Error: Request is not valid JSON" >&2
+  exit 1
+fi
src/create_lilypad_module/templates/README.md (1)

57-57: Added 'stop' parameter with missing comma.

The new 'stop' parameter is a valuable addition, but there's a minor typographical error in the description.

- When this pattern is encountered the LLM will stop generating text and return.
+ When this pattern is encountered, the LLM will stop generating text and return.
🧰 Tools
🪛 LanguageTool

[typographical] ~57-~57: It seems that a comma is missing.
Context: ... sequences to use. When this pattern is encountered the LLM will stop generating text and r...

(IF_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df42378 and 1bb38c5.

📒 Files selected for processing (8)
  • package.json (1 hunks)
  • src/create_lilypad_module/templates/Dockerfile (1 hunks)
  • src/create_lilypad_module/templates/README.md (4 hunks)
  • src/create_lilypad_module/templates/help (1 hunks)
  • src/create_lilypad_module/templates/lilypad_module.json.tmpl (1 hunks)
  • src/create_lilypad_module/templates/scripts/build (2 hunks)
  • src/create_lilypad_module/templates/scripts/run (1 hunks)
  • src/create_lilypad_module/templates/src/run_model (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • package.json
  • src/create_lilypad_module/templates/Dockerfile
🧰 Additional context used
🪛 LanguageTool
src/create_lilypad_module/templates/README.md

[typographical] ~57-~57: It seems that a comma is missing.
Context: ... sequences to use. When this pattern is encountered the LLM will stop generating text and r...

(IF_COMMA)

🔇 Additional comments (14)
src/create_lilypad_module/templates/src/run_model (2)

6-8: Simplification improves code maintainability

The code has been greatly simplified by directly decoding the base64 request without extracting individual parameters. This is more maintainable and allows for flexible request parameters.


58-58: Terminology updated for consistency

Updated debug output to use "Request (Base64)" instead of "Input (Base64)", maintaining consistency with the terminology changes throughout the codebase.

src/create_lilypad_module/templates/README.md (5)

20-40: Improved request structure with JSON format.

The updated example provides a much clearer structure using JSON to specify the model, messages, streaming options, and parameters. This format is more consistent with modern API practices and provides better guidance for users.


43-45: Enhanced parameters header for clarity.

The header change to "Valid Options Parameters and Default Values" better reflects that these parameters belong to the "options" field in the JSON request structure.


58-58: Added 'num_predict' parameter for token generation control.

The 'num_predict' parameter provides important functionality for controlling the maximum number of tokens to predict when generating text.


69-71: Improved script description clarity.

The updated description provides better clarity about what the script does and adds information about the .env file location.


86-86: Clearer version flag description.

The revised wording provides a clearer explanation of what the version flags do.

src/create_lilypad_module/templates/scripts/run (3)

3-5: Improved configuration loading.

Added proper configuration file sourcing to load environment variables from the .env file.


6-29: Added interactive request function.

The new request function provides an excellent user experience by:

  1. Prompting for wallet credentials if needed
  2. Providing a JSON template for the user to customize
  3. Combining user input with model information from the environment

This makes the module much more user-friendly.


31-37: Updated usage and improved argument handling.

The script now handles both interactive mode (no arguments) and command-line arguments more elegantly. The usage message has been updated to reflect the new request format.

src/create_lilypad_module/templates/help (1)

12-12: Consistent terminology update: input to request.

The change from <input> to <request> aligns with the broader terminology shift across the codebase, making the help text more consistent with other files.

src/create_lilypad_module/templates/scripts/build (2)

16-16: Good UX improvement: added shorthand option.

Adding -l as a shorthand for --local improves user experience by offering a more concise command-line option.


93-93: Version update logic improvement.

Moving the version update to occur after successful Docker image publishing is a good practice. This ensures the version is only updated when the operation completes successfully.

src/create_lilypad_module/templates/lilypad_module.json.tmpl (1)

9-9: Consistent terminology update: input to request.

Changing {{ .input }} to {{ .request }} aligns with the terminology updates across the codebase.

@DevlinRocha
Copy link
Owner Author

@CodeRabbit review

Copy link

coderabbitai bot commented Mar 2, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🔭 Outside diff range comments (1)
src/create_lilypad_module/templates/scripts/run (1)

1-69: 🛠️ Refactor suggestion

Check environment variables at the beginning of the script.

The script uses several environment variables (MODEL_NAME, MODEL_VERSION, GITHUB_REPO, DOCKER_IMAGE, VERSION) but doesn't verify they exist before using them. Add checks at the beginning to fail early with clear error messages.

#!/usr/bin/env bash

CONFIG_FILE=".env"
source $CONFIG_FILE

+# Check required environment variables
+required_vars=("MODEL_NAME" "MODEL_VERSION")
+missing_vars=()
+
+for var in "${required_vars[@]}"; do
+  if [ -z "${!var}" ]; then
+    missing_vars+=("$var")
+  fi
+done
+
+if [ ${#missing_vars[@]} -ne 0 ]; then
+  echo "Error: The following required environment variables are missing:"
+  for var in "${missing_vars[@]}"; do
+    echo "  - $var"
+  done
+  echo "Please set them in your $CONFIG_FILE file."
+  exit 1
+fi
+
function request {
    # Function implementation...
🧹 Nitpick comments (1)
src/create_lilypad_module/templates/scripts/run (1)

3-4: Add error handling for config file loading.

The script sources the .env file without checking if it exists, which could cause confusing errors if the file is missing.

CONFIG_FILE=".env"
+if [ ! -f "$CONFIG_FILE" ]; then
+  echo "Error: Config file $CONFIG_FILE not found."
+  exit 1
+fi
source $CONFIG_FILE
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bb38c5 and 961a3d7.

📒 Files selected for processing (1)
  • src/create_lilypad_module/templates/scripts/run (1 hunks)

@DevlinRocha
Copy link
Owner Author

@CodeRabbit review

Copy link

coderabbitai bot commented Mar 2, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/create_lilypad_module/templates/scripts/run (1)

6-31: ⚠️ Potential issue

Improve security and robustness in the request function.

The function has several issues:

  1. The private key is read in plain text (security risk)
  2. No validation of MODEL_NAME and MODEL_VERSION
  3. JSON construction doesn't properly handle escaping
  4. No validation of user input JSON format
function request {
+    local request_json
    if ! printenv | grep -q "WEB3_PRIVATE_KEY=."; then
        printf "Enter your wallet private key: "
-        read -r private_key
+        read -rs private_key
+        echo # Add newline after hidden input
        WEB3_PRIVATE_KEY=$private_key
        echo "Private key set"
        echo "(Hint: Use 'export WEB3_PRIVATE_KEY=<PRIVATE_KEY>' to avoid this prompt in the future)"
    fi

+    # Validate required environment variables
+    if [ -z "$MODEL_NAME" ] || [ -z "$MODEL_VERSION" ]; then
+        echo "Error: MODEL_NAME and MODEL_VERSION must be set in $CONFIG_FILE"
+        exit 1
+    fi

    echo "Copy the JSON below to form your request:"
    echo '
  "messages": [{
    "role": "system",
    "content": "you are a helpful AI assistant"
  },
  {
    "role": "user",
    "content": "what is the animal order of the frog?"
  }],
  "options": {
    "temperature": 1.0
  }
'
    printf "(Paste JSON as one line) ➔ "
    read -r request
+    # Basic JSON validation
+    if [[ ! "$request" =~ \"messages\" ]]; then
+        echo "Error: Invalid JSON format. Request must include 'messages' field."
+        return 1
+    fi
    request="{\"model\": \"$MODEL_NAME:$MODEL_VERSION\", $request, \"stream\": false}"
}
🧹 Nitpick comments (3)
src/create_lilypad_module/templates/scripts/run (3)

3-5: Add error handling when sourcing the config file.

The script sources the config file without checking if it exists or can be read. Also, the CONFIG_FILE variable should be quoted when used to handle paths with spaces.

-CONFIG_FILE=".env"
-source $CONFIG_FILE
+CONFIG_FILE=".env"
+if [ -f "$CONFIG_FILE" ]; then
+  source "$CONFIG_FILE"
+else
+  echo "Warning: Config file $CONFIG_FILE not found. Using default values."
+fi

33-57: Improve argument handling for clarity and robustness.

The current implementation might have unexpected behavior with multiple non-flag arguments. Additionally, it doesn't validate the request argument when provided directly.

if [ $# -gt 2 ]; then
-    echo "Usage: scripts/run [--local] <request>"
+    echo "Usage: scripts/run [--local] [<JSON request>]"
    echo "Example: scripts/run 'What animal order do frogs belong to?'"
    exit 1
elif [ $# -eq 0 ]; then
    request
else
+    local has_request=false
    while [[ $# -gt 0 ]]; do
        case $1 in
        --local | -l)
            echo "Running the Lilypad module Docker image locally..."
            local=true
            shift
            ;;
        *)
+            if [ "$has_request" = true ]; then
+                echo "Warning: Multiple request arguments provided. Using the last one."
+            fi
            request=$1
+            has_request=true
            shift
            ;;
        esac
    done

    if [[ -z $request ]]; then
        request
    fi
fi

1-77: Enhance overall script security and error handling.

The script has several security and robustness issues:

  1. The private key handling should be made more secure
  2. Proper error checking for commands like git and docker is missing
  3. The script doesn't validate JSON input thoroughly
  4. There's inconsistent quoting of variables throughout

Consider adding comprehensive error checking, proper private key handling (using a temporary file with restricted permissions or a credential manager), and thorough input validation to make the script more robust and secure.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 961a3d7 and 2d01db2.

📒 Files selected for processing (1)
  • src/create_lilypad_module/templates/scripts/run (1 hunks)
🔇 Additional comments (2)
src/create_lilypad_module/templates/scripts/run (2)

59-60: Add quotes around variables in the base64 encoding.

Missing quotes around the $request variable can cause issues if the request contains spaces or special characters.

# Base64 encode the request
-base64_request=$(echo $request | base64 -w 0)
+base64_request=$(echo "$request" | base64 -w 0)

71-75: Add quotes around variables in the local execution path.

The script uses variables without quotes which could cause issues with spaces or special characters.

-    MODULE=$DOCKER_IMAGE:$VERSION
+    MODULE="$DOCKER_IMAGE:$VERSION"
    echo "Running $MODULE locally..."
-    echo "Original request: $request"
-    echo "Base64 encoded: $base64_request"
+    echo "Original request: $request"
+    echo "Base64 encoded: $base64_request"
-    docker run $MODULE $base64_request
+    docker run "$MODULE" "$base64_request"

@DevlinRocha DevlinRocha merged commit 0889f5c into ollama Mar 2, 2025
1 of 2 checks passed
@DevlinRocha DevlinRocha deleted the feat/api branch March 2, 2025 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant