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

Opensource examples - Runpod w/Text-Generation-WebUI API Endpoint #247

Merged
merged 26 commits into from
Dec 5, 2023
Merged

Opensource examples - Runpod w/Text-Generation-WebUI API Endpoint #247

merged 26 commits into from
Dec 5, 2023

Conversation

PhiBrandon
Copy link
Contributor

@PhiBrandon PhiBrandon commented Dec 1, 2023

Adding Runpod example that utlizes a premade Ubuntu LLM Container on Runpod, allowing the ability to quickly create an endpoint for the variety of GPTQ models available via TheBloke[https://huggingface.co/TheBloke], with Openai compatible endpoint.

Example utilzes Openhermes 2.5 Mistral 7B - GPTQ model.
Removed Maybe BaseModel, response model = UserDetail.

Summary by CodeRabbit

  • Documentation

    • Updated instructions for setting up Openrouter API endpoint and Runpod account.
    • Added details on deploying a template with Runpod.
    • Clarified the addition of versioning to the Runpod API endpoint.
    • Specified that the default Runpod API key should be set to "None".
  • New Features

    • Introduced a new UserDetail class to enhance data handling within the application.

Copy link
Contributor

coderabbitai bot commented Dec 1, 2023

Walkthrough

The recent updates introduce integration with the Openrouter and Runpod APIs, enhancing the environment with new variables and endpoints. A notable addition is the UserDetail class in the runpod.py script, which aligns with the updated API interactions. These changes streamline the setup process and improve the interaction with external services, reflecting a shift towards more structured and API-centric development.

Changes

File Path Change Summary
.../open_source_examples/README.md Added Openrouter API endpoint and Runpod setup instructions; updated Runpod environment variables.
.../open_source_examples/runpod.py Imported new modules, added models variable, introduced UserDetail class, and modified interaction...
.../examples/open_source.md Introduced a new section for open source model providers supporting the OpenAI API chat endpoint.

🐇✨
In the burrows of the code, changes abound,
New paths are laid, and APIs found.
With a hop and a skip, the updates unfurl,
A digital meadow, where possibilities swirl. 🌼🌱


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d59ed26 and a2f05fc.
Files selected for processing (2)
  • examples/open_source_examples/README.md (1 hunks)
  • examples/open_source_examples/runpod.py (1 hunks)
Files not summarized due to errors (1)
  • examples/open_source_examples/runpod.py: Error: Disallowed special token found: <|im_start|>
Files not reviewed due to errors (1)
  • examples/open_source_examples/runpod.py (Error: Disallowed special token found: <|im_start|>)
Additional comments: 2
examples/open_source_examples/README.md (2)
  • 11-26: The summary mentions the addition of an Openrouter API endpoint, but the hunk shows the addition of a Perplexity API endpoint. Please verify the correct service and update the documentation accordingly.

  • 11-26: The instructions for setting up Perplexity and Runpod accounts are clear and detailed, providing users with step-by-step guidance.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a2f05fc and ed4d42f.
Files selected for processing (2)
  • examples/open_source_examples/README.md (1 hunks)
  • examples/open_source_examples/runpod.py (1 hunks)
Additional comments: 1
examples/open_source_examples/README.md (1)
  • 25-26: The instructions for setting up the Runpod environment are clear and detailed, including the addition of the Runpod API endpoint and key to the environment variables. Ensure that the placeholder your-runpod-link is replaced with the actual link provided by Runpod after deployment.

4. Add Openrouter API endpoint to environment - `export PERPLEXITY_BASE_URL=https://api.perplexity.ai` [See https://docs.perplexity.ai/reference/post_chat_completions for potential updates]
Copy link
Contributor

Choose a reason for hiding this comment

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

The environment variable PERPLEXITY_BASE_URL is incorrectly referred to as the Openrouter API endpoint in the instructions. This should be corrected to reflect the Perplexity API endpoint.

- 4. Add Openrouter API endpoint to environment - `export PERPLEXITY_BASE_URL=https://api.perplexity.ai`
+ 4. Add Perplexity API endpoint to environment - `export PERPLEXITY_BASE_URL=https://api.perplexity.ai`

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
4. Add Openrouter API endpoint to environment - `export PERPLEXITY_BASE_URL=https://api.perplexity.ai` [See https://docs.perplexity.ai/reference/post_chat_completions for potential updates]
4. Add Perplexity API endpoint to environment - `export PERPLEXITY_BASE_URL=https://api.perplexity.ai` [See https://docs.perplexity.ai/reference/post_chat_completions for potential updates]

Comment on lines 24 to 26
models = [
"TheBloke_OpenHermes-2.5-Mistral-7B-GPTQ",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

The models list is defined but not used in the code. If it's intended for future use, consider adding a comment to clarify its purpose, or remove it if it's not needed.

Copy link
Owner

@jxnl jxnl left a comment

Choose a reason for hiding this comment

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

Can you add some documentation in by adding a new markdown file called

opens_source.md in /docs?
and including it in mdkocs.yml?

@PhiBrandon PhiBrandon requested a review from jxnl December 4, 2023 18:17
Copy link
Owner

@jxnl jxnl left a comment

Choose a reason for hiding this comment

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

is this good to merge? can you make sure to run ruff format . and then let me know when you're happy to merge

@PhiBrandon
Copy link
Contributor Author

is this good to merge? can you make sure to run ruff format . and then let me know when you're happy to merge

it's good to go!

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b5626f6 and c1ab8a3.
Files selected for processing (2)
  • examples/open_source_examples/openrouter.py (1 hunks)
  • examples/open_source_examples/runpod.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • examples/open_source_examples/openrouter.py

Comment on lines +9 to +10
runpod_api_key = os.environ.get("RUNPOD_API_KEY")
assert runpod_api_key, "RUNPOD_API_KEY is not set in environment variables"
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of assert for checking environment variables can cause the application to crash if the variables are not set. Consider handling this with proper error messages and exit the application gracefully.

- assert runpod_api_key, "RUNPOD_API_KEY is not set in environment variables"
+ if not runpod_api_key:
+     raise ValueError("RUNPOD_API_KEY is not set in environment variables")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
runpod_api_key = os.environ.get("RUNPOD_API_KEY")
assert runpod_api_key, "RUNPOD_API_KEY is not set in environment variables"
runpod_api_key = os.environ.get("RUNPOD_API_KEY")
if not runpod_api_key:
raise ValueError("RUNPOD_API_KEY is not set in environment variables")

Comment on lines +13 to +14
runpod_base_url = os.environ.get("RUNPOD_BASE_URL")
assert runpod_base_url, "RUNPOD_BASE_URL is not set in environment variables"
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar issue as above with RUNPOD_BASE_URL. Replace the assert with a more graceful error handling mechanism.

- assert runpod_base_url, "RUNPOD_BASE_URL is not set in environment variables"
+ if not runpod_base_url:
+     raise ValueError("RUNPOD_BASE_URL is not set in environment variables")

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
runpod_base_url = os.environ.get("RUNPOD_BASE_URL")
assert runpod_base_url, "RUNPOD_BASE_URL is not set in environment variables"
runpod_base_url = os.environ.get("RUNPOD_BASE_URL")
if not runpod_base_url:
raise ValueError("RUNPOD_BASE_URL is not set in environment variables")

Comment on lines +36 to +41
class UserDetail(BaseModel):
name: str = Field(description="Name extracted from the text")
age: int = Field(description="Age extracted from the text")
occupation: Optional[str] = Field(
default=None, description="Occupation extracted from the text"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The UserDetail class is defined within the if __name__ == "__main__": block, which limits its scope. If this class is intended for use outside of this script, consider moving it to the module level.

try:
user = client.chat.completions.create(
response_model=UserDetail,
model="TheBloke_OpenHermes-2.5-Mistral-7B-GPTQ",
Copy link
Contributor

Choose a reason for hiding this comment

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

The model name is hardcoded in the client.chat.completions.create call. Consider using the models list or an environment variable to make it configurable.

- model="TheBloke_OpenHermes-2.5-Mistral-7B-GPTQ",
+ model=models[0],  # Assuming models list is intended to be used here

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
model="TheBloke_OpenHermes-2.5-Mistral-7B-GPTQ",
model=models[0], # Assuming models list is intended to be used here

Comment on lines +60 to +61
except Exception as e:
print(f"Error: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

The error handling in the loop is basic and only prints the error message. Consider implementing a more robust error handling strategy, such as logging the errors to a file or an error tracking system.

@jxnl jxnl merged commit cb96010 into jxnl:main Dec 5, 2023
4 checks passed
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.

2 participants