2022-12-13 15:50:46 +00:00
{
"cells": [
{
"cell_type": "markdown",
2022-12-14 16:25:37 +00:00
"id": "20ac6b98",
2022-12-13 15:50:46 +00:00
"metadata": {},
"source": [
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"# Getting Started\n",
2022-12-13 15:50:46 +00:00
"\n",
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"This notebook goes over how to use the LLM class in LangChain.\n",
2022-12-13 15:50:46 +00:00
"\n",
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"The LLM class is a class designed for interfacing with LLMs. There are lots of LLM providers (OpenAI, Cohere, Hugging Face, etc) - this class is designed to provide a standard interface for all of them. In this part of the documentation, we will focus on generic LLM functionality. For details on working with a specific LLM wrapper, please see the examples in the [How-To section](how_to_guides.rst).\n",
"\n",
"For this notebook, we will work with an OpenAI LLM wrapper, although the functionalities highlighted are generic for all LLM types."
2022-12-13 15:50:46 +00:00
]
},
{
"cell_type": "code",
"execution_count": 1,
2022-12-14 16:25:37 +00:00
"id": "df924055",
2023-02-14 23:06:14 +00:00
"metadata": {
"tags": []
},
2022-12-13 15:50:46 +00:00
"outputs": [],
"source": [
"from langchain.llms import OpenAI"
]
},
{
"cell_type": "code",
"execution_count": 2,
2022-12-14 16:25:37 +00:00
"id": "182b484c",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [],
"source": [
"llm = OpenAI(model_name=\"text-ada-001\", n=2, best_of=2)"
]
},
{
"cell_type": "markdown",
2022-12-14 16:25:37 +00:00
"id": "9695ccfc",
2022-12-13 15:50:46 +00:00
"metadata": {},
"source": [
"**Generate Text:** The most basic functionality an LLM has is just the ability to call it, passing in a string and getting back a string."
]
},
{
"cell_type": "code",
"execution_count": 3,
2022-12-14 16:25:37 +00:00
"id": "9d12ac26",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"'\\n\\nWhy did the chicken cross the road?\\n\\nTo get to the other side.'"
2022-12-13 15:50:46 +00:00
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm(\"Tell me a joke\")"
]
},
{
"cell_type": "markdown",
2022-12-14 16:25:37 +00:00
"id": "e7d4d42d",
2022-12-13 15:50:46 +00:00
"metadata": {},
"source": [
"**Generate:** More broadly, you can call it with a list of inputs, getting back a more complete response than just the text. This complete response includes things like multiple top responses, as well as LLM provider specific information"
]
},
{
"cell_type": "code",
"execution_count": 4,
2022-12-14 16:25:37 +00:00
"id": "f4dc241a",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [],
"source": [
2022-12-14 16:25:37 +00:00
"llm_result = llm.generate([\"Tell me a joke\", \"Tell me a poem\"]*15)"
2022-12-13 15:50:46 +00:00
]
},
{
"cell_type": "code",
2022-12-15 15:53:32 +00:00
"execution_count": 5,
2022-12-14 16:25:37 +00:00
"id": "740392f6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"30"
]
},
2022-12-15 15:53:32 +00:00
"execution_count": 5,
2022-12-14 16:25:37 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(llm_result.generations)"
]
},
{
"cell_type": "code",
2022-12-15 15:53:32 +00:00
"execution_count": 6,
2022-12-14 16:25:37 +00:00
"id": "ab6cdcf1",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"[Generation(text='\\n\\nWhy did the chicken cross the road?\\n\\nTo get to the other side!'),\n",
" Generation(text='\\n\\nWhy did the chicken cross the road?\\n\\nTo get to the other side.')]"
2022-12-13 15:50:46 +00:00
]
},
2022-12-15 15:53:32 +00:00
"execution_count": 6,
2022-12-13 15:50:46 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm_result.generations[0]"
]
},
{
"cell_type": "code",
2022-12-15 15:53:32 +00:00
"execution_count": 7,
2022-12-14 16:25:37 +00:00
"id": "4946a778",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"[Generation(text=\"\\n\\nWhat if love neverspeech\\n\\nWhat if love never ended\\n\\nWhat if love was only a feeling\\n\\nI'll never know this love\\n\\nIt's not a feeling\\n\\nBut it's what we have for each other\\n\\nWe just know that love is something strong\\n\\nAnd we can't help but be happy\\n\\nWe just feel what love is for us\\n\\nAnd we love each other with all our heart\\n\\nWe just don't know how\\n\\nHow it will go\\n\\nBut we know that love is something strong\\n\\nAnd we'll always have each other\\n\\nIn our lives.\"),\n",
" Generation(text='\\n\\nOnce upon a time\\n\\nThere was a love so pure and true\\n\\nIt lasted for centuries\\n\\nAnd never became stale or dry\\n\\nIt was moving and alive\\n\\nAnd the heart of the love-ick\\n\\nIs still beating strong and true.')]"
2022-12-13 15:50:46 +00:00
]
},
2022-12-15 15:53:32 +00:00
"execution_count": 7,
2022-12-13 15:50:46 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2022-12-14 16:25:37 +00:00
"llm_result.generations[-1]"
2022-12-13 15:50:46 +00:00
]
},
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
{
"cell_type": "markdown",
"id": "9efae834",
"metadata": {},
"source": [
"You can also access provider specific information that is returned. This information is NOT standardized across providers."
]
},
2022-12-13 15:50:46 +00:00
{
"cell_type": "code",
2022-12-14 16:25:37 +00:00
"execution_count": 8,
"id": "242e4527",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"{'token_usage': {'completion_tokens': 3903,\n",
" 'total_tokens': 4023,\n",
" 'prompt_tokens': 120}}"
2022-12-13 15:50:46 +00:00
]
},
2022-12-14 16:25:37 +00:00
"execution_count": 8,
2022-12-13 15:50:46 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm_result.llm_output"
]
},
{
"cell_type": "markdown",
2022-12-14 16:25:37 +00:00
"id": "bde8e04f",
2022-12-13 15:50:46 +00:00
"metadata": {},
"source": [
"**Number of Tokens:** You can also estimate how many tokens a piece of text will be in that model. This is useful because models have a context length (and cost more for more tokens), which means you need to be aware of how long the text you are passing in is.\n",
"\n",
2023-04-14 14:40:26 +00:00
"Notice that by default the tokens are estimated using [tiktoken](https://github.com/openai/tiktoken) (except for legacy version <3.8, where a Hugging Face tokenizer is used)"
2022-12-13 15:50:46 +00:00
]
},
{
"cell_type": "code",
2022-12-15 15:53:32 +00:00
"execution_count": 9,
2022-12-14 16:25:37 +00:00
"id": "b623c774",
2022-12-13 15:50:46 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
2022-12-15 15:53:32 +00:00
"execution_count": 9,
2022-12-13 15:50:46 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm.get_num_tokens(\"what a joke\")"
]
}
],
"metadata": {
"kernelspec": {
2022-12-19 22:36:14 +00:00
"display_name": "Python 3 (ipykernel)",
2022-12-13 15:50:46 +00:00
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
"version": "3.10.9"
2022-12-17 00:47:23 +00:00
},
"vscode": {
"interpreter": {
"hash": "1235b9b19e8e9828b5c1fdb2cd89fe8d3de0fcde5ef5f3db36e4b671adb8660f"
}
2022-12-13 15:50:46 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}