Skip to content

feat: ChatInterfaze — in-repo LangChain chat model (#5) - #12

Merged
Abhinavexist merged 3 commits into
mainfrom
feat/langchain-chatinterfaze
Jul 22, 2026
Merged

feat: ChatInterfaze — in-repo LangChain chat model (#5)#12
Abhinavexist merged 3 commits into
mainfrom
feat/langchain-chatinterfaze

Conversation

@Abhinavexist

@AbhinavexistAbhinavexist commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Addresse #5

An optional interfaze[langchain] extra shipping ChatInterfaze (subclass of langchain_openai.ChatOpenAI, targeting langchain-openai ≥1.3.5). It fixes the gaps the issue documents in the stock ChatOpenAI(base_url=...) fallback:

Gap (issue #5)Fix
Custom response fields (precontext/reasoning/vcache) silently droppedOverride _create_chat_result + _convert_chunk_to_generation_chunk to copy them onto response_metadata + additional_kwargs (non-stream and stream)
Request-side precontext only via raw extra_bodyTyped precontext field injected into extra_body in _get_request_payload (merges, doesn't clobber a caller's extra_body)
{"type":"video",...} blocks raise ValueErrorRewrite video blocks (url / base64 / file_id) to Interfaze's file part before the stock converter sees them
Inline <think>/<precontext> tags not strippedStrip via the SDK's strip_side_channels (only when a tag is actually present, to preserve chunk whitespace)

Defaults base_url/model to Interfaze and resolves api_key from INTERFAZE_API_KEY. Not imported from the package root — the core SDK stays langchain-free; importing interfaze.langchain without the extra raises a clear InterfazeError.

Scope

Per the chosen approach this is the in-repo subclass, not the separately published langchain-interfaze package (which the issue's strategic recommendation describes). No PyPI release; ships as an optional extra with mocked unit tests.

Tests

12 new (tests/test_langchain.py, guarded by importorskip): defaults + override, key resolution, custom fields surfaced (sync/stream/async), request precontext injected/omitted, video url + base64 → file part, streaming tag-strip. Suite: 36 passing; ruff + mypy --strict clean; import smoke test passes.

Known limitations (flagged, out of scope)

  • ChatOpenAI renames max_tokensmax_completion_tokens — resolved by interfaze#218 (deploying): now honored server-side as an alias, no longer a silent no-op.
  • Video rewrite covers the langchain-core 1.x VideoContentBlock (url/base64/file_id), not the v0 source_type/data shape.
  • Streaming tag-strip is per-chunk (whole-tag-in-chunk); the native stream().text_deltas() helper (Streamed <precontext>/<think> tags leak to live consumers #4) handles cross-chunk splits.

@Khurdhula-HarshavardhanKhurdhula-Harshavardhan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please help resolve the following.

Comment threadsrc/interfaze/langchain.py

@Khurdhula-HarshavardhanKhurdhula-Harshavardhan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please help resolve the following.

Comment threadsrc/interfaze/langchain.py
Comment threadsrc/interfaze/langchain.py
Add an in-repo langchain-openai chat model (optional interfaze[langchain]
extra) that fixes the ChatOpenAI(base_url=...) fallback gaps:
- surfaces Interfaze's custom response fields (precontext/reasoning/vcache)
on response_metadata + additional_kwargs (non-stream and stream paths)
- injects request-side precontext via extra_body
- accepts {"type":"video",...} content blocks by rewriting them to a file
part before the stock converter rejects them
- strips inline <think>/<precontext> tags from content
Not imported from the package root, so the core SDK stays langchain-free.
Ships as an optional extra with mocked unit tests.
…E (review #12)
- _stream/_astream now filter <think>/<precontext> statefully across chunk
boundaries (_SideChannelFilter) and recover reasoning/precontext from the full
accumulation at stream-end, instead of the per-chunk strip that dropped split tags.
- _convert_video_block forwards mime_type as file.format (else server sees octet-stream).
@Abhinavexist
Abhinavexistforce-pushed the feat/langchain-chatinterfaze branch from 65bab7c to 7f22448CompareJuly 21, 2026 00:57
…ow_subclassing_any + warn_return_any) (review #12)
@Abhinavexist
Abhinavexist merged commit 05ca033 into mainJul 22, 2026
@Abhinavexist
Abhinavexist deleted the feat/langchain-chatinterfaze branch July 22, 2026 19:52
Sign up for freeto 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.

2 participants

@Abhinavexist@Khurdhula-Harshavardhan