Skip to content
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

fix: keyterms to keyterm #363

Merged
merged 1 commit into from
Feb 13, 2025
Merged

fix: keyterms to keyterm #363

merged 1 commit into from
Feb 13, 2025

Conversation

naomi-lgbt
Copy link
Collaborator

@naomi-lgbt naomi-lgbt commented Feb 13, 2025

Summary by CodeRabbit

  • Refactor
    • Renamed the audio processing keyword configuration from a plural to singular form to ensure consistency across live, recorded, and transcription functionalities.
    • Updated the handling of key term inputs to work with the new singular parameter.
    • Deprecated an older session termination method in favor of an improved alternative.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

The diff updates the property name used for specifying key terms across several files. In all affected locations—ranging from example configurations and transcription functions to type declarations and client logic—the property has been renamed from keyterms to keyterm. In addition, the conditional checks related to key term handling have been updated accordingly. One client method has been additionally modified to deprecate the finish method in favor of calling requestClose.

Changes

File(s) Change Summary
examples/node-agent-live/index.js, examples/node-live/index.js, examples/node-prerecorded/index.js Renamed configuration parameter from keyterms to keyterm in Deepgram agent setup and transcription functions.
src/lib/types/AgentLiveSchema.ts, src/lib/types/TranscriptionSchema.ts Updated interface properties: changed keyterms to keyterm while preserving the type (array of strings or union type).
src/packages/AgentLiveClient.ts, src/packages/ListenLiveClient.ts, src/packages/ListenRestClient.ts Modified conditional checks to verify keyterm rather than keyterms in client methods; deprecation update in ListenLiveClient.finish() now calls requestClose().

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Code
    participant ALC as AgentLiveClient
    participant Deepgram as Deepgram API

    Client->>ALC: configure(options) with agent.listen.keyterm
    ALC->>ALC: Check if agent.listen.keyterm exists
    alt Key term exists and model valid
        ALC->>Deepgram: Start agent with provided keyterm
    else Key term invalid/not supported
        ALC-->>Client: Throw DeepgramError
    end
Loading
sequenceDiagram
    participant Client as Client Code
    participant LLC as ListenLiveClient

    Client->>LLC: finish()
    LLC->>LLC: Call requestClose() internally
    LLC-->>Client: Connection is terminated
Loading

Possibly related PRs

Suggested reviewers

  • lukeocodes
  • jpvajda
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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 (2)
src/packages/ListenLiveClient.ts (1)

133-135: 💡 Verification agent

🧩 Analysis chain

Ensure deprecation notice is documented.

The finish method is now deprecated in favor of requestClose. Make sure this deprecation is documented in the changelog and that consumers are notified of the migration path.

Run the following script to find any direct usages of the deprecated method:


🏁 Script executed:

#!/bin/bash
# Description: Find usages of the deprecated finish method.
rg -A 2 "\.finish\(\)" --type ts --type js

Length of output: 467


Action: Update Documentation and Test References for the Deprecated Method

Please update the changelog to document the deprecation of the finish method, including explicit migration instructions to use requestClose instead. Additionally, note that the deprecated method is still referenced in the disabled tests (e.g., disabled_tests/live.test.ts), so either update these tests to use requestClose or add a comment clarifying that their usage is intentional (and that those tests remain disabled).

src/packages/ListenRestClient.ts (1)

82-86: 🛠️ Refactor suggestion

Add keyterm validation to transcribeFile method.

For consistency, the same keyterm validation that exists in transcribeUrl should be added to transcribeFile. This ensures consistent behavior across both transcription methods.

Add the validation before the requestUrl construction:

  async transcribeFile(
    source: FileSource,
    options?: PrerecordedSchema,
    endpoint = ":version/listen"
  ): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
    try {
      let body;

      if (isFileSource(source)) {
        body = source;
      } else {
        throw new DeepgramError("Unknown transcription source type");
      }

      if (options !== undefined && "callback" in options) {
        throw new DeepgramError(
          "Callback cannot be provided as an option to a synchronous transcription. Use `transcribeUrlCallback` or `transcribeFileCallback` instead."
        );
      }

+     if (options?.keyterm?.length && !options.model?.startsWith("nova-3")) {
+       throw new DeepgramError("Keyterms are only supported with the Nova 3 models.");
+     }

      const requestUrl = this.getRequestUrl(endpoint, {}, { ...{}, ...options });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e301786 and ff782fb.

📒 Files selected for processing (8)
  • examples/node-agent-live/index.js (1 hunks)
  • examples/node-live/index.js (1 hunks)
  • examples/node-prerecorded/index.js (2 hunks)
  • src/lib/types/AgentLiveSchema.ts (1 hunks)
  • src/lib/types/TranscriptionSchema.ts (1 hunks)
  • src/packages/AgentLiveClient.ts (1 hunks)
  • src/packages/ListenLiveClient.ts (1 hunks)
  • src/packages/ListenRestClient.ts (1 hunks)
🔇 Additional comments (6)
examples/node-agent-live/index.js (1)

31-31: LGTM! Change is consistent with other files.

The property rename from keyterms to keyterm in the agent configuration matches the changes in other files.

examples/node-live/index.js (1)

23-24: LGTM! Change aligns with documentation comment.

The property rename from keyterms to keyterm matches the "Keyterm Prompting" terminology in the comment above.

src/lib/types/AgentLiveSchema.ts (1)

170-172: LGTM! Type definition maintains array support.

The property rename from keyterms to keyterm in the type definition:

  1. Maintains the string[] type
  2. Aligns with the documentation link
  3. Matches the implementation in example files
src/packages/ListenLiveClient.ts (1)

38-38: LGTM!

The condition has been correctly updated to check for the new keyterm property.

src/packages/AgentLiveClient.ts (1)

124-124: LGTM!

The condition has been correctly updated to check for the new keyterm property.

src/packages/ListenRestClient.ts (1)

55-55: LGTM!

The condition has been correctly updated to check for the new keyterm property.

@@ -12,7 +12,7 @@ const transcribeUrl = async () => {
},
{
model: "nova-3",
keyterms: ["spacewalk"],
keyterm: ["spacewalk"],
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 array syntax with renamed property.

The property has been renamed from keyterms to keyterm, but it still accepts an array value. Let's verify this is the intended behavior.

Also applies to: 33-33


🌐 Web query:

What is the correct syntax for the keyterm parameter in Deepgram API v2?

💡 Result:

The correct syntax for keyword boosting in Deepgram API v2 involves using multiple keywords parameters with optional weight modifiers. Here's how to implement it:

Basic Syntax
For standard keyword boosting without custom weights:

options = PrerecordedOptions(
    keywords=["epistemology", "ontology"]
)

This sends two keywords as separate parameters[1][4].

Weighted Syntax
To assign importance levels (weights):

options = PrerecordedOptions(
    keywords=["deepgram:10", "api:5"]
)

The colon separates keyword from its weight (1-10 scale)[10].

Key Implementation Details

  • Use array format for multiple keywords[7]
  • Weight defaults to 1 if unspecified[10]
  • Maximum recommended: 100 keywords per request[1]
  • Works best with uncommon words/proper nouns[3][4]

For API v2 specifically:

response = deepgram.listen.rest.v("2").transcribe_file(
    payload,
    options=options
)

The keyword parameter remains consistent across API versions but requires using appropriate SDK methods for each version[7][9].

Note: While called "keyword boosting" in documentation[4], the actual parameter name is keywords (plural)[10]. Avoid confusing it with non-existent keyterm parameter mentioned in some third-party implementations[3].

Citations:


Update property name to match Deepgram API v2 requirements.

The Deepgram API v2 documentation specifies using the keywords (plural) parameter with an array value for keyword boosting, not keyterm or keyterms. Although the array syntax is correct, please update the property name in the example code accordingly.

  • Location:
    • examples/node-prerecorded/index.js
      • Lines 15 and 33 should use keywords instead of keyterm.

@@ -97,7 +97,7 @@ interface TranscriptionSchema extends Record<string, unknown> {
/**
* @see https://developers.deepgram.com/docs/keyterm
*/
keyterms?: string[] | string;
keyterm?: string[] | string;
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 breaking change impact.

The renaming of keyterms to keyterm is a breaking change that will affect consumers of this interface. Ensure this change is properly documented in the changelog and that the major version is bumped accordingly.

Run the following script to find all usages of the old property name:


🏁 Script executed:

#!/bin/bash
# Description: Find any remaining usages of the old property name.
rg -i "keyterms" --type ts

Length of output: 384


Action: Update error messages and documentation for the property rename

The change from keyterms to keyterm in src/lib/types/TranscriptionSchema.ts is indeed breaking. Additionally, our search shows that the term "Keyterms" still appears in error messages in the following files:

  • src/packages/ListenLiveClient.ts
  • src/packages/ListenRestClient.ts
  • src/packages/AgentLiveClient.ts

Please verify that these error messages are either updated to reflect the new property name or that they clearly communicate the intended behavior. Also, ensure that the changelog documents this breaking change and that the major version is bumped accordingly.

@naomi-lgbt naomi-lgbt merged commit 490a2eb into main Feb 13, 2025
4 checks passed
@naomi-lgbt naomi-lgbt deleted the fix/keyterm branch February 13, 2025 19:32
@kdawgwilk
Copy link

This actually causes more confusion I think because the old property uses keywords which is plural and this does not. The SDK API I would think should receive keyterms plural as the property and then map that to the API keyterm query params

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