Skip to content

fix: move example scripts to right folders#164

Merged
abhijitjavelin merged 1 commit into
mainfrom
refactor_files
Mar 19, 2025
Merged

fix: move example scripts to right folders#164
abhijitjavelin merged 1 commit into
mainfrom
refactor_files

Conversation

@abhijitjavelin
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Hello @abhijitjavelin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on correcting the file paths for example scripts within the repository. The primary change involves moving the openai_client.py and openai_javelin_stream&non-stream.js files to their appropriate directories. This adjustment ensures that the example scripts are organized correctly, which improves the overall structure and maintainability of the project.

Highlights

  • File Path Correction: The example scripts are moved to their correct directories to maintain proper project structure.
  • JavaScript Client Update: The JavaScript example script is updated to use openai_client instead of openai.
  • Base URL Correction: The JavaScript example script's base URL is corrected from hhttps://api.javelin.live/v1/query to https://api.javelin.live/v1/query.

Changelog

  • examples/openai/openai_client.py
    • The entire file examples/openai/openai_client.py is new, containing various functions for interacting with OpenAI, Gemini, Azure OpenAI, DeepSeek, and Mistral models. It includes functionalities such as chat completions, embeddings, streaming chats, function calling, image understanding, structured output, and client registration with Javelin.
  • examples/openai/openai_javelin_stream&non-stream.js
    • The variable name openai is changed to openai_client to align with the intended usage.
    • The base URL is corrected from hhttps://api.javelin.live/v1/query to https://api.javelin.live/v1/query to ensure proper API endpoint resolution.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


In directories deep, where scripts reside,
A path astray, a coder's guide.
With careful move and steady hand,
Order restored, across the land.
Examples aligned, a clearer view,
For future coders, seeing it through.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request focuses on moving example scripts to the correct folders and updating the OpenAI client initialization in the JavaScript example. The changes in the Python script involve adding several functions to interact with different OpenAI models and registering them with the Javelin client. The JavaScript file updates the client initialization and fixes a typo in the base URL. Overall, the changes seem reasonable, but there are a few areas that could be improved.

Summary of Findings

  • Inconsistent client initialization: The Python script initializes the Javelin client globally and then re-initializes it within some functions. This could lead to confusion and potential issues if the configurations are different. Consider using the global client instance consistently.
  • Hardcoded API keys: The JavaScript example still contains placeholders for API keys. Ensure these are replaced with environment variables or a secure configuration mechanism before merging.
  • Missing error handling: The Python script lacks specific error handling for API calls. Adding try-except blocks with appropriate logging would improve the robustness of the examples.

Merge Readiness

The pull request is not quite ready for merging. The hardcoded API keys in the JavaScript example and the inconsistent client initialization in the Python script need to be addressed. Additionally, adding error handling to the Python script would improve its robustness. I am unable to approve this pull request, and recommend that the author address the issues raised before merging. It is also recommended that others review and approve this code before merging.


const openai = new OpenAI({
const openai_client = new OpenAI({
apiKey: "", // add your api key
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Ensure that the API key is not hardcoded and is instead loaded from an environment variable or a secure configuration. Leaving it blank poses a security risk.

Suggested change
apiKey: "", // add your api key
apiKey: process.env.OPENAI_API_KEY, // add your api key

Comment on lines +26 to +32
# Initialize Javelin Client
def initialize_javelin_client():
config = JavelinConfig(
base_url=javelin_base_url,
javelin_api_key=javelin_api_key,
)
return JavelinClient(config)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The Javelin client is initialized globally, and then re-initialized here. Consider using the global client instance to avoid confusion and potential conflicts in configuration.

Comment on lines +127 to +128
else:
raise Exception(f"Failed to download image: {response.status_code}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding more specific exception handling to provide more informative error messages. For example, you could catch requests.exceptions.RequestException to handle network errors.

    except requests.exceptions.RequestException as e:
        raise Exception(f"Failed to download image: {e}")

@abhijitjavelin abhijitjavelin merged commit d6c828f into main Mar 19, 2025
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