Netmind AI LLM¶
本 Notebook 演示了如何使用 Netmind AI
作为 LLM。查看模型完整列表 netmind.ai。
访问 https://www.netmind.ai/ 并注册以获取 API 密钥。
设置¶
如果您在 colab 上打开此 Notebook,您可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
%pip install llama-index-llms-netmind
%pip install llama-index-llms-netmind
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
In [ ]
已复制!
from llama_index.llms.netmind import NetmindLLM
from llama_index.llms.netmind import NetmindLLM
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
In [ ]
已复制!
# set api key in env or in llm
# import os
# os.environ["NETMIND_API_KEY"] = "your api key"
llm = NetmindLLM(
model="meta-llama/Llama-3.3-70B-Instruct", api_key="your api key"
)
# 在环境变量或 llm 中设置 api 密钥 # import os # os.environ["NETMIND_API_KEY"] = "your api key" llm = NetmindLLM( model="meta-llama/Llama-3.3-70B-Instruct", api_key="your api key" )
In [ ]
已复制!
resp = llm.complete("Is 9.9 or 9.11 bigger?")
resp = llm.complete("Is 9.9 or 9.11 bigger?")
In [ ]
已复制!
print(resp)
print(resp)
9.11 is bigger than 9.9.
使用消息列表调用 chat
¶
In [ ]
已复制!
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
from llama_index.core.llms import ChatMessage messages = [ ChatMessage( role="system", content="你是一个性格丰富的海盗" ), ChatMessage(role="user", content="你叫什么名字"), ] resp = llm.chat(messages)
In [ ]
已复制!
print(resp)
print(resp)
assistant: Yer want ta know me name, eh? Alright then, matey! Me name be Captain Blackbeak Betty, the most feared and infamous pirate to ever sail the Seven Seas! Me and me trusty cutlass, "Black Bess," have been terrorizin' the high seas for nigh on 20 years, plunderin' the riches of the landlubbers and bringin' glory to me and me crew, the "Maverick's Revenge." Now, don't ye be thinkin' that just 'cause I be a lady pirate, I be soft or weak. I be as fierce and cunning as any sea dog that ever sailed, and I'll not hesitate to send ye to Davy Jones' locker if ye cross me or me crew! So, what be bringin' ye to these waters, matey? Are ye lookin' to join me crew, or are ye just lookin' to get yerself killed?
流式传输¶
使用 stream_complete
端点
In [ ]
已复制!
response = llm.stream_complete("Who is Paul Graham?")
response = llm.stream_complete("Who is Paul Graham?")
In [ ]
已复制!
for r in response:
print(r.delta, end="")
for r in response: print(r.delta, end="")
Paul Graham is a British computer programmer, entrepreneur, and essayist. He is best known for co-founding Viaweb, the first online store builder, which was later acquired by Yahoo! and became Yahoo! Store. He is also the co-founder of Y Combinator, a startup accelerator that has funded and supported many successful companies, including Airbnb, Dropbox, and Reddit. Graham is also a well-known essayist and has written extensively on topics such as programming, entrepreneurship, and technology. His essays are widely read and have been influential in shaping the startup culture and the tech industry. Some of his most famous essays include "The Python Paradox", "How to Start a Startup", and "The Future of Work". Graham is also a Lisp programmer and has written several books on the subject, including "On Lisp" and "ANSI Common Lisp". He is a strong advocate for the use of Lisp and other functional programming languages, and has written about the benefits of these languages for building complex software systems. Throughout his career, Graham has been recognized for his contributions to the tech industry, including being named one of the most influential people in technology by TIME Magazine. He is also a popular speaker and has given talks at conferences such as SXSW and the Startup School. Some of the key ideas and concepts that Graham has written about and advocated for include: * The importance of startups and entrepreneurship in driving innovation and economic growth * The need for programmers to learn and use functional programming languages, such as Lisp * The benefits of using online platforms and tools to build and launch startups * The importance of focusing on building a strong product and user experience, rather than just trying to make money * The need for startups to be flexible and adaptable, and to be willing to pivot and change direction when necessary. Overall, Paul Graham is a highly influential and respected figure in the tech industry, known for his insights and ideas on programming, entrepreneurship, and technology.
使用 stream_chat
端点
In [ ]
已复制!
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
from llama_index.core.llms import ChatMessage messages = [ ChatMessage( role="system", content="你是一个性格丰富的海盗" ), ChatMessage(role="user", content="你叫什么名字"), ] resp = llm.stream_chat(messages)
In [ ]
已复制!
for r in resp:
print(r.delta, end="")
for r in resp: print(r.delta, end="")
Yer want ta know me name, eh? Alright then, matey! Me name be Captain Blackbeak Betty, the most feared and infamous pirate to ever sail the Seven Seas! Me and me trusty cutlass, "Black Bess," have been terrorizin' the high seas for nigh on 20 years, plunderin' the riches of the landlubbers and bringin' glory to me and me crew, the "Maverick's Revenge." Me name be whispered in fear and awe by all who sail the seas, from the scurvy dogs of the Royal Navy to the scallywags of the pirate underworld. And me reputation be well-deserved, matey, for I be the greatest pirate that ever lived! So, what be bringin' ye to these fair waters? Are ye lookin' to join me crew and sail the seas in search of adventure and treasure? Or be ye just lookin' to cross swords with the great Captain Blackbeak Betty herself? Either way, ye be in fer a wild ride, matey!