docs/examples/llm/friendli.ipynb
<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/friendli.ipynb" target="_parent"></a>
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
%pip install llama-index-llms-friendli
!pip install llama-index
%env FRIENDLI_TOKEN=...
from llama_index.llms.friendli import Friendli
# To customize your friendli token, do this
# otherwise it will lookup FRIENDLI_TOKEN from your env variable
# llm = Friendli(friendli_token="Your personal access token")
llm = Friendli()
chat with a list of messagesfrom llama_index.core.llms import ChatMessage, MessageRole
message = ChatMessage(role=MessageRole.USER, content="Tell me a joke.")
resp = llm.chat([message])
print(resp)
resp = llm.stream_chat([message])
for r in resp:
print(r.delta, end="")
resp = await llm.achat([message])
print(resp)
resp = await llm.astream_chat([message])
async for r in resp:
print(r.delta, end="")
complete with a promptprompt = "Draft a cover letter for a role in software engineering."
resp = llm.complete(prompt)
print(resp)
resp = llm.stream_complete(prompt)
for r in resp:
print(r.delta, end="")
resp = await llm.acomplete(prompt)
print(resp)
resp = await llm.astream_complete(prompt)
async for r in resp:
print(r.delta, end="")
from llama_index.llms.friendli import Friendli
llm = Friendli(model="llama-2-70b-chat")
resp = llm.chat([message])
print(resp)