feat: add single-call action protocol and Android stage interfaces
This commit is contained in:
@@ -27,17 +27,20 @@ class LLMProvider:
|
||||
verified_local = (self.base_url == 'http://127.0.0.1:8888/v1'
|
||||
and self.model == 'qwen3.8-27b'
|
||||
and self.template_kwargs == {'enable_thinking': False})
|
||||
self.expression_prepare = verified_local and env.get('LAN_LLM_EXPRESSION_PREPARE', '1') == '1'
|
||||
self.structured_output = env.get('LAN_LLM_STRUCTURED_OUTPUT',
|
||||
'json_schema' if verified_local else 'prompt')
|
||||
self.expression_prepare = self.expression_prepare and self.structured_output == 'json_schema'
|
||||
if self.structured_output not in ('prompt', 'json_schema'):
|
||||
raise ValueError('invalid LLM structured output mode')
|
||||
|
||||
def request(self, messages, *, max_tokens=64):
|
||||
def request(self, messages, *, max_tokens=64, action_plan=False):
|
||||
body = {'model': self.model, 'messages': self.clock.messages(messages), 'max_tokens': max_tokens, 'temperature': 0.3, 'stream': True}
|
||||
if self.template_kwargs:
|
||||
body['chat_template_kwargs'] = self.template_kwargs
|
||||
if self.structured_output == 'json_schema':
|
||||
from action_reply import ACTION_SCHEMA
|
||||
body['response_format'] = {'type': 'json_schema', 'json_schema': {
|
||||
'name': 'role_reply', 'strict': True, 'schema': deepcopy(REPLY_SCHEMA)}}
|
||||
'name': 'role_reply', 'strict': True, 'schema': deepcopy(ACTION_SCHEMA if action_plan else REPLY_SCHEMA)}}
|
||||
headers = {'Authorization': 'Bearer ' + self.api_key} if self.api_key else {}
|
||||
return self.base_url + '/chat/completions', headers, body
|
||||
|
||||
Reference in New Issue
Block a user