mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-04-29 03:50:04 +00:00
rename model_name to model_id
This commit is contained in:
parent
af315a0bab
commit
c65bf8ba12
7 changed files with 40 additions and 35 deletions
|
|
@ -9,36 +9,41 @@ from open_notebook.utils import token_count
|
|||
|
||||
def run_pattern(
|
||||
pattern_name: str,
|
||||
model_name=None,
|
||||
model_id=None,
|
||||
messages=[],
|
||||
state: dict = {},
|
||||
parser=None,
|
||||
output_fixing_model_name=None,
|
||||
output_fixing_model_id=None,
|
||||
) -> dict:
|
||||
system_prompt = Prompter(prompt_template=pattern_name, parser=parser).render(
|
||||
data=state
|
||||
)
|
||||
|
||||
tokens = token_count(str(system_prompt) + str(messages))
|
||||
if tokens > 105_000 and DEFAULT_MODELS.large_context_model:
|
||||
model_name = DEFAULT_MODELS.large_context_model
|
||||
logger.debug(
|
||||
f"Using large context model ({model_name}) because the content has {tokens} tokens"
|
||||
)
|
||||
logger.warning(system_prompt)
|
||||
elif tokens > 105_000 and not DEFAULT_MODELS.large_context_model:
|
||||
logger.critical(
|
||||
f"Content has {tokens} tokens, but no large context model is configured"
|
||||
)
|
||||
elif not model_name:
|
||||
model_name = DEFAULT_MODELS.default_transformation_model
|
||||
|
||||
chain = get_model(model_name, model_type="language")
|
||||
model_id = (
|
||||
DEFAULT_MODELS.large_context_model
|
||||
or DEFAULT_MODELS.default_transformation_model
|
||||
or DEFAULT_MODELS.default_chat_model
|
||||
)
|
||||
if tokens > 105_000:
|
||||
model_id = DEFAULT_MODELS.large_context_model
|
||||
logger.debug(
|
||||
f"Using large context model ({model_id}) because the content has {tokens} tokens"
|
||||
)
|
||||
|
||||
model_id = (
|
||||
model_id
|
||||
or DEFAULT_MODELS.default_transformation_model
|
||||
or DEFAULT_MODELS.default_chat_model
|
||||
)
|
||||
|
||||
chain = get_model(model_id, model_type="language")
|
||||
if parser:
|
||||
chain = chain | parser
|
||||
|
||||
if output_fixing_model_name and parser:
|
||||
output_fix_model = get_model(output_fixing_model_name, model_type="language")
|
||||
if output_fixing_model_id and parser:
|
||||
output_fix_model = get_model(output_fixing_model_id, model_type="language")
|
||||
chain = chain | OutputFixingParser.from_llm(
|
||||
parser=parser,
|
||||
llm=output_fix_model,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue