Skip to content

Instantly share code, notes, and snippets.

@ljnmedium
ljnmedium / alex_key_feature.md
Created September 28, 2023 09:34
alex_key_feature.md
API access solution - 3rd party model. On-premise solution - open source model.
R&D developpement The low initial cost, both in terms of time and money, allows us to quickly reach a Minimum Viable Product (MVP). The procedure for model parameter optimization and MLops is overseen by a third-party e
@ljnmedium
ljnmedium / providers_llm.md
Last active September 28, 2023 09:43
providers_llm.md
Provider Model Cost for input Cost for output Cost per request.
OpenAI text-davinci-004 $0.03/ 1K tokens $0.06/ 1K tokens 0
OpenAI text-davinci-003 $0.02/ 1K tokens $0.02/ 1K tokens 0
OpenAI text-davinci-002 $0.002/ 1K tokens $0.002/ 1K tokens 0
OpenAI gpt-3.5-turbo $0.002/ 1K tokens $0.002/ 1K tokens 0
[Cohere](https://cohere.com/pri
@ljnmedium
ljnmedium / llm_size.md
Created September 28, 2023 09:45
llm_size.md
Provider Model Number of parameters
Meta with Microsoft LLama 2 7B, 13B, 32B, 65.2B
Meta LLama 7B, 13B, 70B
Technology Innovation Institute of UAE Flacon LLM 7B, 40B
Stanford’s CRFM Alpaca 7B
Google Plan-T5 80M, 250M, 780M, 3B, 11B
MPT MosaicML 7B, 30B
@ljnmedium
ljnmedium / table_qa_models.md
Created September 29, 2023 07:23
table_qa_models.md
Direct query

Information appearing in text (entity extraction, summarization, find relevant paragraphs, etc … ).
Indirect query
Inferenced information (mathematical calculation, comparison, conclusion, etc …).
Simple text
Text containing descriptions excluding table.
Complexity: +
Accuracy: +++
Complexity: ++
Accuracy: +++
Complex textText
@ljnmedium
ljnmedium / pinecone_setup.py
Created September 29, 2023 07:28
pinecone_setup.py
pinecone.init(api_key="YOUR_API_KEY", environment="YOUR_ENVIRONMENT")
index = pinecone.Index("projet_esg")
@ljnmedium
ljnmedium / managing_index.py
Created September 29, 2023 07:29
managing_index.py
index.describe_index_stats()
@ljnmedium
ljnmedium / add_data.py
Created September 29, 2023 07:29
add_data.py
values = embedd_model.encode([b['content'] for b in batch])
sparse_values = sparsed_model.encode([b['content'] for b in batch])
# Create unique IDs
ids = [str(b['metadata']['id']) for b in batch]
# Add all to upsert list
to_upsert = [{'id': i, 'values': v, 'metadata':m , 'sparse_values': sv} for (i,v,m,sv) in zip(ids,values, metas, sparse_values)]
# Upsert/insert these records to pinecone
@ljnmedium
ljnmedium / index_describe.py
Created September 29, 2023 07:30
index_describe.py
index.describe_index_stats()
# Return for example:
{
'dimension': 1536,
'index_fullness': 0.1,
'namespaces': {
'Eiffage': {'vector_count': 344},
'total_vector_count': 344
}
@ljnmedium
ljnmedium / refactoring_1.py
Created September 29, 2023 07:32
refactoring_1.py
from openai import Embedding
from pinecone_text.sparse import BM25Encoder
EMBEDDING_MODEL = "text-embedding-ada-002"
SPARSE_MODEL_FILE_NAME = "bm25_values.json"
class Embedding_Model(Embedding):
def __init__(self, model_name):
self.engine = model_name
@ljnmedium
ljnmedium / refactoring_2.py
Created September 29, 2023 07:34
refactoring_2.py
from pinecone import Index
class Retreiver(Index):
def __init__(self, index_name, embedd_openai_model, sparse_model_file_name, dimension=1536, metric="dotproduct"):
self.index_name = index_name
# Create index
if index_name not in pinecone.list_indexes():