Skip to content

Commit e89c738

Browse files
fix: add support in Agent to fix ollama
1 parent 732ec1e commit e89c738

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/lfx/src/lfx/_assets/component_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/lfx/src/lfx/components/ollama/ollama.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class ChatOllamaComponent(LCModelComponent):
101101
info="Refer to https://ollama.com/library for more models.",
102102
refresh_button=True,
103103
real_time_refresh=True,
104+
required=True,
104105
),
105106
SecretStrInput(
106107
name="api_key",
@@ -125,6 +126,7 @@ class ChatOllamaComponent(LCModelComponent):
125126
advanced=False,
126127
table_schema=TABLE_SCHEMA,
127128
value=default_table_row,
129+
show=False,
128130
),
129131
DictInput(name="metadata", display_name="Metadata", info="Metadata to add to the run trace.", advanced=True),
130132
DropdownInput(
@@ -215,6 +217,14 @@ class ChatOllamaComponent(LCModelComponent):
215217
MessageTextInput(
216218
name="template", display_name="Template", info="Template to use for generating text.", advanced=True
217219
),
220+
BoolInput(
221+
name="enable_structured_output",
222+
display_name="Enable Structured Output",
223+
info="Whether to enable structured output in the model.",
224+
value=False,
225+
advanced=True,
226+
real_time_refresh=True,
227+
),
218228
*LCModelComponent.get_base_inputs(),
219229
]
220230

@@ -254,7 +264,7 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var]
254264
)
255265

256266
try:
257-
output_format = self._parse_format_field(self.format)
267+
output_format = self._parse_format_field(self.format) if self.enable_structured_output else None
258268
except Exception as e:
259269
msg = f"Failed to parse the format field: {e}"
260270
raise ValueError(msg) from e
@@ -264,7 +274,7 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var]
264274
"base_url": transformed_base_url,
265275
"model": self.model_name,
266276
"mirostat": mirostat_value,
267-
"format": output_format,
277+
"format": output_format or None,
268278
"metadata": self.metadata,
269279
"tags": self.tags.split(",") if self.tags else None,
270280
"mirostat_eta": mirostat_eta,
@@ -319,6 +329,13 @@ async def is_valid_ollama_url(self, url: str) -> bool:
319329
return False
320330

321331
async def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None):
332+
if field_name == "enable_structured_output":
333+
if field_value:
334+
build_config["format"]["show"] = True
335+
else:
336+
build_config["format"]["show"] = False
337+
return build_config
338+
322339
if field_name == "mirostat":
323340
if field_value == "Disabled":
324341
build_config["mirostat_eta"]["advanced"] = True

0 commit comments

Comments
 (0)