大语言模型(LLM)
大语言模型(LLM)
微调模型
内置模型
点击 市场/模型
查看 算场 Data+AI 平台
的 模型市场
中包括的各类别基础模型和大语言模型在内的诸多模型:
- 包括分类、分割、OCR、异常检测、时序预测等诸多基础模型;
- 包括
Llama3系列
、Qwen系列
等开源大语言模型和bge
、gte
等embedding
模型;
外部模型
创建外部模型服务
您可以创建 模型在线服务
时选择 外部模型
,指定 Secret Key
调用平台支持的外部模型服务。
自定义外部模型
您可以通过 mlflow
记录符合 OPENAI
风格的外部模型服务作为自定义外部模型,下列例子中演示了如何自定义记录 Qwen-max
、Deepseek-Chat
等外部模型服务。
无生成参数
import os
os.environ["OPENAI_API_BASE"] = "<你的 OPENAI API BASE URL>"
os.environ["OPENAI_API_KEY"] = "<你的 OPENAI API KEY>"
model_name = "<模型名称>"
import mlflow
import pandas as pd
import openai
experiment_name = "LLM-Tuturials"
mlflow.set_experiment(experiment_name)
with mlflow.start_run():
info = mlflow.openai.log_model(
model=model_name,
task=openai.chat.completions,
messages=[
{"role": "user", "content": "讲一个关于{animal}的笑话."}
],
artifact_path="model",
)
model = mlflow.pyfunc.load_model(info.model_uri)
df = pd.DataFrame({"animal": ["猫", "狗"]})
print(model.predict(df))
输出
['有一天,一只猫走进了一家酒吧。\n\n酒保问:“你要喝点什么?”\n\n猫回答:“给我来杯牛奶吧。”\n\n酒保笑了笑,说:“我们这里不卖牛奶。”\n\n猫想了想,说:“那给我来杯水吧,我渴了。”\n\n酒保又笑了笑,说:“我们这里也不卖水。”\n\n猫有点不耐烦了,问:“那你们这里卖什么?”\n\n酒保回答:“我们这里卖酒。”\n\n猫听了,摇了摇头,说:“那我还是去别的地方吧,我可不想喝醉了,回家被主人骂。”\n\n说完,猫转身就走了。\n\n酒保看着猫的背影,笑着说:“真是一只聪明的猫!”', '当然可以!这是一个关于狗的笑话:\n\n有一天,一只狗走进了一家酒吧。酒保看到它,惊讶地问:“嘿,你来这里干什么?”\n\n狗从嘴里吐出一张纸条,上面写着:“我听说这里有好喝的啤酒。”\n\n酒保笑了笑,说:“好吧,但我不能给你啤酒,不过我可以给你一杯水。”\n\n狗点点头,喝完了水,然后又吐出一张纸条,上面写着:“谢谢,但我其实是来找工作的。”\n\n酒保愣了一下,然后说:“哦,那你有什么技能?”\n\n狗立刻站起来,用后腿走路,还表演了一段小小的舞蹈。\n\n酒保看得目瞪口呆,说:“哇,你真厉害!不过我们这里不需要会跳舞的狗。”\n\n狗又吐出一张纸条,上面写着:“那你们需要会开门的狗吗?”\n\n酒保想了想,说:“嗯,我们确实需要一个能开门的员工。”\n\n于是,狗得到了这份工作。每天晚上,它都会准时来上班,用嘴打开酒吧的门,迎接客人。\n\n有一天,一个客人问酒保:“那只狗真的会开门吗?”\n\n酒保笑着说:“当然会!不过,它只会开自己的门。”\n\n客人一脸疑惑:“什么意思?”\n\n酒保解释道:“它只会开狗屋的门。”\n\n客人哈哈大笑:“那它怎么上班的?”\n\n酒保耸耸肩:“它每天早上都从狗屋里出来,然后直接走进酒吧。”\n\n希望你喜欢这个笑话!😄']
设置生成参数
import os
os.environ["OPENAI_API_BASE"] = "<你的 OPENAI API BASE URL>"
os.environ["OPENAI_API_KEY"] = "<你的 OPENAI API KEY>"
model_name = "<模型名称>"
import openai
import pandas as pd
from IPython.display import HTML
import mlflow
from mlflow.models.signature import ModelSignature
from mlflow.types.schema import ColSpec, ParamSchema, ParamSpec, Schema
lyrics_prompt = (
"Here's a misheard lyric: {lyric}. What's the actual lyric, which song does it come from, which artist performed it, and can you give a funny "
"explanation as to why the misheard version doesn't make sense? Also, rate the creativity of the lyric on a scale of 1 to 3, where 3 is good."
)
# 创建实验
mlflow.set_experiment("Lyrics Corrector")
# 记录模型
with mlflow.start_run():
model_info = mlflow.openai.log_model(
model=model_name,
task=openai.chat.completions,
artifact_path="model",
prompt=lyrics_prompt,
signature=ModelSignature(
inputs=Schema([ColSpec(type="string", name=None)]),
outputs=Schema([ColSpec(type="string", name=None)]),
params=ParamSchema(
[
ParamSpec(name="max_tokens", default=16, dtype="long"),
ParamSpec(name="temperature", default=0, dtype="float"),
ParamSpec(name="best_of", default=1, dtype="long"),
]
),
),
)
# 以 Python 函数形式加载模型
model = mlflow.pyfunc.load_model(model_info.model_uri)
# 测试用例
bad_lyrics = pd.DataFrame(
{
"lyric": [
"We built this city on sausage rolls",
"Hold me closer, Tony Danza",
"Sweet dreams are made of cheese. Who am I to dis a brie? I cheddar the world and a feta cheese",
"Excuse me while I kiss this guy",
"I want to rock and roll all night and part of every day",
"Don't roam out tonight, it's bound to take your sight, there's a bathroom on the right.",
"I think you'll understand, when I say that somethin', I want to take your land",
]
}
)
fix_my_lyrics = model.predict(bad_lyrics, params={"max_tokens": 500, "temperature": 0})
formatted_output = "<br>".join(
[f"<p><strong>{line.strip()}</strong></p>" for line in fix_my_lyrics]
)
HTML(formatted_output)
输出
That's a fun and creative twist on the classic song "We Built This City" by Starship! If you're imagining a city built on sausage rolls, it might look something like this: - **Skyscrapers**: Towering structures made entirely of stacked sausage rolls, with windows made of mustard or ketchup bottles. - **Roads**: Paved with layers of pastry, leading to various districts like the "Meat Market" or the "Cheese District." - **Parks**: Green spaces filled with lettuce gardens and tomato patches, with benches made of sliced bread.
...