Skip to content

Conversation

@lukeocodes
Copy link
Contributor

@lukeocodes lukeocodes commented Oct 27, 2025

  • New Features
    • Keyterm and keyword parameters now accept either single or multiple values, enabling more flexible configuration options for listening operations.

@lukeocodes lukeocodes requested a review from jpvajda October 27, 2025 18:20
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

Walkthrough

Type signatures for keyterm and keywords parameters in V1 and V2 listen client methods are expanded to accept Union[str, Sequence[str]]. This enables these parameters to receive either a single string or a sequence of strings, while maintaining backward compatibility with existing single-string usage.

Changes

Cohort / File(s) Summary
V1 Listen Client
src/deepgram/listen/v1/client.py
Updated connect() method signatures in V1Client and AsyncV1Client to accept keyterm and keywords parameters as Optional[Union[str, Sequence[str]]] instead of Optional[str], allowing both single and multiple values.
V2 Listen Client
src/deepgram/listen/v2/client.py
Updated connect() method signatures in V2Client and AsyncV2Client to accept keyterm parameter as Optional[Union[str, Sequence[str]]] instead of Optional[str], enabling both single and multiple values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Changes are limited to type signature updates across four closely-related methods with a consistent pattern
  • No logic changes, control flow modifications, or behavioral alterations
  • Type expansion is straightforward and maintains backward compatibility

Possibly related PRs

  • PR support multiple keyterms for v2 listen client #595: Modifies V2 listen client's keyterm parameter to accept Union[str, Sequence[str]], representing a parallel or preceding effort to support multiple values for keyterm parameters across the listen client versions.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix: keyterm and keywords support for multiple values" directly and accurately describes the main changes in the changeset. The modifications expand the keyterm and keywords parameter types from Optional[str] to Optional[Union[str, Sequence[str]]] across both V1 and V2 client classes in their sync and async connect methods, enabling these parameters to accept either single strings or sequences of strings. The title is clear, concise, and specific enough that a teammate reviewing the commit history would immediately understand the primary objective of the change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lo/keyterm-keywords-string-array

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
src/deepgram/listen/v2/client.py (2)

157-157: Critical: Update async method signature to match sync method.

The sync method at line 46 was updated to accept Union[str, Sequence[str]], but this async method still declares Optional[str]. This creates an inconsistency between sync and async APIs.

Apply this diff to fix the inconsistency:

-        keyterm: typing.Optional[str] = None,
+        keyterm: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,

70-70: Update docstrings to reflect the new parameter type.

The docstrings at lines 70 and 181 still indicate typing.Optional[str], but the parameter now accepts typing.Optional[typing.Union[str, typing.Sequence[str]]]. Update both docstrings to reflect the new type.

Apply these diffs:

Line 70:

-        keyterm : typing.Optional[str]
+        keyterm : typing.Optional[typing.Union[str, typing.Sequence[str]]]

Line 181:

-        keyterm : typing.Optional[str]
+        keyterm : typing.Optional[typing.Union[str, typing.Sequence[str]]]

Also applies to: 181-181

src/deepgram/listen/v1/client.py (2)

267-268: Critical: Update async method signature to match sync method.

The sync method at lines 56-57 was updated to accept Union[str, Sequence[str]] for both parameters, but this async method still declares Optional[str]. This creates an inconsistency between sync and async APIs.

Apply this diff to fix the inconsistency:

-        keyterm: typing.Optional[str] = None,
-        keywords: typing.Optional[str] = None,
+        keyterm: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
+        keywords: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,

100-100: Update docstrings to reflect the new parameter types.

The docstrings at lines 100, 102, 311, and 313 still indicate typing.Optional[str], but these parameters now accept typing.Optional[typing.Union[str, typing.Sequence[str]]]. Update all four docstrings to reflect the new types.

Apply these diffs:

Line 100:

-        keyterm : typing.Optional[str]
+        keyterm : typing.Optional[typing.Union[str, typing.Sequence[str]]]

Line 102:

-        keywords : typing.Optional[str]
+        keywords : typing.Optional[typing.Union[str, typing.Sequence[str]]]

Line 311:

-        keyterm : typing.Optional[str]
+        keyterm : typing.Optional[typing.Union[str, typing.Sequence[str]]]

