Feat llm http request modifier #26
Open
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.
Summary
oxy.HttpLLM增加llm_request_modifier的Hook,提供在请求LLM前对headers、url、payload进行自定义修改的能力,应用在例如“headers中增加traceId来提供错误排查、payload中增加stream参数来指定流式返回”,目前应用在调用一些大模型网关的场景,适配该网关定制化的接入方式。
Related Issue(s)
Changes
http_llm.py中,对HttpLLM的class增加llm_request_modifier声明,提供实例化过程中的自定义扩展,在httpx.AsyncClient执行发送请求的逻辑前执行llm_request_modifier,传入headers、url、payload,处理完完整返回headers、url、payload;
对历史逻辑没有影响,在不配置llm_request_modifier的情况下,保持原本headers、url、payload的输出;
示例
Checklist