Skip to main content

LlamaIndex Llms Integration: Friendli

Installation

  1. Install the required Python packages:

    %pip install llama-index-llms-friendli
    !pip install llama-index
    
  2. Set the Friendli token as an environment variable:

    %env FRIENDLI_TOKEN=your_token_here
    

Usage

Basic Chat

To generate a chat response, use the following code:

from llama_index.llms.friendli import Friendli
from llama_index.core.llms import ChatMessage, MessageRole

llm = Friendli()

message = ChatMessage(role=MessageRole.USER, content="Tell me a joke.")
resp = llm.chat([message])
print(resp)

Streaming Responses

To stream chat responses in real-time:

resp = llm.stream_chat([message])
for r in resp:
    print(r.delta, end="")

Asynchronous Chat

For asynchronous chat interactions, use the following:

resp = await llm.achat([message])
print(resp)

Async Streaming

To handle async streaming of chat responses:

resp = await llm.astream_chat([message])
async for r in resp:
    print(r.delta, end="")

Complete with a Prompt

To generate a completion based on a prompt:

prompt = "Draft a cover letter for a role in software engineering."
resp = llm.complete(prompt)
print(resp)

Streaming Completion

To stream completions in real-time:

resp = llm.stream_complete(prompt)
for r in resp:
    print(r.delta, end="")

Async Completion

To handle async completions:

resp = await llm.acomplete(prompt)
print(resp)

Async Streaming Completion

For async streaming of completions:

resp = await llm.astream_complete(prompt)
async for r in resp:
    print(r.delta, end="")

Model Configuration

To configure a specific model:

llm = Friendli(model="llama-2-70b-chat")
resp = llm.chat([message])
print(resp)

LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/friendli/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_llms_friendli-0.6.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_llms_friendli-0.6.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_friendli-0.6.0.tar.gz.

File metadata

  • Download URL: llama_index_llms_friendli-0.6.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_friendli-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5941fb60fbf4022b0f39218e7de4a7ac498c352ec8981102e09e45dc766b6f06
MD5 cc6a35ec6381cfae69f319009b655d85
BLAKE2b-256 bdc5feba947f8d3c9e3915c9fb67096fe9eea06fe981ea805e5f09d729b04dae

See more details on using hashes here.

File details

Details for the file llama_index_llms_friendli-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_friendli-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_friendli-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cc5ef155cdbec74ff051def2c1d5be05caed2a6d51ff1cf14f8a4afad25b6ac
MD5 354a8a041278a83db4e24a4dd27c1b01
BLAKE2b-256 80224a38fe742ac9ae885fcd356c1f85de9c59323e50f4d659832d3d26724308

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page