Cleanlab Trustworthy Language Model¶
This notebook shows how to use Cleanlab's Trustworthy Language Model (TLM). TLM is a more reliable LLM that gives high-quality outputs and indicates when it is unsure of the answer to a question, making it suitable for applications where unchecked hallucinations are a show-stopper.
Read more about TLM API on Cleanlab Studio's docs. Feel free to refer to the quickstart tutorial for more advanced usage.
Visit https://cleanlab.ai and sign up to get an API key.
Setup¶
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
In [ ]:
Copied!
%pip install llama-index-llms-cleanlab
%pip install llama-index-llms-cleanlab
In [ ]:
Copied!
%pip install llama-index
%pip install llama-index
In [ ]:
Copied!
from llama_index.llms.cleanlab import CleanlabTLM
from llama_index.llms.cleanlab import CleanlabTLM
In [ ]:
Copied!
# set api key in env or in llm
# import os
# os.environ["CLEANLAB_API_KEY"] = "your api key"
llm = CleanlabTLM(api_key="your_api_key")
# set api key in env or in llm
# import os
# os.environ["CLEANLAB_API_KEY"] = "your api key"
llm = CleanlabTLM(api_key="your_api_key")
In [ ]:
Copied!
resp = llm.complete("Who is Paul Graham?")
resp = llm.complete("Who is Paul Graham?")
In [ ]:
Copied!
print(resp)
print(resp)
Paul Graham is a British-born computer scientist, venture capitalist, and essayist. He is best known for co-founding the startup incubator and investment firm, Y Combinator, which has provided funding and support to numerous successful tech startups including Dropbox, Airbnb, and Reddit. Before founding Y Combinator, Graham was a successful entrepreneur himself, having co-founded the company Viaweb in 1995, which was later acquired by Yahoo in 1998. Graham is also known for his essays on startups, technology, and programming, which have been widely read and influential in the tech industry. In addition to his work in the tech industry, Graham has a background in artificial intelligence and computer science, having earned a Ph.D. in computer science from Harvard University. He is also a prolific essayist and has written several books, including "Hackers & Painters" and "The Hundred-Year Lie: How to Prevent Corporate Abuse and Save the World from Its Own Worst Appetites."
Streaming¶
Using stream_complete
endpoint
In [ ]:
Copied!
response = llm.stream_complete("Who is Paul Graham?")
response = llm.stream_complete("Who is Paul Graham?")
In [ ]:
Copied!
for r in response:
print(r.delta, end="")
for r in response:
print(r.delta, end="")
Paul Graham is a British-born computer scientist, entrepreneur, venture capitalist, and essayist. He is best known for co-founding the startup incubator and investment firm, Y Combinator, which has provided funding and support to numerous successful startups including Dropbox, Airbnb, and Reddit. Before founding Y Combinator, Graham was a successful entrepreneur himself, having co-founded the company Viaweb in 1995, which was later acquired by Yahoo in 1998. Graham is also known for his essays on startups, technology, and programming, which have been widely read and influential in the tech industry. In addition to his work in the tech industry, Graham has a background in computer science and artificial intelligence, having earned a PhD in this field from Harvard University. He has also taught programming and entrepreneurship at several universities, including Harvard and Stanford.