Usage & Code Examples
LLaMA-3.2
Memory
Rag
Temperature uses
Validated_schema
CodeLLaMA-Instruct 7B
Gemma-2-Instruct 9B
Mistral 7B Instruct
Qwen-2.5-Coder 7B
Phi-3 Medium (8B)
Falcon 7B Instruct
Baichuan-2-7B
InternLM-Chat-7B
Vicuna 7B
### Python ###
# Install if not already
pip install npmai
# Basic usage
from npmai import Ollama
llm = Ollama(
model="llama3.2",
temperature=0.5
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"llama3.2\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "llama3.2";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"llama3.2\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
#Memory(Memory is only in npmai library which is on python)
from npmai import Ollama,Memory
llm = Ollama(
model="internlm:7b",
temperature=0.5
)
memory=Memory(
"unique_file_name"
)
memory_prompt=load_memory_variables()
prompts=f"{memory_prompt} Hello my name is sonu kumar how are you"
result= llm.invoke(prompts)
save_context(prompts,result)
print(result)
#Rag
from npmai import Rag
rag=Rag(
files="file_name",
query="Any question you want to ask if you will ask here you must provide DB_PATH,Model_name",
DB_PATH="Any random name this name will save you file",
temperature=0.5 or any other,
model="qwen2.5-coder:7b"
)
response=rag.send()
print(response)
#If you want just conversion of file content into text then just do this:-
from npmai import Rag
rag=Rag(
files="file_name",
)
response=rag.send()
print(response)
#Whatever file are there just send.
### For other languages scroll down you will get that at API Acess section ###
### Python ###
# Using temperature
from npmai import Ollama
llm = Ollama(
model="llama3.2",
temperature=0.5 # here passs your temperature parameter
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"internlm:7b\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "internlm:7b";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"internlm:7b\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
# Validated Schemas
from npmai import Ollama
llm = Ollama(
model="llama3.2",
temperature=0.7,
validate_schema=#Here pass yor schema
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Python ###
# CodeLLaMA-Instruct 7B
from npmai import Ollama
llm = Ollama(
model="codellama:7b-instruct",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"codellama:7b-instruct\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "codellama:7b-instruct";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"codellama:7b-instruct\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Gemma-2-Instruct 9B
from npmai import Ollama
llm = Ollama(
model="gemma2:9b",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"gemma2:9b\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "gemma2:9b";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"gemma2:9b\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Mistral 7B Instruct
from npmai import Ollama
llm = Ollama(
model="mistral:7b",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"mistral:7b\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "mistral:7b";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"mistral:7b\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Qwen-2.5-Coder 7B
from npmai import Ollama
llm = Ollama(
model="qwen2.5-coder:7b",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"qwen2.5-coder:7b\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "qwen2.5-coder:7b";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"qwen2.5-coder:7b\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Phi-3 Medium (8B)
from npmai import Ollama
llm = Ollama(
model="phi3:medium",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"phi3:medium\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "phi3:medium";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"phi3:medium\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Falcon 7B Instruct
from npmai import Ollama
llm = Ollama(
model="falcon:7b-instruct",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"falcon:7b-instruct\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "falcon:7b-instruct";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"falcon:7b-instruct\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Baichuan-2 (example)
from npmai import Ollama
llm = Ollama(
model="maxkb/baichuan2:13b-chat",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"maxkb/baichuan2:13b-chat\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "maxkb/baichuan2:13b-chat";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"maxkb/baichuan2:13b-chat\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ##
# InternLM-Chat-7B
from npmai import Ollama
llm = Ollama(
model="internlm2:7b",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"internlm2:7b\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "internlm2:7b";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"internlm2:7b\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### Python ###
# Vicuna 7B
from npmai import Ollama
llm = Ollama(
model="vicuna:7b",
temperature=0.7
)
prompts = "Hello, tell me a short summary of NPMAI"
result = llm.invoke(prompts)
print(result)
### Java ###
import java.net.URI;
import java.net.http.*;
public class Main {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"model\": \"vicuna:7b\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://npmai-api.onrender.com/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
### C++ ###
#include
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
nlohmann::json j;
j["prompt"] = "Hello world";
j["model"] = "vicuna:7b";
j["temperature"] = 0.3;
std::string request_body = j.dump();
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_body.c_str());
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
### C ###
#include
#include
int main() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char *json = "{\"prompt\": \"Hello world\", \"model\": \"vicuna:7b\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://npmai-api.onrender.com/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
API Access
Use NPMAI without installing the package via our Render API:
https://npm-api.onrender.com/llm
Use NPMAI Huggingface endpoint to use LLMs:
Llama3.2
https://sonuramashish22028704-npmai.hf.space/llm
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-npmai.hf.space/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-npmai.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-npmai.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-npmai.hf.space/llm"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
gemma2:9b
https://sonuramashish22028704-vicuna7b.hf.space/gemma
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-vicuna7b.hf.space/gemma"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-vicuna7b.hf.space/gemma");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-vicuna7b.hf.space/gemma");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-vicuna7b.hf.space/gemma"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
codellama:7b-instruct
https://sonuramashish22028704-falcon7binstruct.hf.space/codellama
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-falcon7binstruct.hf.space/codellama"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-falcon7binstruct.hf.space/codellama");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-falcon7binstruct.hf.space/codellama");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-falcon7binstruct.hf.space/codellama"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
mistral:7b
https://sonuramashish22028704-mistral7b.hf.space/llm
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-mistral7b.hf.space/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-mistral7b.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-mistral7b.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-mistral7b.hf.space/llm"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
qwen2.5-coder:7b
https://sonuramashish22028704-npmai.hf.space/qwen
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-npmai.hf.space/qwen"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-npmai.hf.space/qwen");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-npmai.hf.space/qwen");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-npmai.hf.space/qwen"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
phi3:medium
https://sonuramashish22028704-phi3medium.hf.space/llm
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-phi3medium.hf.space/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-phi3medium.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-phi3medium.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-phi3medium.hf.space/llm"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
falcon:7b-instruct
https://sonuramashish22028704-falcon7binstruct.hf.space/llm
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-falcon7binstruct.hf.space/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-falcon7binstruct.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-falcon7binstruct.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-falcon7binstruct.hf.space/llm"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
maxkb/baichuan2:13b-chat
https://sonuramashish22028704-internlm27b.hf.space/baichuan
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-internlm27b.hf.space/baichuan"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-internlm27b.hf.space/baichuan");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-internlm27b.hf.space/baichuan");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-internlm27b.hf.space/baichuan"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
internlm2:7b
https://sonuramashish22028704-internlm27b.hf.space/llm
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-internlm27b.hf.space/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-internlm27b.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-internlm27b.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-internlm27b.hf.space/llm"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
vicuna:7b
https://sonuramashish22028704-vicuna7b.hf.space/llm
Examples using different langauges:-
Java
import java.net.URI;
import java.net.http.*;
public class HFClient {
public static void main(String[] args) throws Exception {
var client = HttpClient.newHttpClient();
String json = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://sonuramashish22028704-vicuna7b.hf.space/llm"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
C++
#include
#include
int main() {
CURL* curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
const char* data = "{\"prompt\": \"Hello world\", \"temperature\": 0.3}";
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-vicuna7b.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
C
#include
#include
int main(void) {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-vicuna7b.hf.space/llm");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"prompt\": \"Hello world\", \"temperature\": 0.3}");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Java-Script
async function callHuggingFace() {
const api_url = "https://sonuramashish22028704-vicuna7b.hf.space/llm"; // Direct HF API link
const payload = {
prompt: "Hello world",
temperature: 0.3
};
try {
const response = await fetch(api_url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
console.log(data.response);
} catch (err) {
console.error("Failed:", err);
}
}
NPMAI RAG API FRAMEWORK
https://sonuramashish22028704-npmeduai.hf.space/ingestion
Examples using different languages:-
### Java ###
import java.net.http.*;
import java.nio.file.Paths;
public Map send() throws Exception {
String HF_API = "https://sonuramashish22028704-npmeduai.hf.space/ingestion";
// Using a library like Apache HttpComponents or OkHttp is recommended for Multipart
// Below is a conceptual OkHttp implementation
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(600, TimeUnit.SECONDS)
.build();
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("query", this.query)
.addFormDataPart("DB_PATH", this.db_path)
.addFormDataPart("temperature", String.valueOf(this.temperature))
.addFormDataPart("model", this.model)
.addFormDataPart("file", "filename",
RequestBody.create(new File(this.files), MediaType.parse("application/octet-stream")))
.build();
Request request = new Request.Builder().url(HF_API).post(requestBody).build();
try (Response response = client.newCall(request).execute()) {
JSONObject json = new JSONObject(response.body().string());
return Map.of("response", json.get("response"));
}
}
### C++ ###
#include
void send() {
CURL *curl = curl_easy_init();
if(curl) {
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "query", CURLFORM_COPYCONTENTS, query.c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "DB_PATH", CURLFORM_COPYCONTENTS, db_path.c_str(), CURLFORM_END);
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, files.c_str(), CURLFORM_END);
// ... add other fields ...
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-npmeduai.hf.space/ingestion");
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 600L);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formpost);
}
}
### C ###
#include
#include
void send_request(const char* file_path, const char* query) {
CURL *curl;
CURLcode res;
curl_mime *mime;
curl_mimepart *part;
curl = curl_easy_init();
if(curl) {
mime = curl_mime_init(curl);
// Text field
part = curl_mime_addpart(mime);
curl_mime_name(part, "query");
curl_mime_data(part, query, CURL_ZERO_TERMINATED);
// File field
part = curl_mime_addpart(mime);
curl_mime_name(part, "file");
curl_mime_filedata(part, file_path);
curl_easy_setopt(curl, CURLOPT_URL, "https://sonuramashish22028704-npmeduai.hf.space/ingestion");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 600L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_mime_free(mime);
}
}
### Java-Script
async function send() {
const HF_API = "https://sonuramashish22028704-npmeduai.hf.space";
// 1. Prepare Multipart Data
const formData = new FormData();
formData.append("query", this.query);
formData.append("DB_PATH", this.db_path);
formData.append("temperature", this.temperature);
formData.append("model", this.model);
// For Node.js, use: formData.append("file", await fs.openAsBlob(this.files));
formData.append("file", this.files);
// 2. Setup Timeout (600 seconds)
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 600000);
try {
const res = await fetch(HF_API, {
method: "POST",
body: formData,
signal: controller.signal
// Note: DO NOT manually set 'Content-Type'; fetch does this automatically for FormData
});
clearTimeout(timeoutId); // Clean up timer
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
const data = await res.json();
return { response: data.response };
} catch (error) {
if (error.name === 'AbortError') {
return { error: "Request timed out after 600 seconds" };
}
return { error: error.message };
}
}