id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
8caafaafb328-139
Try to update ForwardRefs on fields based on this Model, globalns and localns. pydantic model langchain.llms.SelfHostedPipeline[source]# Run model inference on self-hosted remote hardware. Supported hardware includes auto-launched instances on AWS, GCP, Azure, and Lambda, as well as servers specified by IP address and ...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-140
hardware=gpu, model_reqs=["./", "torch", "transformers"], ) Example passing model path for larger models:from langchain.llms import SelfHostedPipeline import runhouse as rh import pickle from transformers import pipeline generator = pipeline(model="gpt2") rh.blob(pickle.dumps(generator), path="models/pipeline.pkl" ...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-141
Run the LLM on the given prompt and input. async agenerate_prompt(prompts: List[langchain.schema.PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]] = None) → langchain.schema.LLMResult# Take in a li...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-142
Returns new model instance dict(**kwargs: Any) → Dict# Return a dictionary of the LLM. classmethod from_pipeline(pipeline: Any, hardware: Any, model_reqs: Optional[List[str]] = None, device: int = 0, **kwargs: Any) → langchain.llms.base.LLM[source]# Init the SelfHostedPipeline from a pipeline object or string. generate...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-143
Get the token present in the text. json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: ...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-144
stochasticai = StochasticAI(api_url="") Validators build_extra » all fields raise_deprecation » all fields set_verbose » verbose validate_environment » all fields field api_url: str = ''# Model name to use. field model_kwargs: Dict[str, Any] [Optional]# Holds any model parameters valid for create call not explicitly sp...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-145
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclu...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-146
Get the number of tokens present in the text. get_num_tokens_from_messages(messages: List[langchain.schema.BaseMessage]) → int# Get the number of tokens in the message. get_token_ids(text: str) → List[int]# Get the token present in the text. json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, ...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-147
Wrapper around Google Vertex AI large language models. Validators raise_deprecation » all fields set_verbose » verbose validate_environment » all fields field credentials: Optional['Credentials'] = None# The default custom credentials to use when making API calls. If not provided field location: str = 'us-central1'# Th...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-148
Run the LLM on the given prompt and input. async agenerate_prompt(prompts: List[langchain.schema.PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]] = None) → langchain.schema.LLMResult# Take in a li...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-149
Returns new model instance dict(**kwargs: Any) → Dict# Return a dictionary of the LLM. generate(prompts: List[str], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]] = None) → langchain.schema.LLMResult# Run the...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-150
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps(). predict(text: str, *, stop: Optional[Sequence[str]] = None) → str# Predict text from text. predict_messages(messages: List[langchain.schema.BaseMessage], *, stop: Optional[Sequence[str]] = None) → langchain.schema...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-151
field model_id: str = 'palmyra-instruct'# Model name to use. field n: Optional[int] = None# How many completions to generate. field presence_penalty: Optional[float] = None# Penalizes repeated tokens regardless of frequency. field repetition_penalty: Optional[float] = None# Penalizes repeated tokens according to freque...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-152
Take in a list of prompt values and return an LLMResult. async apredict(text: str, *, stop: Optional[Sequence[str]] = None) → str# Predict text from text. async apredict_messages(messages: List[langchain.schema.BaseMessage], *, stop: Optional[Sequence[str]] = None) → langchain.schema.BaseMessage# Predict message from m...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-153
Run the LLM on the given prompt and input. generate_prompt(prompts: List[langchain.schema.PromptValue], stop: Optional[List[str]] = None, callbacks: Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]] = None) → langchain.schema.LLMResult# Take in a list of p...
https://python.langchain.com/en/latest/reference/modules/llms.html
8caafaafb328-154
Save the LLM. Parameters file_path – Path to file to save the LLM to. Example: .. code-block:: python llm.save(file_path=”path/llm.yaml”) classmethod update_forward_refs(**localns: Any) → None# Try to update ForwardRefs on fields based on this Model, globalns and localns. previous Writer next Chat Models By Harrison Ch...
https://python.langchain.com/en/latest/reference/modules/llms.html
8ceef0c87e6d-0
.rst .pdf Embeddings Embeddings# Wrappers around embedding modules. pydantic model langchain.embeddings.AlephAlphaAsymmetricSemanticEmbedding[source]# Wrapper for Aleph Alpha’s Asymmetric Embeddings AA provides you with an endpoint to embed a document and a query. The models were optimized to make the embeddings of doc...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-1
embed_documents(texts: List[str]) → List[List[float]][source]# Call out to Aleph Alpha’s asymmetric Document endpoint. Parameters texts – The list of texts to embed. Returns List of embeddings, one for each text. embed_query(text: str) → List[float][source]# Call out to Aleph Alpha’s asymmetric, query embedding endpoin...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-2
Model name to use. field truncate: Optional[str] = None# Truncate embeddings that are too long from start or end (“NONE”|”START”|”END”) embed_documents(texts: List[str]) → List[List[float]][source]# Call out to Cohere’s embedding endpoint. Parameters texts – The list of texts to embed. Returns List of embeddings, one f...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-3
Returns The embedding for the input query text. Return type List[float] classmethod from_credentials(model_id: str, *, es_cloud_id: Optional[str] = None, es_user: Optional[str] = None, es_password: Optional[str] = None, input_field: str = 'text_field') → langchain.embeddings.elasticsearch.ElasticsearchEmbeddings[source...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-4
Embed search docs. embed_query(text: str) → List[float][source]# Embed query text. pydantic model langchain.embeddings.HuggingFaceEmbeddings[source]# Wrapper around sentence_transformers embedding models. To use, you should have the sentence_transformers python package installed. Example from langchain.embeddings impor...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-5
environment variable HUGGINGFACEHUB_API_TOKEN set with your API token, or pass it as a named parameter to the constructor. Example from langchain.embeddings import HuggingFaceHubEmbeddings repo_id = "sentence-transformers/all-mpnet-base-v2" hf = HuggingFaceHubEmbeddings( repo_id=repo_id, task="feature-extractio...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-6
) field cache_folder: Optional[str] = None# Path to store models. Can be also set by SENTENCE_TRANSFORMERS_HOME environment variable. field embed_instruction: str = 'Represent the document for retrieval: '# Instruction to use for embedding documents. field model_kwargs: Dict[str, Any] [Optional]# Key word arguments to ...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-7
Number of tokens to process in parallel. Should be a number between 1 and n_ctx. field n_ctx: int = 512# Token context window. field n_gpu_layers: Optional[int] = None# Number of layers to be loaded into gpu memory. Default None. field n_parts: int = -1# Number of parts to split the model into. If -1, the number of par...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-8
Model name to use. embed_documents(texts: List[str]) → List[List[float]][source]# Compute doc embeddings using a modelscope embedding model. Parameters texts – The list of texts to embed. Returns List of embeddings, one for each text. embed_query(text: str) → List[float][source]# Compute query embeddings using a models...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-9
Parameters texts – The list of texts to embed. Returns List of embeddings, one for each text. embed_query(text: str) → List[float][source]# Embed a query using a MosaicML deployed instructor embedding model. Parameters text – The text to embed. Returns Embeddings for the text. pydantic model langchain.embeddings.OpenAI...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-10
api_type="azure", ) text = "This is a test query." query_result = embeddings.embed_query(text) field chunk_size: int = 1000# Maximum number of texts to embed in each batch field max_retries: int = 6# Maximum number of retries to make when generating. field request_timeout: Optional[Union[float, Tuple[float, float]]] = ...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-11
See: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html field content_handler: langchain.embeddings.sagemaker_endpoint.EmbeddingsContentHandler [Required]# The content handler class that provides an input and output transform functions to handle formats between LLM and the endpoint. field credentials...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-12
chunk size specified by the class. Returns List of embeddings, one for each text. embed_query(text: str) → List[float][source]# Compute query embeddings using a SageMaker inference endpoint. Parameters text – The text to embed. Returns Embeddings for the text. pydantic model langchain.embeddings.SelfHostedEmbeddings[so...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-13
rh.blob(pickle.dumps(pipeline), path="models/pipeline.pkl").save().to(gpu, path="models") embeddings = SelfHostedHFEmbeddings.from_pipeline( pipeline="models/pipeline.pkl", hardware=gpu, model_reqs=["./", "torch", "transformers"], ) Validators raise_deprecation » all fields set_verbose » verbose field i...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-14
gpu = rh.cluster(name="rh-a10x", instance_type="A100:1") hf = SelfHostedHuggingFaceEmbeddings(model_name=model_name, hardware=gpu) Validators raise_deprecation » all fields set_verbose » verbose field hardware: Any = None# Remote hardware to send the inference function to. field inference_fn: Callable = <function _embe...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-15
Validators raise_deprecation » all fields set_verbose » verbose field embed_instruction: str = 'Represent the document for retrieval: '# Instruction to use for embedding documents. field model_id: str = 'hkunlp/instructor-large'# Model name to use. field model_reqs: List[str] = ['./', 'InstructorEmbedding', 'torch']# R...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
8ceef0c87e6d-16
Parameters texts – The list of texts to embed. Returns List of embeddings, one for each text. embed_query(text: str) → List[float][source]# Compute query embeddings using a TensorflowHub embedding model. Parameters text – The text to embed. Returns Embeddings for the text. previous Chat Models next Indexes By Harrison ...
https://python.langchain.com/en/latest/reference/modules/embeddings.html
72d62d9cc3de-0
.md .pdf Quickstart Guide Contents Installation Environment Setup Building a Language Model Application: LLMs LLMs: Get predictions from a language model Prompt Templates: Manage prompts for LLMs Chains: Combine LLMs and prompts in multi-step workflows Agents: Dynamically Call Chains Based on User Input Memory: Add S...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-1
LangChain provides many modules that can be used to build language model applications. Modules can be combined to create more complex applications, or be used individually for simple applications. LLMs: Get predictions from a language model# The most basic building block of LangChain is calling an LLM on some input. Le...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-2
This is easy to do with LangChain! First lets define the prompt template: from langchain.prompts import PromptTemplate prompt = PromptTemplate( input_variables=["product"], template="What is a good name for a company that makes {product}?", ) Let’s now see how this works! We can call the .format method to forma...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-3
Now we can run that chain only specifying the product! chain.run("colorful socks") # -> '\n\nSocktastic!' There we go! There’s the first chain - an LLM Chain. This is one of the simpler types of chains, but understanding how it works will set you up well for working with more complex chains. For more details, check out...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-4
pip install google-search-results And set the appropriate environment variables. import os os.environ["SERPAPI_API_KEY"] = "..." Now we can get started! from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.llms import OpenAI # First,...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-5
Thought: I now know the final answer Final Answer: The high temperature in SF yesterday in Fahrenheit raised to the .023 power is 1.0974509573251117. > Finished chain. Memory: Add State to Chains and Agents# So far, all the chains and agents we’ve gone through have been stateless. But often, you may want a chain or age...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-6
Current conversation: Human: Hi there! AI: > Finished chain. ' Hello! How are you today?' output = conversation.predict(input="I'm doing well! Just having a conversation with an AI.") print(output) > Entering new chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The A...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-7
AIMessage, HumanMessage, SystemMessage ) chat = ChatOpenAI(temperature=0) You can get completions by passing in a single message. chat([HumanMessage(content="Translate this sentence from English to French. I love programming.")]) # -> AIMessage(content="J'aime programmer.", additional_kwargs={}) You can also pa...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-8
You can recover things like token usage from this LLMResult: result.llm_output['token_usage'] # -> {'prompt_tokens': 57, 'completion_tokens': 20, 'total_tokens': 77} Chat Prompt Templates# Similar to LLMs, you can make use of templating by using a MessagePromptTemplate. You can build a ChatPromptTemplate from one or mo...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-9
from langchain import LLMChain from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ) chat = ChatOpenAI(temperature=0) template = "You are a helpful assistant that translates {input_language} to {output_language}." system_message_prompt = SystemMe...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-10
agent = initialize_agent(tools, chat, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True) # Now let's test it out! agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?") > Entering new AgentExecutor chain... Thought: I need to use a search engine to find Olivia Wilde...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-11
'2.169459462491557' Memory: Add State to Chains and Agents# You can use Memory with chains and agents initialized with chat models. The main difference between this and Memory for LLMs is that rather than trying to condense all previous messages into a string, we can keep them as their own unique memory object. from la...
https://python.langchain.com/en/latest/getting_started/getting_started.html
72d62d9cc3de-12
conversation.predict(input="Tell me about yourself.") # -> "Sure! I am an AI language model created by OpenAI. I was trained on a large dataset of text from the internet, which allows me to understand and generate human-like language. I can answer questions, provide information, and even have conversations like this on...
https://python.langchain.com/en/latest/getting_started/getting_started.html
24347204e210-0
.md .pdf Concepts Contents Chain of Thought Action Plan Generation ReAct Self-ask Prompt Chaining Memetic Proxy Self Consistency Inception MemPrompt Concepts# These are concepts and terminology commonly used when developing LLM applications. It contains reference to external papers or sources where the concept was fi...
https://python.langchain.com/en/latest/getting_started/concepts.html
24347204e210-1
to respond in a certain way framing the discussion in a context that the model knows of and that will result in that type of response. For example, as a conversation between a student and a teacher. Paper Self Consistency# Self Consistency is a decoding strategy that samples a diverse set of reasoning paths and then se...
https://python.langchain.com/en/latest/getting_started/concepts.html
b8553fa47e4d-0
.md .pdf Tutorials Contents Tutorials# This is a collection of LangChain tutorials on YouTube. ⛓ icon marks a new video [last update 2023-05-15] # LangChain Tutorials by Edrick: ⛓ LangChain, Chroma DB, OpenAI Beginner Guide | ChatGPT with your PDF LangChain Crash Course: Build an AutoGPT app in 25 minutes by Nicholas...
https://python.langchain.com/en/latest/getting_started/tutorials.html
b8553fa47e4d-1
Workaround OpenAI's Token Limit With Chain Types Build Your Own OpenAI + LangChain Web App in 23 Minutes Working With The New ChatGPT API OpenAI + LangChain Wrote Me 100 Custom Sales Emails Structured Output From OpenAI (Clean Dirty Data) Connect OpenAI To +5,000 Tools (LangChain + Zapier) Use LLMs To Extract Data From...
https://python.langchain.com/en/latest/getting_started/tutorials.html
b8553fa47e4d-2
⛓ Using LangChain with DuckDuckGO Wikipedia & PythonREPL Tools ⛓ Building Custom Tools and Agents with LangChain (gpt-3.5-turbo) ⛓ LangChain Retrieval QA Over Multiple Files with ChromaDB ⛓ LangChain Retrieval QA with Instructor Embeddings & ChromaDB for PDFs ⛓ LangChain + Retrieval Local LLMs for Retrieval QA - No Ope...
https://python.langchain.com/en/latest/getting_started/tutorials.html
b8553fa47e4d-3
Analyze Custom CSV Data with GPT-4 using Langchain ⛓ Build ChatGPT Chatbots with LangChain Memory: Understanding and Implementing Memory in Conversations ⛓ icon marks a new video [last update 2023-05-15] previous Concepts next Models Contents By Harrison Chase © Copyright 2023, Harrison Chase. L...
https://python.langchain.com/en/latest/getting_started/tutorials.html