fix: 修复 to_dict list 类型丢失与 OpenAI stop 参数失效
- to_dict() 增加 list 类型序列化支持,metrics 等字段不再丢失 - OpenAIHandler 补充 get_stop_sequences/on_token,读取 request.stop 并检测停止序列 - 文档类图补充缺失字段、修正关系分类、ChatCompletionRequest 字段增加 Optional
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
__version__ = "1.3.5"
|
||||
__version__ = "1.3.6"
|
||||
__author__ = "ViperEkura"
|
||||
|
||||
from astrai.config import (
|
||||
|
||||
@@ -11,7 +11,6 @@ __all__ = [
|
||||
"BaseModelConfig",
|
||||
"AutoRegressiveLMConfig",
|
||||
"EncoderConfig",
|
||||
"ModelConfig",
|
||||
"ConfigFactory",
|
||||
"TrainConfig",
|
||||
]
|
||||
|
||||
@@ -13,7 +13,7 @@ class BaseConfig:
|
||||
d[fld.name] = v
|
||||
elif v is None:
|
||||
d[fld.name] = None
|
||||
elif isinstance(v, dict):
|
||||
elif isinstance(v, (dict, list)):
|
||||
try:
|
||||
json.dumps(v)
|
||||
d[fld.name] = v
|
||||
|
||||
@@ -226,6 +226,17 @@ class OpenAIHandler(ProtocolHandler):
|
||||
def create_response_id(self) -> str:
|
||||
return f"chatcmpl-{uuid.uuid4().hex[:12]}"
|
||||
|
||||
def get_stop_sequences(self) -> List[str]:
|
||||
stop = self.request.stop
|
||||
if stop is None:
|
||||
return []
|
||||
return [stop] if isinstance(stop, str) else stop
|
||||
|
||||
def on_token(
|
||||
self, ctx: StreamContext, token: str, stop_checker: StopChecker
|
||||
) -> Optional[str]:
|
||||
return stop_checker.check(ctx.accumulated)
|
||||
|
||||
def format_stream_start(self, ctx: StreamContext) -> List[str]:
|
||||
return [
|
||||
_sse_event(
|
||||
|
||||
Reference in New Issue
Block a user