LangChain

satya - 1/22/2024, 4:35:54 PM

Langchain docs

Langchain docs

satya - 2/5/2024, 3:23:12 PM

Had to be coming back to it at some point

Had to be coming back to it at some point

satya - 2/5/2024, 3:50:27 PM

LLM Chains API

LLM Chains API

satya - 2/5/2024, 4:35:33 PM

Source code in github for HuggingFaceEndpoint

Source code in github for HuggingFaceEndpoint

satya - 2/6/2024, 11:54:32 AM

Here is the real API for LangChain

Here is the real API for LangChain

satya - 2/6/2024, 12:10:46 PM

How do I navigate the LLMResult object in Langchaing LLMs?

How do I navigate the LLMResult object in Langchaing LLMs?

Search for: How do I navigate the LLMResult object in Langchaing LLMs?

satya - 2/6/2024, 12:19:01 PM

What is pydanticparser and how to use it in langchain?

What is pydanticparser and how to use it in langchain?

Search for: What is pydanticparser and how to use it in langchain?

satya - 2/6/2024, 12:30:48 PM

So here is the sample code


import hfdriver as aiutils
import baselog as log

from langchain_community.chat_models import ChatHuggingFace

#This import is important
#This allows pylance to recognize the type in this sentence
from langchain_community.llms.huggingface_endpoint import HuggingFaceEndpoint

from langchain_core.outputs.llm_result import LLMResult

def getAHfLLM(token, endpoint):
    hf_ep = HuggingFaceEndpoint(
        endpoint_url=endpoint,
        huggingfacehub_api_token=token,
        task="text-generation"
    )
    return hf_ep

def getASampleHFEndPoint() -> HuggingFaceEndpoint:
    token = aiutils.getAPIKey()
    ep_url = aiutils.getSampleHFEndPoint()
    return getAHfLLM(token,ep_url)

def testEndPoint():
    llm = getASampleHFEndPoint()
    #Expects a list of strings
    reply =  llm.generate(["Are roses red?"])
    log.ph("Reply from LLM", f"{reply}")
    log.ph("Json from there", reply.json())
    getSingleTextFromHFEndPointReply(reply)
   
def getSingleTextFromHFEndPointReply(reply: LLMResult):
    output = reply.flatten()
    firstResult = output[0]
    log.ph("First", firstResult)
    firstGenList = firstResult.generations[0]
    log.ph("First Gen List", firstGenList)
    firstGen = firstGenList[0]
    log.ph("First Gen", firstGen)
    text = firstGen.text
    log.ph("First Gen text", text)
    return text


def localTest():
    log.ph1("Starting local test")
    testEndPoint()
    log.ph1("End local test")

if __name__ == '__main__':
    localTest()

satya - 2/6/2024, 12:34:34 PM

Output

Reply from LLM

***********************

generations=[[Generation(text="\n\nAre violets blue?\n\nIs love a game we play?\n\nOr is it something true?\n\nThese questions and more\n\nAre asked by love's devotees\n\nAs they seek to understand\n\nThe mysteries of love's decree\n\nIs love a force of nature?\n\nOr is it something we choose?\n\nIs it a flame that burns brightly,\n\nOr a gentle breeze that softly blows")]] llm_output=None run=[RunInfo(run_id=UUID('4e877cff-b330-4bb0-acef-437ac0d655bf'))]

Json from there

***********************

{"generations": [[{"text": "\n\nAre violets blue?\n\nIs love a game we play?\n\nOr is it something true?\n\nThese questions and more\n\nAre asked by love's devotees\n\nAs they seek to understand\n\nThe mysteries of love's decree\n\nIs love a force of nature?\n\nOr is it something we choose?\n\nIs it a flame that burns brightly,\n\nOr a gentle breeze that softly blows", "generation_info": null, "type": "Generation"}]], "llm_output": null, "run": [{"run_id": "4e877cff-b330-4bb0-acef-437ac0d655bf"}]}

First

***********************

generations=[[Generation(text="\n\nAre violets blue?\n\nIs love a game we play?\n\nOr is it something true?\n\nThese questions and more\n\nAre asked by love's devotees\n\nAs they seek to understand\n\nThe mysteries of love's decree\n\nIs love a force of nature?\n\nOr is it something we choose?\n\nIs it a flame that burns brightly,\n\nOr a gentle breeze that softly blows")]] llm_output=None run=None

First Gen List

***********************

[Generation(text="\n\nAre violets blue?\n\nIs love a game we play?\n\nOr is it something true?\n\nThese questions and more\n\nAre asked by love's devotees\n\nAs they seek to understand\n\nThe mysteries of love's decree\n\nIs love a force of nature?\n\nOr is it something we choose?\n\nIs it a flame that burns brightly,\n\nOr a gentle breeze that softly blows")]

First Gen

***********************

