告别高昂AI成本!用RouteLLM打造智能路由聊天机器人,成本降低85%!性能达到GPT-4的95%!为企业省下一大笔钱!#RouteLLM #llama3 #gemma2 #ollama #ai

AI超元域
5 min readJul 9, 2024

--

🔥🔥🔥本篇笔记所对应的视频 https://youtu.be/uU0dpNzmLgk

RouteLLM 是一个高效的LLM(大型语言模型)路由框架,旨在在优化成本和响应质量之间实现平衡。

RouteLLM: 智能路由让大语言模型更经济实惠

RouteLLM是一个创新的开源框架,旨在优化大语言模型(LLM)的使用成本和性能。它通过智能路由技术,在保持高质量输出的同时显著降低了LLM的使用成本。

背景介绍

我们知道,像GPT-4这样的大语言模型功能强大,但使用成本也很高。而像Mixtral这样的小型模型虽然便宜,但能力有限。那么,有没有办法既能获得高质量的回答,又能控制成本呢?

RouteLLM的创新之处

这就是RouteLLM框架的创新之处。它的核心思想是:对于简单的问题,我们用便宜的小模型;对于复杂的问题,才用昂贵的大模型。

具体来说,RouteLLM会先分析用户的问题,然后决定将其发送给哪个模型。这个过程,我们称之为”路由”。

潜在影响

RouteLLM为大规模部署LLM提供了经济可行的解决方案,有望加速AI技术在各行各业的应用和普及。

RouteLLM代表了AI技术在效率和经济性方面的重要突破,为未来更广泛、更深入的AI应用铺平了道路。

结语

RouteLLM的出现,为我们提供了一种聪明的方法来平衡大语言模型的成本和性能。它让我们能够更经济、更高效地使用这些强大的AI工具。

未来,随着更多人参与到这个开源项目中来,我们有理由相信,RouteLLM会变得更加强大,为AI的普及应用铺平道路。

感谢收看,如果您对RouteLLM感兴趣,欢迎查看他们的GitHub仓库和论文,进一步了解详情。

pip install "routellm[serve,eval]"



export OPENAI_API_KEY="sk-proj-wDPaUDu1I"
export ANYSCALE_API_KEY="secret_r4jh"


#test question
#what is the square root of 1787569?




import os
from routellm.controller import Controller

os.environ["OPENAI_API_KEY"] = "sk-proj-wDPaUDu1Iimxi8SG3BfwT3B5M"
# Replace with your model provider, we use Anyscale's Mixtral here.
os.environ["ANYSCALE_API_KEY"] = "esecret_r4jhxj9jx75mewwt3"

client = Controller(
routers=["mf"],
strong_model="gpt-4-1106-preview",
weak_model="anyscale/mistralai/Mixtral-8x7B-Instruct-v0.1",
)

response = client.chat.completions.create(
# This tells RouteLLM to use the MF router with a cost threshold of 0.11593
model="router-mf-0.11593",
messages=[
{"role": "user", "content": "Hello!"}
]
)

ollama

import os
from routellm.controller import Controller

# 设置 OpenAI API 密钥


client = Controller(
routers=["mf"],
strong_model="gpt-4-1106-preview",
weak_model="ollama_chat/gemma2",
)


response = client.chat.completions.create(
model="router-mf-0.11593",
messages=[
{"role": "user", "content": "Hello!"}
]
)

print(response.choices[0].message.content)

👉👉👉如有问题请联系我的徽信 stoeng

🔥🔥🔥本项目代码由AI超元域频道制作,观看更多大模型微调视频请访问我的频道⬇

👉👉👉我的哔哩哔哩频道

👉👉👉我的YouTube频道

👉👉👉我的开源项目 https://github.com/win4r/AISuperDomain

stream

import os
from routellm.controller import Controller

client = Controller(
routers=["mf"],
strong_model="gpt-4-1106-preview",
weak_model="ollama_chat/gemma2",
)

# 创建流式响应
stream = client.chat.completions.create(
model="router-mf-0.11593",
messages=[
{"role": "user", "content": "who are you?"}
],
stream=True # 启用流式输出
)

# 遍历流并打印每个部分的内容
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end='', flush=True)

# 打印换行符,使下一个提示符出现在新行
print()

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response