-
Notifications
You must be signed in to change notification settings - Fork 406
Feat/add gemini #349
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
Feat/add gemini #349
Conversation
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
- fixed tsconfig so linter works properly, no more red squigglies!
- Added Google Gemini - Updated AiEngine to import AI provider classes instead of importing instances so that the app doesn't attempt to instantiate every AI provider class - Small refactoring to clean up typescript linting errors in generateCommitMessageFromGitdiff.ts
- adding unit tests for gemini support - small tweaks to jest config
This commit adds tests for the gemini model, including: - initialization with correct config - generating commit message - warming up correctly - handling missing API key - handling unsupported model These tests ensure that the gemini model is working as expected and that it is properly integrated with the rest of the code.
…ngine This commit adds support for the Gemini AI engine. It includes the following changes: - Added Gemini to the list of supported providers in the `config.ts` file. - Added a default model for Gemini in the `getDefaultModel` function. - Updated the `Gemini` class to use the correct model name and to handle the different message roles. - Added a check to ensure that the specified model is valid for Gemini.
* 3.0.12 * build * feat: anthropic claude 3 support * fix: add system prompt * fix: type check * fix: package version * fix: update anthropic for dependency bug fix * feat: update build files * feat: update version number --------- Co-authored-by: di-sukharev <dim.sukharev@gmail.com>
… for commands/config.ts#getConfig (di-sukharev#330) * feat(jest.config.ts): update jest preset for TS ESM support and ignore patterns feat(package.json): add test:unit script with NODE_OPTIONS for ESM refactor(src/commands/config.ts): improve dotenv usage with dynamic paths feat(src/commands/config.ts): allow custom config and env paths in getConfig refactor(src/commands/config.ts): streamline environment variable access feat(test/unit): add unit tests for config handling and utility functions - Implement unit tests for `getConfig` function to ensure correct behavior in various scenarios including default values, global config, and local env file precedence. - Add utility function `prepareFile` for creating temporary files during tests, facilitating testing of file-based configurations. * feat(e2e.yml): add unit-test job to GitHub Actions for running unit tests on pull requests * ci(test.yml): add GitHub Actions workflow for unit and e2e tests on pull requests * refactor(config.ts): streamline environment variable access using process.env directly test(config.test.ts): add setup and teardown for environment variables in tests to ensure test isolation * feat(package.json): add `test:all` script to run all tests in Docker refactor(package.json): consolidate Docker build steps into `test:docker-build` script for DRY principle fix(package.json): ensure `test:unit:docker` and `test:e2e:docker` scripts use the same Docker image and remove container after run chore(test/Dockerfile): remove default CMD to allow dynamic test script execution in Docker * refactor(config.test.ts): anonymize API keys in tests for better security practices * feat(config.test.ts): add tests for OCO_ANTHROPIC_API_KEY configuration * refactor(config.ts): streamline path imports and remove unused DotenvParseOutput - Simplify path module imports by removing default import and using named imports for `pathJoin` and `pathResolve`. - Remove unused `DotenvParseOutput` import to clean up the code. * refactor(config.test.ts): simplify API key mock values for clarity in tests * test(config.test.ts): remove tests for default config values and redundant cases - Removed tests that checked for default config values when no config or env files are present, as these scenarios are now handled differently. - Eliminated tests for empty global config and local env files to streamline testing focus on actual config loading logic. - Removed test for prioritizing local env over global config due to changes in config loading strategy, simplifying the configuration management.
* 🐛 (config.ts, engine/ollama.ts, utils/engine.ts): improve Ollama AI configuration and usage ✨ (config.ts): add support for multiple Ollama models and allow users to specify the model in their config ✅ (engine/ollama.ts, utils/engine.ts): refactor code to use the specified Ollama model instead of hardcoding it * add build results
* ✨ feat(api.ts): add support for Azure OpenAI API The Azure OpenAI API is now supported in addition to the OpenAI API. The API type can be specified in the configuration file using the OPENAI_API_TYPE key. If the key is not specified, the default value is 'openai'. The AzureOpenAIApi class is added to the utils folder to handle the Azure OpenAI API calls. The createChatCompletion method is implemented in the AzureOpenAIApi class to handle the chat completion requests. The method is called in the generateCommitMessage method in the OpenAi class if the apiType is set to 'azure'. * 🐛 fix(AzureOpenAI.ts): fix import path for AxiosRequestConfig to avoid conflicts with openai's axios dependency In AzureOpenAI.ts, the import path for AxiosRequestConfig was changed to avoid conflicts with openai's axios dependency, which was causing lint errors. * 🔧 fix(AzureOpenAI.ts): import RequiredError to fix error handling and remove commented out debug code The RequiredError class was not being imported from the openai/dist/base module, causing errors to be thrown incorrectly. This has been fixed by importing the RequiredError class. Debug code has been removed and comments have been updated to reflect the changes made. * 🔇 chore(AzureOpenAI.ts): remove console.log statement and translate Japanese comment The commented console.log statement was removed to improve code cleanliness. * 🔥 refactoring(api.ts, AzureOpenAI.ts): Leverage openai npm package 🐛 fix(config.ts): API Key string validation * ✨ (README.md): update opencommit command to set OCO_AI_PROVIDER instead of OPENAI_API_TYPE to improve consistency and clarity in configuration ♻️ (config.ts): update OCO_AI_PROVIDER enum in configValidators to include 'azure' and remove unnecessary conditionals to improve maintainability and extensibility ⬆️ (config.ts): add OCO_AZURE_API_VERSION to ConfigType and getConfig() to support new azure api version configuration ♻️ (engine/ollama.ts): add space between temperature and top_p properties to improve readability ♻️ (engine/openAi.ts): refactor OpenAi class to improve readability and maintainability by extracting configuration logic into separate switch statement 🔧 (generateCommitMessageFromGitDiff.ts): refactor MAX_TOKENS_INPUT and MAX_TOKENS_OUTPUT lines to improve readability 🔧 (generateCommitMessageFromGitDiff.ts): refactor generateCommitMessageByDiff and getMessagesPromisesByChangesInFile functions to use destructuring and improve readability ♻️ (generateCommitMessageFromGitDiff.ts): refactor getCommitMsgsPromisesFromFileDiffs function to use destructuring and improve readability 📝 (modules/commitlint/config.ts): add missing types to function parameters and improve readability by removing unnecessary comments and whitespace 📝 (modules/commitlint/utils.ts): fix indentation and add missing types to function parameters 📝 (prompts.ts): update INIT_MAIN_PROMPT description to include clarification on the use of present tense and line length 📝 (version.ts): fix import statements and add missing types to function parameters * ✨ (package.json): add @azure/openai dependency to support integration with Azure AI services 🔧 (config.ts): change CONFIG_KEYS.OCO_AZURE_API_VERSION to CONFIG_KEYS.OCO_AZURE_ENDPOINT to improve semantics and allow configuration of Azure endpoint URL ♻️ (config.ts): refactor configValidators to use OCO_AZURE_ENDPOINT instead of OCO_AZURE_API_VERSION and update validation message for OCO_AZURE_ENDPOINT ✨ (config.ts): add OCO_AZURE_ENDPOINT to getConfig function to retrieve Azure endpoint configuration from environment variables ✨ (azure.ts): introduce a new file azure.ts to implement Azure AI engine ✨ (azure.ts): implement generateCommitMessage function in Azure AI engine ✨ (prompts.ts): add a new line to INIT_MAIN_PROMPT to mention that changes within a single file should be described with a single commit message ♻️ (engine.ts): refactor getEngine function to add support for 'azure' as the AI provider and return the azure engine * 📝 (prompts.ts): remove unnecessary information about crafting a concise commit message with a one single message for OCO_ONE_LINE_COMMIT configuration * 3.0.14 (di-sukharev#333) * test: ✅ add the first E2E test and configuration to CI (di-sukharev#316) * add tests * Add push config (di-sukharev#220) * feat: add instructions and support for configuring gpt-4-turbo (di-sukharev#320) * 3.0.12 * build * feat: add 'gpt-4-turbo' to supported models in README and config validation --------- Co-authored-by: di-sukharev <dim.sukharev@gmail.com> * ✅ fix the broken E2E tests due to the addition of OCO_GITPUSH (di-sukharev#321) * test(oneFile.test.ts): update test expectations to match new push prompt text * build * Feat: Add Claude 3 support (di-sukharev#318) * 3.0.12 * build * feat: anthropic claude 3 support * fix: add system prompt * fix: type check * fix: package version * fix: update anthropic for dependency bug fix * feat: update build files * feat: update version number --------- Co-authored-by: di-sukharev <dim.sukharev@gmail.com> * 🐛bug fix: enable to use the new format of OpenAI's project API Key (di-sukharev#328) * fix(config.ts): remove validation for OCO_OPENAI_API_KEY length to accommodate variable key lengths * build * ♻️ refactor(config.ts): Addition of UnitTest environment and unittest for commands/config.ts#getConfig (di-sukharev#330) * feat(jest.config.ts): update jest preset for TS ESM support and ignore patterns feat(package.json): add test:unit script with NODE_OPTIONS for ESM refactor(src/commands/config.ts): improve dotenv usage with dynamic paths feat(src/commands/config.ts): allow custom config and env paths in getConfig refactor(src/commands/config.ts): streamline environment variable access feat(test/unit): add unit tests for config handling and utility functions - Implement unit tests for `getConfig` function to ensure correct behavior in various scenarios including default values, global config, and local env file precedence. - Add utility function `prepareFile` for creating temporary files during tests, facilitating testing of file-based configurations. * feat(e2e.yml): add unit-test job to GitHub Actions for running unit tests on pull requests * ci(test.yml): add GitHub Actions workflow for unit and e2e tests on pull requests * refactor(config.ts): streamline environment variable access using process.env directly test(config.test.ts): add setup and teardown for environment variables in tests to ensure test isolation * feat(package.json): add `test:all` script to run all tests in Docker refactor(package.json): consolidate Docker build steps into `test:docker-build` script for DRY principle fix(package.json): ensure `test:unit:docker` and `test:e2e:docker` scripts use the same Docker image and remove container after run chore(test/Dockerfile): remove default CMD to allow dynamic test script execution in Docker * refactor(config.test.ts): anonymize API keys in tests for better security practices * feat(config.test.ts): add tests for OCO_ANTHROPIC_API_KEY configuration * refactor(config.ts): streamline path imports and remove unused DotenvParseOutput - Simplify path module imports by removing default import and using named imports for `pathJoin` and `pathResolve`. - Remove unused `DotenvParseOutput` import to clean up the code. * refactor(config.test.ts): simplify API key mock values for clarity in tests * test(config.test.ts): remove tests for default config values and redundant cases - Removed tests that checked for default config values when no config or env files are present, as these scenarios are now handled differently. - Eliminated tests for empty global config and local env files to streamline testing focus on actual config loading logic. - Removed test for prioritizing local env over global config due to changes in config loading strategy, simplifying the configuration management. * new version --------- Co-authored-by: Takanori Matsumoto <matscube@gmail.com> Co-authored-by: Moret84 <aurelienrivet@hotmail.fr> Co-authored-by: yowatari <4982161+YOwatari@users.noreply.github.com> Co-authored-by: metavind <94786679+metavind@users.noreply.github.com> * 3.0.15 * build * 🐛 (prepare-commit-msg-hook.ts): improve error message to cover missing OCO_ANTHROPIC_API_KEY and OCO_AZURE_API_KEY in addition to OCO_OPENAI_API_KEY * 🐛 (azure.ts): fix check for OCO_AI_PROVIDER to properly assign provider variable 🐛 (azure.ts): initialize OpenAIClient only if provider is 'azure' 🔧 (Dockerfile): rearrange instructions to optimize caching by copying package.json and package-lock.json first before running npm ci and copying the rest of the files 🔧 (e2e/noChanges.test.ts): remove unnecessary line break 🔧 (e2e/oneFile.test.ts): remove unnecessary line break --------- Co-authored-by: Takuya Ono <takuya-o@users.osdn.me> Co-authored-by: GPT10 <57486732+di-sukharev@users.noreply.github.com> Co-authored-by: Takanori Matsumoto <matscube@gmail.com> Co-authored-by: Moret84 <aurelienrivet@hotmail.fr> Co-authored-by: yowatari <4982161+YOwatari@users.noreply.github.com> Co-authored-by: metavind <94786679+metavind@users.noreply.github.com> Co-authored-by: di-sukharev <dim.sukharev@gmail.com>
… prompt (di-sukharev#341) docs(README.md): document the `--yes` flag usage in README for user guidance
… MODEL]` validator to allow for dynamic model selection based on configuration (di-sukharev#337) feat(engine/ollama.ts): integrate with config command to load OCO_MODEL from configuration and use it as the default AI engine model
- Added Google Gemini - Updated AiEngine to import AI provider classes instead of importing instances so that the app doesn't attempt to instantiate every AI provider class - Small refactoring to clean up typescript linting errors in generateCommitMessageFromGitdiff.ts
…ther modules ♻️ (utils/engine.ts): refactor getEngine function to use OCO_AI_PROVIDER environment variable to determine the AI engine to use ♻️ (test/unit/gemini.test.ts): remove unnecessary mock call to generateContent in Gemini test
# Conflicts: # README.md # out/cli.cjs # out/github-action.cjs # package-lock.json # package.json # src/commands/config.ts # src/engine/anthropic.ts # src/engine/azure.ts # src/engine/ollama.ts # src/engine/openAi.ts # src/engine/testAi.ts # src/utils/engine.ts # test/jest-setup.ts # test/unit/config.test.ts
# Conflicts: # README.md # out/cli.cjs # out/github-action.cjs # src/commands/config.ts # src/utils/engine.ts # test/e2e/noChanges.test.ts # test/e2e/oneFile.test.ts
This commit removes unused imports and mock dependencies from the `gemini.test.ts` file. The following changes were made: - Removed unused imports: `HarmBlockThreshold`, `HarmCategory`, `CONFIG_MODES`, `DEFAULT_TOKEN_LIMITS`, `MODEL_LIST`. - Removed unnecessary mocking of `@google/generative-ai` and `../src/commands/config` as they are now imported directly. - Removed unnecessary mocking of `process.exit` as it is now used directly. - Removed unnecessary mocking of `warmup` method as it is now used directly. - Removed unnecessary mocking of `generateCommitMessage` method as it is now used directly. - Removed unnecessary mocking of `process.argv` as it is now used directly. - Removed unnecessary mocking of `process.env` as it is now used directly. - Removed unnecessary mocking of `getConfig` method as it is now used directly. - Removed unnecessary mocking of `intro` and `outro` methods from `@clack/prompts` as they are not used in this test. These changes improve the readability and maintainability of the test file.
Contributor
Author
|
@di-sukharev can you merge this when you get a chance? I abandoned the other PR when I targeted to dev because I realized there were a lot of other changes that were conflicting significantly with the changes I have made. |
Owner
|
I will, a bit busy today, thank you!
|
b0d7e15 to
f2d005e
Compare
di-sukharev
added a commit
that referenced
this pull request
Aug 13, 2024
* 📝 (README.md): add support for custom AI models and update documentation to reflect new environment variable OCO_ AI_PROVIDER (#351) * Feat/add gemini (#349) * 🐛Fix: prompt-module/@commitlint (#336) * fix(commitlint/utils.ts): correct variable used in search for JSON block end tag * ♻️ (commitlint/config.ts & pwd-commitlint.ts): Refactor commitlint config loading to support both CJS and ESM modules 💡 (pwd-commitlint.ts): Add detailed comments and error handling for better clarity and robustness in commitlint module loading process * ✨ (package.json): Add setup script for e2e tests to install dependencies for commitlint configurations 🔧 (setup.sh): Add shell script to set up commitlint configurations for e2e tests * ✨ (config.ts): Add support for OCO_TEST_MOCK_TYPE configuration key to define test mock type for testing purposes 📝 (config.ts): Update documentation for OCO_TEST_MOCK_TYPE configuration key in configValidators and getConfig functions 📝 (testAi.ts): Add TEST_MOCK_TYPES constant array to define supported test mock types 📝 (testAi.ts): Update generateCommitMessage function to use OCO_TEST_MOCK_TYPE from config for different test mock types 📝 (commitlint.test.ts): Add e2e test for running "oco commitlint force" with different @commitlint versions using CJS and ESM 📝 (utils.ts): Add wait function to introduce delay in milliseconds for testing purposes * ✨ (commitlint.test.ts): refactor setupCommitlint function to accept a version parameter for better code organization and readability 📝 (commitlint.test.ts): add test case for commitlint@9 using CJS to ensure proper functionality and compatibility 📝 (commitlint.test.ts): add test case for commitlint@18 using CJS to ensure proper functionality and compatibility 📝 (commitlint.test.ts): add test case for commitlint@19 using ESM to ensure proper functionality and compatibility * 🔧 (commitlint.test.ts): remove unnecessary commands to create and add index.ts file before running tests * refactor(test/e2e/prompt-module/commitlint.test.ts): remove unused import configure style(test/e2e/prompt-module/commitlint.test.ts): add missing semicolon for consistency test(test/e2e/prompt-module/commitlint.test.ts): add e2e tests for @commitlint prompt-module integration * ✨ (e2e tests): add package.json copying to setupCommitlint for version accuracy ♻️ (commitlint config): refactor commitlint.config.js to use ES module syntax ✨ (package.json): specify "type": "module" to support ES module syntax * docs: spelling fix (#325) * 3.0.17 * ♻️ (config.ts): refactor OCO_AZURE_ENDPOINT default value from empty string to undefined resolving #352 - creates invalid config file --------- Co-authored-by: tumf <y.takahara@gmail.com> Co-authored-by: Drew Payment <drew.payment@gmail.com> Co-authored-by: Takanori Matsumoto <matscube@gmail.com> Co-authored-by: Kellan Stevens <kellan@kellanstevens.com> Co-authored-by: di-sukharev <dim.sukharev@gmail.com>
di-sukharev
added a commit
that referenced
this pull request
Aug 18, 2024
* 📝 (README.md): add support for custom AI models and update documentation to reflect new environment variable OCO_ AI_PROVIDER (#351) * feat/add gemini (#349) * fix: prompt-module/@commitlint (#336) * docs: spelling fix (#325) --------- Co-authored-by: tumf <y.takahara@gmail.com> Co-authored-by: Drew Payment <drew.payment@gmail.com> Co-authored-by: Takanori Matsumoto <matscube@gmail.com> Co-authored-by: Kellan Stevens <kellan@kellanstevens.com> Co-authored-by: JMN09 <jmn09@mail.aub.edu> Co-authored-by: JMN09 <157629053+JMN09@users.noreply.github.com>
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.
Ok @di-sukharev ! I rewrote all of the Gemini integration. It seems like a lot of changes have been happening often.
I also stopped all of the models from instantiating on app start and imported the classes so that they instantiate only if they're being used now (I hope there isn't another reason why that would have been happening before).
This should be good to merge. I think 2 of my error case tests broke while merging but will update those soon.