Skip to content

Conversation

@abidkhan484
Copy link

@abidkhan484 abidkhan484 commented Jul 31, 2025

Pull Request Title

Fix user journey with openai API key. e.g: resume or job description parsing etc.

Related Issue

#421
#430

Description

Fixed OpenAI integration issues: resolved top_k param update, updated default model, handled CreateEmbeddingResponse access error, added missing API key config, and improved structure_job prompt to correctly detect remoteStatus.

Type

  • Bug Fix
  • Feature Enhancement
  • Documentation Update
  • Code Refactoring
  • Other (please specify):

Proposed Changes

  1. Fix top_k issue happened due to openai API update.
  2. Updated the default model of openai API.
  3. Fix OpenAI embedding data app.agent.exceptions.ProviderError: OpenAI - error generating embedding: 'CreateEmbeddingResponse' object is not subscriptable
  4. Fix the config with adding OpenAI API key attribute.
  5. Update the structure_job prompt to detect correct value of remoteStatus.

How to Test

  • With completing the user journey with OPENAI_API_KEY by providing resume or job description.

Checklist

  • The code compiles successfully without any errors or warnings
  • The changes have been tested and verified
  • The documentation has been updated (if applicable)
  • The changes follow the project's coding guidelines and best practices
  • The commit messages are descriptive and follow the project's guidelines
  • All tests (if applicable) pass successfully
  • This pull request has been linked to the related issue (if applicable)

Summary by cubic

Fixed issues with the OpenAI integration so users can now parse resumes and job descriptions without errors.

  • Bug Fixes
    • Updated default model and fixed parameter names to match latest OpenAI API.
    • Resolved embedding response access error.
    • Added missing OpenAI API key config.
    • Improved job prompt to detect remote status correctly.

Summary by CodeRabbit

  • Enhancements

    • Improved the clarity of prompt instructions by explicitly listing valid options for the remote status field in the JSON output.
    • Minor formatting correction in the prompt text for better readability.
  • Chores

    • Removed an unnecessary trailing newline in internal exception handling (no user-facing impact).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

Walkthrough

One file had only a whitespace change, removing a trailing newline. Another file updated a prompt by dynamically inserting valid enum values for a field, ensuring output adheres to allowed options, and made a minor formatting correction. No changes were made to public APIs or function/class declarations.

Changes

Cohort / File(s) Change Summary
Whitespace Adjustment
apps/backend/app/agent/providers/openai.py
Removed a trailing newline at the end of the file; no functional or logic changes.
Prompt Update with Enum Values
apps/backend/app/prompt/structured_job.py
Imports RemoteStatusEnum and dynamically inserts its values into the prompt; minor formatting fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~6 minutes

Poem

A hop and a skip, a newline's gone astray,
While prompts now sing with enums on display.
Formatting tweaks, enum values in tow,
These little changes help the workflow grow.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 48b3265 and 740ab60.

📒 Files selected for processing (1)
  • apps/backend/app/agent/providers/openai.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/backend/app/agent/providers/openai.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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.

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.

Actionable comments posted: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f2ed00b and 48b3265.

📒 Files selected for processing (3)
  • apps/backend/app/agent/providers/openai.py (3 hunks)
  • apps/backend/app/core/config.py (1 hunks)
  • apps/backend/app/prompt/structured_job.py (1 hunks)
🔇 Additional comments (4)
apps/backend/app/prompt/structured_job.py (2)

1-4: Excellent implementation of dynamic enum values.

The dynamic generation of remote_status_values from RemoteStatusEnum ensures the prompt stays synchronized with schema changes automatically. This is a robust approach that prevents manual maintenance issues.


12-12: Great improvement to prompt specificity.

Adding the specific allowed values for remoteStatus directly in the prompt will significantly improve the accuracy of structured output from the OpenAI model by providing clear constraints.

apps/backend/app/agent/providers/openai.py (2)

61-61: Good fix for embedding response access.

The change from dictionary-style access (response["data"][0]["embedding"]) to attribute-style access (response.data[0].embedding) correctly addresses the issue mentioned in the PR objectives where CreateEmbeddingResponse object was not subscriptable.


15-15: No action needed: gpt-4.1-mini is a valid OpenAI model

  • apps/backend/app/agent/providers/openai.py:15 – the default model "gpt-4.1-mini" is officially supported (a smaller, cost-efficient variant of GPT-4.1). No change required.

"top_p": generation_args.get("top_p", 0.9),
"top_k": generation_args.get("top_k", 40),
"max_tokens": generation_args.get("max_length", 20000),
"max_output_tokens": generation_args.get("max_length", 20000),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the parameter name change.

The parameter was changed from "max_tokens" to "max_output_tokens". This aligns with the PR objective of fixing parameter issues due to OpenAI API updates.


🌐 Web query:

What is the correct parameter name for limiting output tokens in the current OpenAI API - is it "max_tokens" or "max_output_tokens"?

💡 Result:

In the OpenAI API, the parameter used to limit the number of tokens generated in a model's response is max_tokens. This parameter sets the maximum number of tokens that the model will generate in the completion. It's important to note that the total number of tokens in your prompt plus the max_tokens value cannot exceed the model's context length. (help.openai.com)