Line 313:

-        keywords : typing.Optional[str]
+        keywords : typing.Optional[typing.Union[str, typing.Sequence[str]]]

Also applies to: 102-102, 311-311, 313-313

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 876fc73 and 584fb4e.

📒 Files selected for processing (2)
  • src/deepgram/listen/v1/client.py (1 hunks)
  • src/deepgram/listen/v2/client.py (1 hunks)
🔇 Additional comments (1)
src/deepgram/listen/v1/client.py (1)

56-57: LGTM! Verify httpx behavior as noted in v2 client review.

The type signature updates for both keyterm and keywords enable multi-value support. Ensure that httpx.QueryParams.add() at lines 169-172 correctly handles sequences (same verification as requested for the v2 client).

eot_threshold: typing.Optional[str] = None,
eot_timeout_ms: typing.Optional[str] = None,
keyterm: typing.Optional[str] = None,
keyterm: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 27, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify httpx.QueryParams.add() handles sequences correctly.

The type signature update looks good and enables multi-value support. However, ensure that httpx.QueryParams.add() at lines 102-103 correctly serializes a sequence into multiple query parameters with the same key (e.g., ?keyterm=val1&keyterm=val2).

Run the following script to verify httpx behavior:


🏁 Script executed:

#!/bin/bash
# Description: Test httpx.QueryParams.add() behavior with sequences

python << 'EOF'
import httpx

# Test with string
qp = httpx.QueryParams()
qp = qp.add("keyterm", "single")
print("Single string:", str(qp))

# Test with list
qp2 = httpx.QueryParams()
qp2 = qp2.add("keyterm", ["val1", "val2"])
print("List of strings:", str(qp2))

# Test with tuple
qp3 = httpx.QueryParams()
qp3 = qp3.add("keyterm", ("val1", "val2"))
print("Tuple of strings:", str(qp3))
EOF

Length of output: 142


🏁 Script executed:

#!/bin/bash
# Check the actual implementation at lines 102-103 and surrounding context
sed -n '95,110p' src/deepgram/listen/v2/client.py

Length of output: 870


🏁 Script executed:

#!/bin/bash
# Check if other parameters use sequences and how they're handled
rg -n "typing.Sequence" src/deepgram/listen/v2/client.py | head -20

Length of output: 84



---

🌐 Web query:

```web
httpx QueryParams add multiple values same key

💡 Result:

Use a dict whose value is a list (httpx does not accept a list-of-tuples for params). Example:

If you need advanced merging/serialization (custom list formats, preserving order, etc.) consider httpx-qs. [1][2]

Sources:
[1] HTTPX compatibility / Query Parameters (requests -> httpx differences). [3search2]
[2] httpx-qs (extra query-string control). [0search6]


Fix httpx.QueryParams.add() to properly handle keyterm sequences.

The type signature at line 46 allows Union[str, Sequence[str]], but the implementation at line 102 uses .add("keyterm", keyterm) which incorrectly stringifies sequences instead of expanding them into multiple query parameters.

When keyterm=["val1", "val2"] is passed, httpx produces keyterm=%5B%27val1%27%2C+%27val2%27%5D instead of the correct keyterm=val1&keyterm=val2.

Solution: Check if keyterm is a sequence and add multiple parameters, or iterate through the sequence:

if keyterm is not None:
    if isinstance(keyterm, str):
        query_params = query_params.add("keyterm", keyterm)
    else:
        for term in keyterm:
            query_params = query_params.add("keyterm", term)
🤖 Prompt for AI Agents
In src/deepgram/listen/v2/client.py around line 46 and the query-building at
~line 102, the code currently does query_params = query_params.add("keyterm",
keyterm) which stringifies sequences; change it to detect if keyterm is None, a
str, or a sequence (e.g., isinstance(keyterm, str) to treat strings as scalar,
otherwise iterate the sequence) and call query_params.add("keyterm", term) for
each element so multiple keyterm entries are added (keyterm=val1&keyterm=val2)
instead of encoding the whole list.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lukeocodes might be worth looking at.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only is it right, this file should have been updated by Fern.

Shit, i'll need to look into this

@lukeocodes lukeocodes closed this Oct 28, 2025
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