Skip to content

Add support for OpenAI organization in the secrets file - #2

Merged
okotek merged 1 commit into
mainfrom
feature/support_openai_org
Jul 6, 2023
Merged

okotek merged 1 commit into
mainfrom
feature/support_openai_org

Conversation

@okotek

@okotek okotek commented Jul 6, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@okotek
okotek merged commit 84231f9 into main Jul 6, 2023
@okotek
okotek deleted the feature/support_openai_org branch July 6, 2023 07:06
@almog-lv

almog-lv commented Jul 6, 2023

Copy link
Copy Markdown
Contributor

@CodiumAI-Agent

@QodoAI-Agent

Copy link
Copy Markdown

PR Analysis

  • 🎯 Main theme: Adding support for OpenAI organization in the secrets file
  • 🔍 Description and title: No
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ✨ Minimal and focused: Yes, the PR is minimal and focused as it only adds support for OpenAI organization in the secrets file and does not make any other changes.
  • 🔒 Security concerns: No, the PR does not introduce any obvious security concerns as it only adds support for an additional configuration parameter.

PR Feedback

  • 💡 General PR suggestions: The PR lacks a description which is important for understanding the context and purpose of the changes. Please add a meaningful description to the PR. Also, it would be beneficial to add tests to verify the new functionality.

  • 🤖 Code suggestions:

    • relevant file: pr_agent/algo/ai_handler.py
      suggestion content: Consider adding a more specific error message when the OpenAI organization is not found in the settings. This will help in debugging if the key is missing. [important]

    • relevant file: pr_agent/settings/.secrets_template.toml
      suggestion content: Consider adding a comment to explain what the 'org' field represents and where to find it. This will make it easier for users to understand what they need to provide. [medium]

How to use

Tag me in a comment '@CodiumAI-Agent' to ask for a new review after you update the PR.
You can also tag me and ask any question, for example '@CodiumAI-Agent is the PR ready for merge?'

@QodoAI-Agent

Copy link
Copy Markdown

PR Analysis

  • 🎯 Main theme: Adding support for OpenAI organization in the secrets file
  • 🔍 Description and title: No
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ✨ Minimal and focused: Yes, the PR is focused on adding support for OpenAI organization in the secrets file and doesn't contain unrelated changes.
  • 🔒 Security concerns: No, the PR doesn't introduce any obvious security concerns. It's just adding an optional configuration for OpenAI organization.

PR Feedback

  • 💡 General PR suggestions: The PR lacks a description which is crucial for understanding the context and the reason for the changes. It's recommended to always include a meaningful description. Also, it would be beneficial to add tests to verify the new functionality.

  • 🤖 Code suggestions:

    • relevant file: pr_agent/algo/ai_handler.py
      suggestion content: Consider handling the case when the 'org' key is not present in the settings. Currently, if the 'org' key is not present, it might raise an AttributeError. To prevent this, you can use a default value when trying to access the 'org' key. For example: openai.organization = settings.openai.get('org', None) [important]

    • relevant file: pr_agent/settings/.secrets_template.toml
      suggestion content: It would be helpful to add a comment explaining what the 'org' key is used for and how to obtain it, similar to the comment for the 'key'. [medium]

How to use

Tag me in a comment '@CodiumAI-Agent' to ask for a new review after you update the PR.
You can also tag me and ask any question, for example '@CodiumAI-Agent is the PR ready for merge?'

okotek added a commit that referenced this pull request Jul 6, 2023
@okotek
okotek restored the feature/support_openai_org branch January 7, 2024 11:50
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
…ai_org

Add support for OpenAI organization in the secrets file
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
@mrT23

mrT23 commented Jul 16, 2024 •

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Possible issue
Improve the robustness of the check for the 'OPENAI.ORG' setting

Consider using a more explicit check for the presence of the 'OPENAI.ORG' setting.
The current check might not behave as expected if the setting exists but is set to a
falsy value (like an empty string or None). A more robust approach would be to check
if the key exists in the settings and is not None.