For newer reasoning models like o3, o4-mini, and gpt-4.1, OpenAI has introduced the max_completion_tokens parameter. This parameter specifically limits the number of tokens generated in the model's response. However, for earlier models, max_tokens remains the appropriate parameter to use. (help.openai.com)

Therefore, if you're working with newer reasoning models, you should use max_completion_tokens to limit the output tokens. For earlier models, max_tokens is the correct parameter.

Citations:


Use the correct OpenAI API parameter name

We’ve confirmed that the OpenAI API expects max_tokens (or, for newer “o3”-style models, max_completion_tokens) rather than max_output_tokens. Please update the call accordingly.

• apps/backend/app/agent/providers/openai.py:39

-            "max_output_tokens": generation_args.get("max_length", 20000),
+            "max_tokens":           generation_args.get("max_length", 20000),

If you’re targeting a newer reasoning model (e.g. o3, o4-mini, gpt-4.1), switch to:

-            "max_output_tokens": generation_args.get("max_length", 20000),
+            "max_completion_tokens": generation_args.get("max_length", 20000),
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"max_output_tokens": generation_args.get("max_length", 20000),
"max_tokens": generation_args.get("max_length", 20000),
🤖 Prompt for AI Agents
In apps/backend/app/agent/providers/openai.py at line 39, the parameter name
"max_output_tokens" is incorrect for the OpenAI API. Replace "max_output_tokens"
with "max_tokens" for standard models or "max_completion_tokens" if targeting
newer "o3"-style models like "o3", "o4-mini", or "gpt-4.1" to ensure
compatibility with the API.

SESSION_SECRET_KEY: Optional[str]
DB_ECHO: bool = False
PYTHONDONTWRITEBYTECODE: int = 1
OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY')
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix type annotation to handle potential None value.

The type annotation indicates str but os.getenv('OPENAI_API_KEY') returns None if the environment variable is not set, causing a type mismatch.

Apply this diff to fix the type annotation:

-    OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY')
+    OPENAI_API_KEY: Optional[str] = os.getenv('OPENAI_API_KEY')

Alternatively, if you want to ensure a string value:

-    OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY')
+    OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY', '')
🤖 Prompt for AI Agents
In apps/backend/app/core/config.py at line 17, the variable OPENAI_API_KEY is
annotated as str but os.getenv can return None if the environment variable is
not set. To fix this, change the type annotation to Optional[str] to reflect
that the value can be either a string or None. Import Optional from typing if
not already imported.

@abidkhan484 abidkhan484 changed the title user journey with openai is now working srbhr/Resume-Matcher#421 OpenAI Integration Fixes and Prompt Enhancements Jul 31, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic analysis

2 issues found across 3 files • Review in cubic

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

SESSION_SECRET_KEY: Optional[str]
DB_ECHO: bool = False
PYTHONDONTWRITEBYTECODE: int = 1
OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY')
Copy link
Contributor

Choose a reason for hiding this comment

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

Rule violated: Detect Unused or Redundant Configuration Parameters

OPENAI_API_KEY is added to Settings, but the rest of the codebase never references settings.OPENAI_API_KEY; all consumers still call os.getenv(&quot;OPENAI_API_KEY&quot;). This makes the new configuration parameter redundant and misleading, violating the guideline on removing unused configuration parameters.

Prompt for AI agents
Address the following comment on apps/backend/app/core/config.py at line 17:

<comment>`OPENAI_API_KEY` is added to `Settings`, but the rest of the codebase never references `settings.OPENAI_API_KEY`; all consumers still call `os.getenv(&quot;OPENAI_API_KEY&quot;)`. This makes the new configuration parameter redundant and misleading, violating the guideline on removing unused configuration parameters.</comment>

<file context>
@@ -14,6 +14,7 @@ class Settings(BaseSettings):
     SESSION_SECRET_KEY: Optional[str]
     DB_ECHO: bool = False
     PYTHONDONTWRITEBYTECODE: int = 1
+    OPENAI_API_KEY: str = os.getenv(&#39;OPENAI_API_KEY&#39;)
 
     model_config = SettingsConfigDict(
</file context>

SESSION_SECRET_KEY: Optional[str]
DB_ECHO: bool = False
PYTHONDONTWRITEBYTECODE: int = 1
OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY')
Copy link
Contributor

Choose a reason for hiding this comment

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

Annotating OPENAI_API_KEY as str while defaulting to os.getenv() can produce a None value that violates the declared type and defeats Pydantic’s built-in env loading; declare it Optional[str] and let BaseSettings handle the environment lookup instead.

Prompt for AI agents
Address the following comment on apps/backend/app/core/config.py at line 17:

<comment>Annotating OPENAI_API_KEY as str while defaulting to os.getenv() can produce a None value that violates the declared type and defeats Pydantic’s built-in env loading; declare it Optional[str] and let BaseSettings handle the environment lookup instead.</comment>

<file context>
@@ -14,6 +14,7 @@ class Settings(BaseSettings):
     SESSION_SECRET_KEY: Optional[str]
     DB_ECHO: bool = False
     PYTHONDONTWRITEBYTECODE: int = 1
+    OPENAI_API_KEY: str = os.getenv(&#39;OPENAI_API_KEY&#39;)
 
     model_config = SettingsConfigDict(
</file context>
Suggested change
OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY')
OPENAI_API_KEY: Optional[str] = None

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.

1 participant