text="\n\nAre violets blue?\n\nIs love a game we play?\n\nOr is it something true?\n\nThese questions and more\n\nAre asked by love's devotees\n\nAs they seek to understand\n\nThe mysteries of love's decree\n\nIs love a force of nature?\n\nOr is it something we choose?\n\nIs it a flame that burns brightly,\n\nOr a gentle breeze that softly blows"

satya - 2/6/2024, 12:35:17 PM

And the final reply extracted


First Gen text
***********************


Are violets blue?

Is love a game we play?

Or is it something true?

These questions and more

Are asked by love's devotees

As they seek to understand

The mysteries of love's decree

Is love a force of nature?

Or is it something we choose?

Is it a flame that burns brightly,

Or a gentle breeze that softly blows

satya - 2/6/2024, 7:19:26 PM

Guides, Custom LLMs

Guides, Custom LLMs

satya - 2/8/2024, 12:04:29 PM

Chroma docs on Langchaing

Chroma docs on Langchaing

satya - 2/8/2024, 12:14:00 PM

Chroma wrapper basics at langchain

Chroma wrapper basics at langchain

satya - 2/8/2024, 12:19:22 PM

Pathway to chroa

  1. Docs
  2. Integrations
  3. Components
  4. Vector stores
  5. Chroma

satya - 2/8/2024, 5:20:24 PM

Creating custom embeddings in Langchain

Creating custom embeddings in Langchain

Search for: Creating custom embeddings in Langchain

satya - 2/8/2024, 5:21:16 PM

Text embedding models are documented here

Text embedding models are documented here

satya - 2/8/2024, 5:22:46 PM

All of the available embedding models are explained here individually

All of the available embedding models are explained here individually

satya - 2/8/2024, 5:23:45 PM

This is under

  1. docs
  2. integrations
  3. text-embedding

satya - 2/8/2024, 5:25:16 PM

Sentence transformers are here

Sentence transformers are here

satya - 2/8/2024, 5:37:49 PM

Here is Langchain base class source code: Embeddings: langchain_core/embeddings.py

Here is Langchain base class source code: Embeddings: langchain_core/embeddings.py

satya - 2/8/2024, 5:38:14 PM

Other derived classes are here

Other derived classes are here

satya - 2/8/2024, 5:38:59 PM

Sample embedder: hugging face local

Sample embedder: hugging face local

satya - 2/8/2024, 5:39:18 PM

Langchain openai embedder

Langchain openai embedder

satya - 2/8/2024, 5:39:33 PM

Fast Embedder

Fast Embedder

satya - 2/8/2024, 5:40:05 PM

Fake embedder

Fake embedder

satya - 2/8/2024, 5:42:22 PM

Core undrestanding: Get started with hugging face embeddings using an API

Core undrestanding: Get started with hugging face embeddings using an API

satya - 2/8/2024, 5:42:52 PM

Core understanding: OpenAI api embeddings

Core understanding: OpenAI api embeddings

satya - 2/8/2024, 5:43:39 PM

Core undestanding: Chromadb embeddings

Core undestanding: Chromadb embeddings

satya - 2/9/2024, 10:29:59 AM

More on embedding models: sbert.net

More on embedding models: sbert.net

satya - 2/9/2024, 10:32:38 AM

You will find here

  1. something called sbert.net
  2. various pre-trained models
  3. from sentence_transformers import SentenceTransformer
  4. Various models with their perf metrics
  5. Semantic search
  6. multi-qa models
  7. Multi-lingual models
  8. Image and text
  9. ...and more

satya - 2/10/2024, 9:49:11 PM

Chroma as a database is documented here

Chroma as a database is documented here

satya - 2/10/2024, 9:53:17 PM

you will find here

  1. Under: docs/components/vector stores/chroma
  2. install
  3. store
  4. split
  5. Creating a Chroma db using a collection from Chromadb native
  6. Making Chroma a server
  7. Update and delete data
  8. Retrievers
  9. Similarity search
  10. Metadata filtering

satya - 2/10/2024, 9:54:29 PM

How do I know if a langchain vectordatabase created or exists?

How do I know if a langchain vectordatabase created or exists?

Search for: How do I know if a langchain vectordatabase created or exists?

satya - 2/10/2024, 9:56:50 PM

VectorStore base class in github

VectorStore base class in github

satya - 2/10/2024, 9:58:58 PM

Chroma source code

Chroma source code

satya - 2/11/2024, 8:41:34 AM

LangChain ai powered chat: question and answers

LangChain ai powered chat: question and answers

satya - 2/14/2024, 6:38:46 PM

Some standard imports

  1. from langchain.chains import LLMChain
  2. from langchain.prompts import PromptTemplate
  3. from vectorlib.database import DatabaseRepo
  4. from vectorlib.database import Database
  5. from langchain_core.vectorstores import VectorStore
  6. from langchain_core.runnables import RunnablePassthrough
  7. from langchain_core.output_parsers import StrOutputParser
  8. from langchain_core.language_models.llms import LLM