pr_agent/algo/ai_handler.py [15-16]

-if settings.get("OPENAI.ORG", None):
+if "OPENAI.ORG" in settings and settings.openai.org is not None:
     openai.organization = settings.openai.org
 
Suggestion importance[1-10]: 9

Why: The suggestion improves the robustness of the code by ensuring that the 'OPENAI.ORG' setting is both present and not None, which prevents potential issues with falsy values.

9
Possible bug
Add error handling for missing 'OpenAI organization' setting

It's recommended to handle the potential AttributeError that could be raised if
settings.openai.org is not set, similar to how the absence of settings.openai.key is
handled. This will prevent the application from crashing due to a missing
configuration.

pr_agent/algo/ai_handler.py [15-16]

 if settings.get("OPENAI.ORG", None):
-    openai.organization = settings.openai.org
+    try:
+        openai.organization = settings.openai.org
+    except AttributeError:
+        raise ValueError("OpenAI organization is required") from None
 
Suggestion importance[1-10]: 8

Why: This suggestion adds valuable error handling for the 'OpenAI organization' setting, similar to the existing handling for the API key, which enhances the code's robustness.

8
Enhancement
Enhance the comment for the 'org' field to provide clearer usage instructions

To avoid confusion and potential errors, consider providing more guidance on when
and how to use the 'org' field in the comments. This could include instructions on
when it's necessary to specify an organization and the implications of doing so.

pr_agent/settings/.secrets_template.toml [11]

-org = "<ORGANIZATION>"  # Optional, may be commented out.
+org = "<ORGANIZATION>"  # Optional. Specify if your API usage is linked to a specific OpenAI organization. Leave commented if not applicable.
 
Suggestion importance[1-10]: 7

Why: The suggestion improves the clarity of the comments, helping users understand when and how to use the 'org' field, which can prevent potential misconfigurations.

7
Best practice
Add logging for successful configuration of OpenAI settings

To ensure that the settings are correctly loaded and used, consider adding a logging
statement that confirms the successful configuration of the OpenAI API key and
organization. This will help in debugging and verifying that the settings are
applied as expected.

pr_agent/algo/ai_handler.py [14-16]

 openai.api_key = settings.openai.key
 if settings.get("OPENAI.ORG", None):
     openai.organization = settings.openai.org
+logging.info("OpenAI API configured with key: %s and organization: %s", settings.openai.key, settings.openai.org)
 
Suggestion importance[1-10]: 6

Why: Adding logging for successful configuration is a good practice for debugging and verification, although it is not crucial for the functionality of the code.

6

mrT23 pushed a commit that referenced this pull request May 25, 2025
feat: add add_diagram flag in configuration.toml
Tyler-Rak referenced this pull request in Tyler-Rak/pr-agent Nov 12, 2025
- Add new /webhook-parallel endpoint for concurrent PR processing
- Extract process_webhook() function for shared logic
- Add configuration options: enable_parallel_reviews, max_concurrent_reviews
- Implement asyncio.create_task() for true concurrent execution
- Add semaphore-based concurrency limiting (default: 5 concurrent reviews)
- Keep original /webhook endpoint unchanged for backward compatibility
- Add comprehensive architecture documentation with sequence diagrams

Benefits:
- PR #2 latency: 80s -> 41s (49% improvement)
- PR #3 latency: 120s -> 42s (65% improvement)
- 3x throughput improvement

Feature can be enabled by:
1. Setting bitbucket_app.enable_parallel_reviews=true
2. Changing webhook URL to /webhook-parallel
agonzalesipcoop-cmyk pushed a commit to agonzalesipcoop-cmyk/pr-agent that referenced this pull request May 8, 2026
…view

