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.1.0.tar.gz (3.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.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llama_index_llms_novita-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure

File hashes

Hashes for llama_index_llms_novita-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b24e4e6ed62815b593ad1137a76f4cef20e01443a45b5a3df9a65edabb118367
MD5 630ce0ecc8c9a1e7f8291f7be6c9e64b
BLAKE2b-256 fd9584cc7a2c57d15d1185c0a532438480710db39adeadc4eb11dc777f371257

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_llms_novita-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9482ca0bb8adc0ae54a4061f104eab6944bd035c140ddb9ae41a33a35f21cbe
MD5 76baede1b2a525c45c709f401ba7c67c
BLAKE2b-256 264640e0155066dac61f24f69afd7259de6601d6cd3d1ab90b990d12131a8130

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