Skip to main content

llama-index llms novita integration

Project description

LlamaIndex Llms Integration: NovitaAI

Installation

%pip install llama-index-llms-novita

Select Model

Large Language Models: https://novita.ai/llm-api?utm_source=github_llama_index&utm_medium=github_readme&utm_campaign=link

Basic usage

# Import NovitaAI
from llama_index.llms.novita import NovitaAI

# Set your API key
api_key = "Your API KEY"

# Call complete function
response = NovitaAI(
    model="meta-llama/llama-3.1-8b-instruct", api_key=api_key
).complete("who are you")
print(response)

# Call complete with stop
response = NovitaAI(
    model="meta-llama/llama-3.1-8b-instruct", api_key=api_key
).complete(prompt="who are you", stop=["AI"])
print(response)

# Call chat with a list of messages
from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="user", content="who are you"),
]

response = NovitaAI(
    model="meta-llama/llama-3.1-8b-instruct", api_key=api_key
).chat(messages)
print(response)

Streaming: Using stream endpoint

from llama_index.llms.novita import NovitaAI

# Set your API key
api_key = "Your API KEY"

llm = NovitaAI(model="meta-llama/llama-3.1-8b-instruct", api_key=api_key)

# Using stream_complete endpoint
response = llm.stream_complete("who are you")
for r in response:
    print(r.delta, end="")

# Using stream_chat endpoint
messages = [
    ChatMessage(role="user", content="who are you"),
]

response = llm.stream_chat(messages)
for r in response:
    print(r.delta, end="")

Function Calling

from datetime import datetime
from llama_index.core.tools import FunctionTool
from llama_index.llms.novita import NovitaAI

# Set your API key
api_key = "Your API KEY"


def get_current_time() -> dict:
    """Get the current time"""
    return {"time": datetime.now().strftime("%Y-%m-%d %H:%M:%S")}


llm = NovitaAI(model="deepseek/deepseek_v3", api_key=api_key)
tool = FunctionTool.from_defaults(fn=get_current_time)
response = llm.predict_and_call([tool], "What is the current time?")
print(response)

NovitaAI Documentation

API Documentation: https://novita.ai/docs/guides/llm-api

Project details


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_novita-0.2.1.tar.gz (5.3 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_novita-0.2.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_novita-0.2.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_llms_novita-0.2.1.tar.gz
Algorithm Hash digest
SHA256 23a7ce0c94f91dd194e87a3c1a4f10caf33318e3e8912e2f687ae19465a0b600
MD5 f009e2262332f251c1595c922fa78927
BLAKE2b-256 a52ab81a814b45a76ee5436279c7495131317a0976dd6595f516038e0b1f2fb8

See more details on using hashes here.

File details

Details for the file llama_index_llms_novita-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_llms_novita-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e1498ecc00d4c1d5dab266d9d9ecbe7d86d87cdbce167a322074cee59e5e8387
MD5 2682b6c871f837d06cb16c455165a69b
BLAKE2b-256 e09964f2a846838e134c1931ba828913ead7e44aa79a5566613015bd51ef35f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page