Skip to content

Instantly share code, notes, and snippets.

View makispl's full-sized avatar

Plegas Gerasimos makispl

View GitHub Profile
# Set the API Key, either by setting the env var or editing it directly here:
openai_api_key = [YOUR_OPENAI_KEY]
# Create a new prompter using any desired model (GPT-3.5)and add the query_results
prompt_text = "Summarize the criticality provisions"
print (f"\n > Prompting LLM with '{prompt_text}'")
prompter = Prompt().load_model("gpt-3.5-turbo", api_key=openai_api_key)
sources = prompter.add_source_query_results(query_res)
# Prompt the LLM with the sources and query string
embedded_text = ''
for q in query_res:
embedded_text += '\n'.join(q['text'].split("\'\'"))
# check all of the pertinent HuggingFace models for performance
models = ["llmware/bling-1b-0.1",
"llmware/bling-1.4b-0.1",
"llmware/bling-falcon-1b-0.1",
"llmware/bling-cerebras-1.3b-0.1",
# Construct the query
query = 'What is defined as criticality?'
query_res = Query(library).semantic_query(query, result_count=2)
print(query_res)
# Create vector embeddings for the library and store them in Milvus
# Opt for the industry-bert-asset-management model which is trained for our domain
library.install_new_embedding(embedding_model_name="industry-bert-asset-management", vector_db="milvus")
# Create a library and load it with llmware samples
library = Library().create_new_library("Project_lib")
library.add_files([REPLACE_WITH_DOCS_PATH])
# Create a test library and load it with llmware samples
test_library = Library().create_new_library("Agreements")
samples_path = Setup().load_sample_files()
test_library.add_files(os.path.join(samples_path,"Agreements"))
# Create vector embeddings for the library and store them in Milvus
test_library.install_new_embedding(embedding_model_name="industry-bert-contracts", vector_db="milvus")
# Perform a semantic search in the test library
os.environ["TOKENIZERS_PARALLELISM"] = "false" # HuggingFace tokenizer warning to be avoided
# import dependencies
import os
import time
from llmware.library import Library
from llmware.retrieval import Query
from llmware.prompts import Prompt
from llmware.setup import Setup
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose.yaml
docker compose up -d
# Install transformers
pip install transformers
# Install llmware
pip install llmware