Fix/open utf8 encodingfix: specify utf-8 encoding for text file reads#4350
Fix/open utf8 encodingfix: specify utf-8 encoding for text file reads#4350LuoisaWu wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThis PR adds explicit UTF-8 encoding to file ChangesUTF-8 Encoding Fixes
Aleph Alpha Sample App
Estimated code review effort: 1 (Trivial) | ~5 minutes Related issues: Suggested labels: bug, enhancement, dependencies Suggested reviewers: nirga 🐰 A rabbit hopped through code so wide, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
scripts/codegen/generate_evaluator_models.py (1)
27-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove leftover commented-out code / trailing whitespace.
Line 27 keeps the old
open()call as a comment and line 28 has trailing whitespace.♻️ Proposed cleanup
- # with open(swagger_path) as f: the same as above, we need to specify encoding - with open(swagger_path, encoding="utf-8") as f: + with open(swagger_path, encoding="utf-8") as f: data = json.load(f)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/codegen/generate_evaluator_models.py` around lines 27 - 28, Remove the leftover commented-out `open()` line and trim the trailing whitespace in the `generate_evaluator_models.py` block; keep the actual `with open(swagger_path, encoding="utf-8") as f:` call and clean up the surrounding formatting so the `open` usage is only represented once and the line is whitespace-free.packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py (1)
26-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove leftover commented-out code.
Lines 26 and 31 keep the old
open()calls as comments; line 32 also has trailing whitespace. Consider dropping the dead comments and trailing whitespace for cleanliness.♻️ Proposed cleanup
p = Path(__file__).with_name("qdrant_client_methods.json") -# with open(p, "r") as f: --first version of the file was not utf-8 encoded, so we need to specify encoding with open(p, "r", encoding="utf-8") as f: QDRANT_CLIENT_METHODS = json.loads(f.read()) p = Path(__file__).with_name("async_qdrant_client_methods.json") -# with open(p, "r") as f: the same as above, we need to specify encoding -with open(p, "r", encoding="utf-8") as f: +with open(p, "r", encoding="utf-8") as f: ASYNC_QDRANT_CLIENT_METHODS = json.loads(f.read())🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py` around lines 26 - 32, Remove the leftover commented-out open() lines in the qdrant instrumentation module and clean up the trailing whitespace. Update the import-time JSON loading code in __init__.py around the QDRANT_CLIENT_METHODS and async_qdrant_client_methods.json reads so only the active with open(..., encoding="utf-8") calls remain, with no dead comments or extra spaces.packages/sample-app/sample_app/alephalpha_example.py (1)
8-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a docstring documenting required env vars.
Other sample scripts (e.g.
litellm_completion.py) document required environment variables andTRACELOOP_API_KEYneeds upfront in a module docstring. This script silently falls back betweenALEPH_ALPHA_API_KEY/AA_TOKENand will only fail atclient.complete()call time with an unclear error if neither is set.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sample-app/sample_app/alephalpha_example.py` around lines 8 - 10, Add a module docstring at the top of alephalpha_example.py that documents the required environment variables, matching the style used in other sample scripts like litellm_completion.py. Mention that TRACELOOP_API_KEY is required upfront and that the Aleph Alpha client expects either ALEPH_ALPHA_API_KEY or AA_TOKEN, so users know what must be set before running the sample. Keep the guidance near Traceloop.init and Client initialization so the required setup is clear immediately.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py`:
- Around line 26-32: Remove the leftover commented-out open() lines in the
qdrant instrumentation module and clean up the trailing whitespace. Update the
import-time JSON loading code in __init__.py around the QDRANT_CLIENT_METHODS
and async_qdrant_client_methods.json reads so only the active with open(...,
encoding="utf-8") calls remain, with no dead comments or extra spaces.
In `@packages/sample-app/sample_app/alephalpha_example.py`:
- Around line 8-10: Add a module docstring at the top of alephalpha_example.py
that documents the required environment variables, matching the style used in
other sample scripts like litellm_completion.py. Mention that TRACELOOP_API_KEY
is required upfront and that the Aleph Alpha client expects either
ALEPH_ALPHA_API_KEY or AA_TOKEN, so users know what must be set before running
the sample. Keep the guidance near Traceloop.init and Client initialization so
the required setup is clear immediately.
In `@scripts/codegen/generate_evaluator_models.py`:
- Around line 27-28: Remove the leftover commented-out `open()` line and trim
the trailing whitespace in the `generate_evaluator_models.py` block; keep the
actual `with open(swagger_path, encoding="utf-8") as f:` call and clean up the
surrounding formatting so the `open` usage is only represented once and the line
is whitespace-free.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 85f55567-34b5-4ea6-b274-624c289e0ae7
📒 Files selected for processing (4)
packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.pypackages/sample-app/pyproject.tomlpackages/sample-app/sample_app/alephalpha_example.pyscripts/codegen/generate_evaluator_models.py
Summary
Fixes #4286.
This PR adds explicit
encoding="utf-8"to text-modeopen()calls that read JSON / Swagger files.This avoids relying on the platform default encoding, which can fail on systems where the default encoding is not UTF-8, such as Windows environments using GBK.
Changes
encoding="utf-8"when loading Qdrant method metadata JSON files.encoding="utf-8"when loading the Swagger spec in the evaluator model codegen script.Verification