- Extract loader into pr_agent/algo/best_practices.py and reuse it from
  /improve and /review so OSS behavior is symmetric (closes Qodo The-PR-Agent#1).
- Guard int(max_lines_allowed) with TypeError/ValueError fallback to 800
  plus a targeted warning (Qodo The-PR-Agent#2).
- Bitbucket get_pr_agent_repo_custom_file: only accept HTTP 200, log
  non-404 failures, add 10s timeout, and use the repo default branch
  via get_repo_default_branch (Qodo The-PR-Agent#3, The-PR-Agent#5, The-PR-Agent#6).
- LocalGitProvider get_pr_agent_repo_custom_file: resolve and verify the
  candidate path stays inside the repo root before reading (Qodo The-PR-Agent#7).
- Soften prompt wording in code-suggestions templates and add a parallel
  block in pr_reviewer_prompts.toml so the model treats the section as
  guidance, ignoring obvious non-guideline content.
- Drop unused _FakeContext test helper, retarget patches to the new
  module, add coverage for the invalid max_lines fallback (Qodo The-PR-Agent#4).
- Update docs/improve.md and docs/review.md to reflect that both tools
  now consume best_practices.md in OSS.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
sizickp pushed a commit to sizickp/pr-agent that referenced this pull request May 15, 2026
Six findings from the latest bot review:

1. `_find_anchor_note` calls `body.startswith` without checking the body
   is a string — add an `isinstance(body, str)` guard. Paranoid but cheap.

2. Anchor selection was wrong when the newest matching note's timestamp
   couldn't be parsed: the local `sorted(...)` with a `datetime.min` fallback
   demoted the newest match below older parseable ones, so incremental runs
   anchored on an older note and re-reviewed already-reviewed commits.
   Drop the local sort entirely — GitLab returns notes in created_at-DESC
   order by default, so iterating in natural order picks the newest match.
   When that match has an unparseable timestamp, `_get_incremental_commits`
   already falls back to a full run via the `last_seen_commit is None`
   branch.

3. `_parse_gitlab_iso_datetime` used single-quoted string literals —
   switched to double quotes to match the repo's Ruff convention.

4. `_get_incremental_commits` extracted `new_path` via dict access only;
   non-dict diff entries (a stricter library or a stubbed client) were
   silently dropped. Add a `getattr(diff, 'new_path', None)` fallback so
   the object-shape branch isn't dead code.

5. `pr_code_suggestions.py` import line wasn't isort-clean after adding
   `IncrementalPR` — reorder to `GitProvider, IncrementalPR, get_main_pr_language`.

6. `PRCodeSuggestions.__init__` called `get_main_pr_language(get_languages(),
   get_files())` before `run()` short-circuited the no-op incremental
   path. For GitLab, `get_files()` falls back to a full `mr.changes()`
   call when `unreviewed_files_set` is empty — that's a wasted API
   round-trip on every push that finds nothing new to review. Set
   `self._incremental_empty_scope = True` and return early from
   `__init__`; `run()` short-circuits on the same flag.

Bot finding The-PR-Agent#2 ("Commit shape mismatch") was a false positive — python-
gitlab's `RESTObject` supports both attribute and item access on the same
object, so the inconsistency the bot flagged doesn't manifest in practice.
@dellch dellch mentioned this pull request Jun 2, 2026
3 tasks done
ashearin added a commit to ashearin/pr-agent that referenced this pull request Jun 29, 2026
- Add GitProvider.publish_managed_labels with a default implementation
  that preserves existing read-modify-write semantics for non-GitLab
  providers (no behavior change for GitHub, Bitbucket, Gitea, etc.).
- Override in GitLabProvider to refresh the MR exactly once and compute
  both the user-label filter and the add/remove diff against that single
  snapshot. This closes the cross-method race where a caller's
  get_pr_labels(update=True) and publish_labels' internal refresh
  produced two snapshots, allowing a label added between them to be
  removed via current - desired.
- /describe (_safe_publish_labels) and /review (set_review_labels) now
  call publish_managed_labels with a managed-label predicate instead of
  doing their own pre-read + manual merge + publish_labels.
- Refactor publish_labels to share _publish_labels_against(mr, desired)
  with publish_managed_labels so the two write paths cannot drift.
- _safe_publish_labels now catches a narrow set of expected
  provider/network errors (ConnectionError, TimeoutError, OSError,
  ValueError, KeyError, AttributeError) instead of bare Exception, so
  programmer errors surface to /describe's outer handler.
- Strengthen publish_labels tests to capture add_labels / remove_labels
  at save-time via a save() side_effect and assert the exact
  comma-separated wire payload.
- Add six tests for publish_managed_labels covering single-refresh,
  user-label preservation, no-op when nothing changes, removal of all
  managed labels when desired is empty, abort on refresh failure, and
  diff-attr cleanup on save() failure.

Addresses Qodo review items #1 (broad except in _safe_publish_labels),
The-PR-Agent#2 (cross-method label race), and The-PR-Agent#3 (weak test payload assertions) on
PR The-PR-Agent#2483.

Signed-off-by: Allen Shearin <allen.p.shearin@gmail.com>
ashearin added a commit to ashearin/pr-agent that referenced this pull request Jun 29, 2026
…h failures via typed exception

Addresses Qodo review items The-PR-Agent#2, The-PR-Agent#3, The-PR-Agent#4 on PR The-PR-Agent#2483.

The-PR-Agent#2 Hardcoded managed_default label set
- Add is_describe_managed_label() and _describe_managed_label_names() in
  pr_agent.algo.utils as the single source of truth for the
  /describe-managed namespace.
- Rewrite get_user_labels() to defer to the same helper so the inclusion
  and exclusion rules can never drift.

The-PR-Agent#3 Default label not managed (Bug fix with tests)
- When enable_custom_labels=True and no custom_labels are configured,
  set_custom_labels injects defaults that include 'Bug fix with tests'.
  is_describe_managed_label now classifies that label as managed so
  /describe can remove it once it is no longer recommended.
- This also fixes a pre-existing bug in get_user_labels where
  'Bug fix with tests' was misclassified as a user label.

The-PR-Agent#4 Refresh failure misreported
- Add LabelRefreshError in pr_agent.git_providers.git_provider so
  callers can distinguish a refresh failure from a genuine no-op.
- GitProvider.publish_managed_labels (default impl) and
  GitLabProvider.publish_managed_labels now raise LabelRefreshError on
  pre-write refresh failure instead of returning None.
- PRDescription._safe_publish_labels and PRReviewer.set_review_labels
  catch LabelRefreshError specifically and log a warning that names the
  failure, instead of mis-logging it as 'labels unchanged' /
  'already set'.

#1, The-PR-Agent#5, The-PR-Agent#6, The-PR-Agent#7 from Qodo's review are already addressed in earlier
commits on this branch (36ec454, a7a8cad); Qodo's review listing is
pinned to PR-level diff hunks so they appear in the report against
older revisions.

Tests:
- New TestDescribeManagedLabelNamespace locks the predicate behavior:
  default-set always managed, Bug fix with tests managed under the
  custom-labels default-injection path, and is_describe_managed_label /
  get_user_labels stay disjoint.
- TestSafePublishLabels gains test_predicate_includes_bug_fix_with_tests_when_custom_labels_default
  and test_logs_distinctly_on_refresh_failure.
- test_pr_reviewer_core gains test_set_review_labels_logs_distinctly_on_refresh_failure.
- test_publish_managed_labels_aborts_when_refresh_fails replaced with
  test_publish_managed_labels_raises_when_refresh_fails.
- Full unit suite: 1066 passed, 1 skipped, 3 xfailed (was 1060).

Signed-off-by: Allen Shearin <allen.p.shearin@gmail.com>
naorpeled added a commit to tharatynowicz/pr-agent that referenced this pull request Aug 8, 2026
…view

Rework the state-leak fix from a full 'restore all settings to a startup
snapshot' into a surgical per-key revert, and address Qodo's review of The-PR-Agent#2346.

Why the rework: a blanket snapshot-restore at the top of apply_repo_settings()
also wipes legitimate per-request/base config that current main sets before the
call (config.extra_config_url, config.is_auto_command, mosaico flags, ...),
regressing 11 existing tests. Instead, note_repo_setting_override() records the
pre-override value of each key a repo/extra .pr_agent.toml writes, and
reset_repo_settings_overrides() reverts exactly those keys on the next load.

This addresses the review findings:
- The-PR-Agent#1 (is_auto_command wiped): flags set outside the repo-settings merge are
  never recorded, so they are never reverted by the second apply_repo_settings().
- The-PR-Agent#2 (reset missed context settings): record/revert both go through
  get_settings(), so a per-request context['settings'] clone is handled too.
- The-PR-Agent#3 (non-atomic global reset): record/revert are guarded by an RLock and touch
  only the overridden keys; full cross-request isolation still relies on a
  per-request clone.

Also uses Dynaconf unset(force=True) (a plain unset() is a no-op) so a
repo-injected key that did not exist at baseline is actually removed on revert.

Tests: extend tests/unittest/test_apply_repo_settings.py with cases for flag
preservation, non-repo config survival, and revert targeting the effective
settings object. Full unit suite: 1717 passed.

Co-authored-by: Tomasz Haratynowicz <75249676+tharatynowicz@users.noreply.github.com>
@naorpeled
naorpeled deleted the feature/support_openai_org branch August 29, 2026 19:59
ira-at-work referenced this pull request in Agrematch/pr-agent Sep 28, 2026
…e fix

- Regenerate the config reference so the documented no_temperature_models
  default includes the GLM-5 entries added in the previous commit (the docs
  build guard would otherwise catch this drift, per Qodo finding #1).
- Extend the Kimi K3 completion test to also cover the GLM-5 bare, regional,
  and Converse spellings, since the model list added a second model with no
  matching coverage (Qodo finding #2).
- Reword the test docstring to imperative phrasing (Qodo finding The-PR-Agent#4).

Qodo finding #3 (import order) is a false positive: `ruff check` against this
repo's actual pyproject.toml config passes the original tomllib-then-pathlib
order unchanged (straight imports sort before from-imports within a section
by default); left as-is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ira-at-work referenced this pull request in Agrematch/pr-agent Sep 28, 2026
…e fix

- Regenerate the config reference so the documented no_temperature_models
  default includes the GLM-5 entries added in the previous commit (the docs
  build guard would otherwise catch this drift, per Qodo finding #1).
- Extend the Kimi K3 completion test to also cover the GLM-5 bare, regional,
  and Converse spellings, since the model list added a second model with no
  matching coverage (Qodo finding #2).
- Reword the test docstring to imperative phrasing (Qodo finding The-PR-Agent#4).

Qodo finding #3 (import order) is a false positive: `ruff check` against this
repo's actual pyproject.toml config passes the original tomllib-then-pathlib
order unchanged (straight imports sort before from-imports within a section
by default); left as-is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ira-at-work referenced this pull request in Agrematch/pr-agent Sep 28, 2026
…e fix

- Regenerate the config reference so the documented no_temperature_models
  default includes the GLM-5 entries added in the previous commit (the docs
  build guard would otherwise catch this drift, per Qodo finding #1).
- Extend the Kimi K3 completion test to also cover the GLM-5 bare, regional,
  and Converse spellings, since the model list added a second model with no
  matching coverage (Qodo finding #2).
- Reword the test docstring to imperative phrasing (Qodo finding The-PR-Agent#4).

Qodo finding #3 (import order) is a false positive: `ruff check` against this
repo's actual pyproject.toml config passes the original tomllib-then-pathlib
order unchanged (straight imports sort before from-imports within a section
by default); left as-is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

4 participants