LangChain
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, 4:35:33 PM
Source code in github for HuggingFaceEndpoint
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/8/2024, 12:19:22 PM
Pathway to chroa
satya - 2/8/2024, 5:20:24 PM
Creating custom embeddings in Langchain
Creating custom embeddings in Langchain
satya - 2/8/2024, 5:21:16 PM
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
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:59 PM
Sample embedder: hugging face local
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
satya - 2/8/2024, 5:43:39 PM
Core undestanding: Chromadb embeddings
satya - 2/9/2024, 10:29:59 AM
More on embedding models: sbert.net
satya - 2/9/2024, 10:32:38 AM
You will find here
satya - 2/10/2024, 9:49:11 PM
Chroma as a database is documented here
satya - 2/10/2024, 9:53:17 PM
you will find here
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/11/2024, 8:41:34 AM
LangChain ai powered chat: question and answers
satya - 2/14/2024, 6:38:46 PM
Some standard imports