Skip to content

Keyword Extraction Fix and OpenAI bug free #408

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ArshCypherZ
Copy link

@ArshCypherZ ArshCypherZ commented Jul 21, 2025

Pull Request Title

Keyword Extraction Fix and OpenAI bug free

Related Issue

#386

Description

Solves openAI's embedding subscript error, any keywords extraction missed by LLM while parsing resume and fixing employmentType parsing error in job description.

Type

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

Proposed Changes

  • Changed embedding model from ada to small 03 which is better
  • Fixed return type subscript error of embedding function, handling api key of OpenAI
  • Fixed various keywords extraction

Summary by CodeRabbit

  • New Features

    • Added extraction of keywords from resumes, now included as "Extracted Keywords" in the output.
    • Updated configuration to support loading the OpenAI API key from environment variables.
  • Improvements

    • Changed the default embedding model for OpenAI embeddings.
    • Updated prompt instructions for job extraction to standardize "Internship" labeling.
    • Renamed the extracted keywords field in job schemas to use a consistent naming convention.
    • Improved handling of extracted keywords in resume processing to always provide a value.

…e Internship keyword, Also made keyword extraction more robust
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

The changes update environment variable handling for OpenAI API keys, modify prompt instructions for job and resume extraction, adjust schema field naming conventions, and refine how extracted keywords are serialized and stored. Default models and parameters for OpenAI providers are updated, and configuration settings are extended to include an optional API key field.

Changes

File(s) Change Summary
apps/backend/app/agent/providers/openai.py Loads dotenv at module level; removes api_key param from providers; changes default models; updates response access style; removes some generation options.
apps/backend/app/core/config.py Adds optional OPENAI_API_KEY field to Settings class.
apps/backend/app/prompt/structured_job.py Adds rule to set employmentType to "Internship" if it contains "internship".
apps/backend/app/prompt/structured_resume.py Updates prompt to require extraction of keywords into a new field "Extracted Keywords".
apps/backend/app/schemas/json/structured_job.py Renames schema key from "extractedKeywords" to "extracted_keywords".
apps/backend/app/schemas/pydantic/structured_job.py Removes alias "extractedKeywords" from extracted_keywords field in StructuredJobModel.
apps/backend/app/services/resume_service.py Always JSON-encodes extracted_keywords (defaulting to empty list); removes conditional assignment to None.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30-60 minutes

Suggested reviewers

  • srbhr

Poem

In fields of code where changes grow,
The dotenv seeds now softly sow.
Keywords extracted, prompts refined,
Snake_case and clarity aligned.
With every hop, a schema's neat—
This bunny finds the changes sweet!
🐇✨

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 b009871 and 9f0bf6f.

📒 Files selected for processing (1)
  • apps/backend/app/core/config.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/backend/app/core/config.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

🔭 Outside diff range comments (3)
apps/backend/app/agent/providers/openai.py (3)

18-24: api_key arg is accepted but discarded

The constructor signature still exposes api_key, yet the first line overwrites it with os.getenv. This is misleading and blocks dependency-injection/testing.

-    def __init__(self, api_key: None, model: str = "gpt-4o"):
-        api_key = os.getenv("OPENAI_API_KEY")
+    def __init__(self, model: str = "gpt-4o", *, api_key: str | None = None):
+        api_key = api_key or os.getenv("OPENAI_API_KEY")

Do the same for OpenAIEmbeddingProvider, or drop the parameter entirely.


26-37: Incorrect endpoint – will raise at runtime

self._client.responses.create(...) and response.output_text are not part of the official OpenAI Python v1 SDK. Use chat.completions.create (or completions.create) and extract response.choices[0].message.content (or .text) instead.

Example fix:

-            response = self._client.responses.create(
-                model=self.model,
-                instructions=self.instructions,
-                input=prompt,
-                **options,
-            )
-            return response.output_text
+            response = self._client.chat.completions.create(
+                model=self.model,
+                messages=[
+                    {"role": "system", "content": self.instructions},
+                    {"role": "user", "content": prompt},
+                ],
+                **options,
+            )
+            return response.choices[0].message.content

This is a blocking issue—current code will crash on first invocation.


49-57: Same silent-ignore pattern for embeddings

api_key argument is again ignored. Align with the fix suggested for the chat provider to enable explicit key passing or remove the parameter altogether.

🧹 Nitpick comments (3)
apps/backend/app/prompt/structured_job.py (1)

8-9: Clarify internship rule & make it case-insensitive

Consider re-phrasing:

- If employmentType contains the word "internship" (case-insensitive), set the value to "Internship".

This avoids ambiguity and matches the enum in the schema.

apps/backend/app/schemas/pydantic/structured_job.py (1)

97-98: Verify compatibility after alias removal

With the alias gone, any code still emitting extractedKeywords will now fail validation.
If backward compatibility is needed, keep the alias or set populate_by_name=True and accept both keys for a transition period.

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

10-13: Avoid loading .env at import time

Loading environment variables in every import can mask runtime-injected values and slows cold-starts. Prefer calling load_dotenv() once in the main entry-point or behind a guard.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d6a18ef and b009871.

📒 Files selected for processing (7)
  • 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)
  • apps/backend/app/prompt/structured_resume.py (1 hunks)
  • apps/backend/app/schemas/json/structured_job.py (1 hunks)
  • apps/backend/app/schemas/pydantic/structured_job.py (1 hunks)
  • apps/backend/app/services/resume_service.py (0 hunks)
💤 Files with no reviewable changes (1)
  • apps/backend/app/services/resume_service.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/backend/app/agent/providers/openai.py (1)
apps/backend/app/agent/providers/base.py (1)
  • Provider (5-11)
🔇 Additional comments (1)
apps/backend/app/schemas/json/structured_job.py (1)

45-48: No lingering extractedKeywords references found
I ran both

  • rg -n '"extractedKeywords"'
  • rg -n extractedKeywords
    and confirmed there are no remaining camelCase usages. All keys now match the snake_case Pydantic model.

@ArshCypherZ ArshCypherZ changed the title Sometimes there are Full-time Internships and similar, so we priortize Internship keyword, Also made keyword extraction more robust Keyword Extraction Fix and OpenAI bug free Jul 21, 2025
Comment on lines +18 to +19
def __init__(self, api_key: None, model: str = "gpt-4o"):
api_key = os.getenv("OPENAI_API_KEY")

Choose a reason for hiding this comment

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

Why are you keeping the api_key parameter if it's always going to be overwritten by the environment variable?

Copy link
Author

Choose a reason for hiding this comment

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

my bad, it was supposed to be the api_key parameter "or" the environment variable, but during testing i removed the parameter for some reasons and kept only environment variable, looks like i forgot to add it again but it doesn't really matter

Comment on lines +10 to +12
from dotenv import load_dotenv

load_dotenv()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be needed here

@@ -42,7 +42,7 @@
"applyLink": "string",
"contactEmail": "Optional[string]",
},
"extractedKeywords": [
"extracted_keywords": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Since everywhere in the json we are using camel case, any reason why we want to use snake case here?

Copy link
Author

Choose a reason for hiding this comment

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

Since everywhere in the json we are using camel case, any reason why we want to use snake case here?

no reason

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