feat(model): add scripted chat model for tests - #1161
Open
March-77 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
feat
Check the PR title.
<type>(optional scope): <description>.(Optional) Translate the PR title into Chinese.
feat(model): 添加面向单元测试的可脚本化 ChatModel
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Eino users currently need to implement BaseChatModel manually or depend on gomock to test multi-turn agents and graphs. The generated mock under
internal/is intentionally unavailable to downstream applications.This PR adds a dependency-free
components/model/modeltestpackage with:OnTurn;OnPromptmatchers;LastUserMessageandLastToolMessageName;WithToolsderivation implementingmodel.ToolCallingChatModel;User impact: applications can unit-test ChatModelAgent, ReAct, and graph behavior without provider credentials, network calls, gomock setup, or handwritten model stubs.
Compatibility/risk: this is an additive package with no changes to existing interfaces or implementations. Each scripted expectation is consumed once, making missing or unexpected calls fail deterministically.
Validation:
go test ./components/model/modeltest -count=1(pass)go test -race ./components/model/modeltest -count=1(pass)go test ./... -count=1(pass)go vet ./...(pass)gofmt -sandgit diff --check(pass)golangci-lintcould not start because its first-time v2.12.2 download repeatedly stalled ongithub.com/MirrexOne/unqueryvet; both attempts were stopped after no progress.zh(optional):
新增无外部依赖的可脚本化 ChatModel,支持按轮次或 Prompt 匹配响应、流式分片、工具调用、错误响应、调用历史及不可变工具绑定,供下游 Agent 和 Graph 单元测试直接使用。
(Optional) Which issue(s) this PR fixes:
Fixes #1029
(optional) The PR that updates user documentation:
N/A