Skip to content

Instantly share code, notes, and snippets.

@softaverse
softaverse / llama.cpp-server-test.js
Created May 25, 2024 16:29
test llama.cpp server
const prompt = `Building a website can be done in 10 simple steps:`;
const stream = true;
async function Test() {
let response = await fetch("http://127.0.0.1:8080/completion", {
method: 'POST',
body: JSON.stringify({
prompt,
n_predict: 512,
})
@softaverse
softaverse / llama3-with-langChain.py
Created May 13, 2024 16:16
Llama 3🦙🦙🦙 + llama.cpp + LangChain🦜🔗
import bs4
from langchain import hub
from langchain_community.document_loaders import WebBaseLoader
from langchain_chroma import Chroma
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from langchain_community.embeddings import GPT4AllEmbeddings
from langchain.prompts import PromptTemplate
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.llms import LlamaCpp
@softaverse
softaverse / book.gbnf
Created April 20, 2024 08:05
GBNF for llama 2 - book
root ::= Book
Auther ::= "{" ws "\"firstName\":" ws string "," ws "\"lastName\":" ws string "," ws "\"age\":" ws number "}"
Autherlist ::= "[]" | "[" ws Auther ("," ws Auther)* "]"
Book ::= "{" ws "\"title\":" ws string "," ws "\"subtitle\":" ws string "," ws "\"authers\":" ws Autherlist "," ws "\"genres\":" ws stringlist "," ws "\"pages\":" ws number "," ws "\"description\":" ws string "," ws "\"isbn\":" ws string "}"
Booklist ::= "[]" | "[" ws Book ("," ws Book)* "]"
string ::= "\"" ([^"]*) "\""
boolean ::= "true" | "false"
ws ::= [ \t\n]*
number ::= [0-9]+ "."? [0-9]*
stringlist ::= "[" ws "]" | "[" ws string ("," ws string)* ws "]"
@softaverse
softaverse / weather.gbnf
Created April 20, 2024 08:01
GBNF for llama 2 - weather
root ::= answer
answer ::= (weather | complaint | yesno)
weather ::= ("Sunny." | "Cloudy." | "Rainy.")
complaint ::= "I don't like talking about the weather."
yesno ::= ("Yes." | "No.")
@softaverse
softaverse / car.gbnf
Created April 20, 2024 07:55
GBNF for llama 2 - car
root ::= CarAndOwner
PerformanceFeature ::= "{" ws "\"engine\":" ws string "," ws "\"horsepower\":" ws number "," ws "\"topSpeed\":" ws number "}"
PerformanceFeaturelist ::= "[]" | "[" ws PerformanceFeature ("," ws PerformanceFeature)* "]"
SafetyFeature ::= "{" ws "\"airbags\":" ws number "," ws "\"parkingSensors\":" ws number "," ws "\"laneAssist\":" ws number "}"
SafetyFeaturelist ::= "[]" | "[" ws SafetyFeature ("," ws SafetyFeature)* "]"
AudioFeature ::= "{" ws "\"brand\":" ws string "," ws "\"speakers\":" ws number "," ws "\"hasBluetooth\":" ws boolean "}"
AudioFeaturelist ::= "[]" | "[" ws AudioFeature ("," ws AudioFeature)* "]"
Features ::= "{" ws "\"audio\":" ws AudioFeature "," ws "\"safety\":" ws SafetyFeature "," ws "\"performance\":" ws PerformanceFeature "}"
Featureslist ::= "[]" | "[" ws Features ("," ws Features)* "]"
Owner ::= "
@softaverse
softaverse / list.gbnf
Last active April 20, 2024 07:57
GBNF for llama 2 - list
root ::= item+
item ::= "- " [^\r\n\x0b\x0c\x85\u2028\u2029]+ "\n"
// 具名函式 named function
function foo(name: string) {
return 'foo ' + name;
}
// 函式運算式 function expression
let foo2 = function (name: string) {
return 'foo ' + name;
}
function MyObject(name, message) {
this.name = name.toString();
this.message = message.toString();
}
(function() {
this.getName = function() {
return this.name;
};
this.getMessage = function() {
return this.message;
function MyObject(name, message) {
this.name = name.toString();
this.message = message.toString();
}
MyObject.prototype.getName = function() {
return this.name;
};
MyObject.prototype.getMessage = function() {
return this.message;
};
function MyObject(name, message) {
this.name = name.toString();
this.message = message.toString();
this.getName = function() {
return this.name;
};
this.getMessage = function() {
return this.message;
};