llama-index llms deepinfra integration
Project description
LlamaIndex Llms Integration: DeepInfra
Installation
First, install the necessary package:
pip install llama-index-llms-deepinfra
Initialization
Set up the DeepInfraLLM
class with your API key and desired parameters:
from llama_index.llms.deepinfra import DeepInfraLLM
import asyncio
llm = DeepInfraLLM(
model="mistralai/Mixtral-8x22B-Instruct-v0.1", # Default model name
api_key="your-deepinfra-api-key", # Replace with your DeepInfra API key
temperature=0.5,
max_tokens=50,
additional_kwargs={"top_p": 0.9},
)
Synchronous Complete
Generate a text completion synchronously using the complete
method:
response = llm.complete("Hello World!")
print(response.text)
Synchronous Stream Complete
Generate a streaming text completion synchronously using the stream_complete
method:
content = ""
for completion in llm.stream_complete("Once upon a time"):
content += completion.delta
print(completion.delta, end="")
Synchronous Chat
Generate a chat response synchronously using the chat
method:
from llama_index.core.base.llms.types import ChatMessage
messages = [
ChatMessage(role="user", content="Tell me a joke."),
]
chat_response = llm.chat(messages)
print(chat_response.message.content)
Synchronous Stream Chat
Generate a streaming chat response synchronously using the stream_chat
method:
messages = [
ChatMessage(role="system", content="You are a helpful assistant."),
ChatMessage(role="user", content="Tell me a story."),
]
content = ""
for chat_response in llm.stream_chat(messages):
content += chat_response.message.delta
print(chat_response.message.delta, end="")
Asynchronous Complete
Generate a text completion asynchronously using the acomplete
method:
async def async_complete():
response = await llm.acomplete("Hello Async World!")
print(response.text)
asyncio.run(async_complete())
Asynchronous Stream Complete
Generate a streaming text completion asynchronously using the astream_complete
method:
async def async_stream_complete():
content = ""
response = await llm.astream_complete("Once upon an async time")
async for completion in response:
content += completion.delta
print(completion.delta, end="")
asyncio.run(async_stream_complete())
Asynchronous Chat
Generate a chat response asynchronously using the achat
method:
async def async_chat():
messages = [
ChatMessage(role="user", content="Tell me an async joke."),
]
chat_response = await llm.achat(messages)
print(chat_response.message.content)
asyncio.run(async_chat())
Asynchronous Stream Chat
Generate a streaming chat response asynchronously using the astream_chat
method:
async def async_stream_chat():
messages = [
ChatMessage(role="system", content="You are a helpful assistant."),
ChatMessage(role="user", content="Tell me an async story."),
]
content = ""
response = await llm.astream_chat(messages)
async for chat_response in response:
content += chat_response.message.delta
print(chat_response.message.delta, end="")
asyncio.run(async_stream_chat())
For any questions or feedback, please contact us at feedback@deepinfra.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file llama_index_llms_deepinfra-0.3.0.tar.gz
.
File metadata
- Download URL: llama_index_llms_deepinfra-0.3.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1789644c51b36531f4be262f09580ff9135b51ae5f81e58672718ba8e9e19169 |
|
MD5 | 894491cd00840a3a6487669089d4a927 |
|
BLAKE2b-256 | 8060cbf61a9e1982b92b3c4d9d4c53b646a2685f36e20768e2e643c2748d471f |
File details
Details for the file llama_index_llms_deepinfra-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_llms_deepinfra-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c24d2990ac1cab470c33a1b3e233026dca0775d94d5569e1eeb99aa2ba08004e |
|
MD5 | 5b4c2cecc4fb537777f10bc55fd16ab1 |
|
BLAKE2b-256 | cda5959a906a8c36a84476c2874266b289b01692c6277c0e3712673e8a4d2f63 |