Spaces:
Running
Running
Carry actual user feature requirements into Llama synthesis
Browse files- public_agent.py +8 -4
public_agent.py
CHANGED
|
@@ -105,9 +105,10 @@ def llm_features(task,n=4,token=None,requirements=""):
|
|
| 105 |
base,key=credentials(token)
|
| 106 |
prompt=f'''{sm.to_prompt(task)}
|
| 107 |
Propose {n} feature programs for {DATA[task]['name']} risk prediction.
|
| 108 |
-
User feature requirements: {requirements}
|
|
|
|
| 109 |
Use only declared c0/c1/c2/c3 columns. Never use entity_id or labels.
|
| 110 |
-
Format: [{{"name":"snake_case","path":["{task}"],"agg":"none","expr":"c0","window_days":null,"rationale":"한국어 근거"}}].
|
| 111 |
These are snapshots with no time history. agg must be none and window_days null.
|
| 112 |
Include relevant source columns and optionally defensible arithmetic expressions if requested. No fictitious time aggregations or units. JSON object with programs array only.'''
|
| 113 |
schema={'type':'object','properties':{'programs':{'type':'array','minItems':1,'maxItems':n,'items':{'type':'object','properties':{'name':{'type':'string'},'path':{'type':'array','items':{'type':'string','enum':[task]},'minItems':1,'maxItems':1},'agg':{'type':'string','enum':['none']},'expr':{'type':'string'},'window_days':{'type':'null'},'rationale':{'type':'string'}},'required':['name','path','agg','expr','window_days','rationale'],'additionalProperties':False}}},'required':['programs'],'additionalProperties':False}
|
|
@@ -151,7 +152,7 @@ def propose_features(ctx:RunContextWrapper,task:str,n:int=4,requirements:str='',
|
|
| 151 |
"""Use the LLM to synthesize feature programs, then validate against the ontology. task: churn|stockout|defect, n:1-8. summary: Korean status."""
|
| 152 |
def run():
|
| 153 |
if not 1<=n<=8:raise ValueError('n must be 1-8')
|
| 154 |
-
result=llm_features(task,n,ctx.context.id,requirements);ctx.context.proposals[task]=result;return result
|
| 155 |
return observe(ctx,'propose_features',run)
|
| 156 |
|
| 157 |
|
|
@@ -236,7 +237,10 @@ class PublicSession(SessionRuntime):
|
|
| 236 |
steps=STEPS
|
| 237 |
own_tools=set(STEPS)
|
| 238 |
def __init__(self):
|
| 239 |
-
super().__init__();self.proposals={};self.features={};self.runs={};self.model_requests={};self.touched=time.monotonic()
|
|
|
|
|
|
|
|
|
|
| 240 |
def _agent(self,mcp_servers=()):
|
| 241 |
base,key=credentials(self.id)
|
| 242 |
return Agent(name='ONTIC',instructions=SYSTEM_PROMPT+'\n'+DEPLOYMENT_NOTES,tools=TOOLS,model_settings=ModelSettings(parallel_tool_calls=False),model=OpenAIChatCompletionsModel(model=MODEL,openai_client=AsyncOpenAI(base_url=base,api_key=key,timeout=120,max_retries=0)))
|
|
|
|
| 105 |
base,key=credentials(token)
|
| 106 |
prompt=f'''{sm.to_prompt(task)}
|
| 107 |
Propose {n} feature programs for {DATA[task]['name']} risk prediction.
|
| 108 |
+
User feature requirements (must follow; n is a maximum): {requirements}
|
| 109 |
+
When the user names specific columns, use ONLY those columns and do not add others. Resolve their exact Korean source names through the semantic model descriptions. Ignore entity identifiers and labels.
|
| 110 |
Use only declared c0/c1/c2/c3 columns. Never use entity_id or labels.
|
| 111 |
+
Format: {{"programs":[{{"name":"snake_case","path":["{task}"],"agg":"none","expr":"c0","window_days":null,"rationale":"한국어 근거"}}]}}.
|
| 112 |
These are snapshots with no time history. agg must be none and window_days null.
|
| 113 |
Include relevant source columns and optionally defensible arithmetic expressions if requested. No fictitious time aggregations or units. JSON object with programs array only.'''
|
| 114 |
schema={'type':'object','properties':{'programs':{'type':'array','minItems':1,'maxItems':n,'items':{'type':'object','properties':{'name':{'type':'string'},'path':{'type':'array','items':{'type':'string','enum':[task]},'minItems':1,'maxItems':1},'agg':{'type':'string','enum':['none']},'expr':{'type':'string'},'window_days':{'type':'null'},'rationale':{'type':'string'}},'required':['name','path','agg','expr','window_days','rationale'],'additionalProperties':False}}},'required':['programs'],'additionalProperties':False}
|
|
|
|
| 152 |
"""Use the LLM to synthesize feature programs, then validate against the ontology. task: churn|stockout|defect, n:1-8. summary: Korean status."""
|
| 153 |
def run():
|
| 154 |
if not 1<=n<=8:raise ValueError('n must be 1-8')
|
| 155 |
+
result=llm_features(task,n,ctx.context.id,requirements or ctx.context.request_text);ctx.context.proposals[task]=result;return result
|
| 156 |
return observe(ctx,'propose_features',run)
|
| 157 |
|
| 158 |
|
|
|
|
| 237 |
steps=STEPS
|
| 238 |
own_tools=set(STEPS)
|
| 239 |
def __init__(self):
|
| 240 |
+
super().__init__();self.request_text='';self.proposals={};self.features={};self.runs={};self.model_requests={};self.touched=time.monotonic()
|
| 241 |
+
def send(self,text):
|
| 242 |
+
self.request_text=text
|
| 243 |
+
return super().send(text)
|
| 244 |
def _agent(self,mcp_servers=()):
|
| 245 |
base,key=credentials(self.id)
|
| 246 |
return Agent(name='ONTIC',instructions=SYSTEM_PROMPT+'\n'+DEPLOYMENT_NOTES,tools=TOOLS,model_settings=ModelSettings(parallel_tool_calls=False),model=OpenAIChatCompletionsModel(model=MODEL,openai_client=AsyncOpenAI(base_url=base,api_key=key,timeout=120,max_retries=0)))
|