mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-17 22:05:53 +08:00
feat: support json_schema for ollama models (#11449)
This commit is contained in:
parent
1ce51e57ab
commit
7e1184c071
@ -181,9 +181,11 @@ class OllamaLargeLanguageModel(LargeLanguageModel):
|
|||||||
# prepare the payload for a simple ping to the model
|
# prepare the payload for a simple ping to the model
|
||||||
data = {"model": model, "stream": stream}
|
data = {"model": model, "stream": stream}
|
||||||
|
|
||||||
if "format" in model_parameters:
|
if format_schema := model_parameters.pop("format", None):
|
||||||
data["format"] = model_parameters["format"]
|
try:
|
||||||
del model_parameters["format"]
|
data["format"] = format_schema if format_schema == "json" else json.loads(format_schema)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
raise InvokeBadRequestError(f"Invalid format schema: {str(e)}")
|
||||||
|
|
||||||
if "keep_alive" in model_parameters:
|
if "keep_alive" in model_parameters:
|
||||||
data["keep_alive"] = model_parameters["keep_alive"]
|
data["keep_alive"] = model_parameters["keep_alive"]
|
||||||
@ -733,12 +735,12 @@ class OllamaLargeLanguageModel(LargeLanguageModel):
|
|||||||
ParameterRule(
|
ParameterRule(
|
||||||
name="format",
|
name="format",
|
||||||
label=I18nObject(en_US="Format", zh_Hans="返回格式"),
|
label=I18nObject(en_US="Format", zh_Hans="返回格式"),
|
||||||
type=ParameterType.STRING,
|
type=ParameterType.TEXT,
|
||||||
|
default="json",
|
||||||
help=I18nObject(
|
help=I18nObject(
|
||||||
en_US="the format to return a response in. Currently the only accepted value is json.",
|
en_US="the format to return a response in. Format can be `json` or a JSON schema.",
|
||||||
zh_Hans="返回响应的格式。目前唯一接受的值是json。",
|
zh_Hans="返回响应的格式。目前接受的值是字符串`json`或JSON schema.",
|
||||||
),
|
),
|
||||||
options=["json"],
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
pricing=PriceConfig(
|
pricing=PriceConfig(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user