-
Notifications
You must be signed in to change notification settings - Fork 63
feat: add required fileds #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca7f0d1
93d579e
b15a315
3d20289
fa46565
05a42b1
17beda1
efd780e
d3dbf55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,32 +247,38 @@ def generate_llm_config_dataframe(llm_list): | |
|
|
||
| def suggest_fields_dataframe(rule_list, llm_list): | ||
| """Suggest required field mappings based on selected evaluators""" | ||
| from dingo.io.input import RequiredField | ||
|
|
||
| suggested_fields = set() | ||
|
|
||
| # Fields required by rule evaluators | ||
| rule_type_mapping = get_rule_type_mapping() | ||
| data_column_mapping = get_data_column_mapping() | ||
| # Get rule and llm name maps | ||
| rule_name_map = Model.get_rule_name_map() | ||
| llm_name_map = Model.get_llm_name_map() | ||
|
|
||
| # Fields required by rule evaluators | ||
| for rule in rule_list: | ||
| # Find which type this rule belongs to | ||
| for rule_type, rules in rule_type_mapping.items(): | ||
| if rule in rules: | ||
| if rule_type in data_column_mapping: | ||
| suggested_fields.update(data_column_mapping[rule_type]) | ||
| break | ||
| if rule in rule_name_map: | ||
| rule_class = rule_name_map[rule] | ||
| if hasattr(rule_class, '_required_fields'): | ||
| for field in rule_class._required_fields: | ||
| if isinstance(field, RequiredField): | ||
| suggested_fields.add(field.value) | ||
|
|
||
| # Fields required by LLM evaluators | ||
| llm_column_mapping = get_llm_column_mapping() | ||
| for llm in llm_list: | ||
| if llm in llm_column_mapping: | ||
| suggested_fields.update(llm_column_mapping[llm]) | ||
|
|
||
| # Generate suggested fields rows | ||
| if llm in llm_name_map: | ||
| llm_class = llm_name_map[llm] | ||
| if hasattr(llm_class, '_required_fields'): | ||
| for field in llm_class._required_fields: | ||
| if isinstance(field, RequiredField): | ||
| suggested_fields.add(field.value) | ||
|
Comment on lines
259
to
+274
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for iterating through |
||
|
|
||
| # Generate suggested fields rows - Required Field and Dataset Column both with same value | ||
| rows = [] | ||
| for field in sorted(suggested_fields): | ||
| rows.append([field, field]) | ||
|
|
||
| return gr.update(value=rows if rows else [["content", "content"]]) | ||
| return gr.update(value=rows) | ||
|
|
||
|
|
||
| def get_rule_type_mapping(): | ||
|
|
@@ -405,11 +411,11 @@ def get_data_column_mapping(): | |
| # Field mapping configuration | ||
| gr.Markdown("**EvalPipline.fields** - Field Mapping") | ||
| fields_dataframe = gr.Dataframe( | ||
| value=[["content", "content"]], | ||
| headers=["Field Key", "Dataset Column"], | ||
| value=[], | ||
| headers=["Required Field", "Dataset Column"], | ||
| datatype=["str", "str"], | ||
| column_count=(2, "fixed"), | ||
| row_count=(1, "dynamic"), | ||
| row_count=(0, "dynamic"), | ||
| label="Field Mappings (add/remove rows as needed)", | ||
| interactive=True | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from dingo.io.input.data import Data # noqa E402. | ||
| from dingo.io.input.required_field import RequiredField # noqa E402. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class RequiredField(Enum): | ||
| CONTENT = "content" | ||
| PROMPT = "prompt" | ||
| CONTEXT = "context" | ||
| IMAGE = "image" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |||||
|
|
||||||
| from pydantic import Field | ||||||
|
|
||||||
| from dingo.io.input import RequiredField | ||||||
| from dingo.model.llm.agent.tools.base_tool import BaseTool, ToolConfig | ||||||
| from dingo.model.llm.agent.tools.tool_registry import tool_register | ||||||
| from dingo.utils import log | ||||||
|
|
@@ -76,6 +77,8 @@ class TavilySearch(BaseTool): | |||||
| description = "Search the web for factual information using Tavily AI" | ||||||
| config: TavilyConfig = TavilyConfig() | ||||||
|
|
||||||
| _required_fields = [RequiredField.IMAGE] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def execute(cls, query: str, **kwargs) -> Dict[str, Any]: | ||||||
| """ | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| import json | ||||||
| from typing import List | ||||||
|
|
||||||
| from dingo.io.input import Data | ||||||
| from dingo.io.input import Data, RequiredField | ||||||
| from dingo.io.output.eval_detail import EvalDetail | ||||||
| from dingo.model import Model | ||||||
| from dingo.model.llm.base_openai import BaseOpenAI | ||||||
|
|
@@ -20,6 +20,7 @@ class LLMClassifyQR(BaseOpenAI): | |||||
| "evaluation_results": "" | ||||||
| } | ||||||
|
|
||||||
| _required_fields = [RequiredField.CONTENT] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This model classifies images, but
Suggested change
|
||||||
| prompt = """ | ||||||
| 'Classify the image into one of the following categories: "CAPTCHA", "QR code", or "Normal image". ' | ||||||
| 'Return the type as the image category (CAPTCHA or QR code or Normal image) and the reason as the specific type of CAPTCHA or QR code. ' | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import
from dingo.io.input import RequiredFieldis located inside thesuggest_fields_dataframefunction. According to PEP 8, imports should be at the top of the file. This also avoids the overhead of re-importing the module on every function call.