mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-07 02:15:19 +03:00
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>
6.4 KiB
6.4 KiB
In [1]:
from langchain.llms import OpenAIIn [2]:
llm = OpenAI(model_name="text-ada-001", n=2, best_of=2)In [3]:
llm("Tell me a joke")Out [3]:
'\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'
In [4]:
llm_result = llm.generate(["Tell me a joke", "Tell me a poem"]*15)In [5]:
len(llm_result.generations)Out [5]:
30
In [6]:
llm_result.generations[0]Out [6]:
[Generation(text='\n\nWhy did the chicken cross the road?\n\nTo get to the other side!'), Generation(text='\n\nWhy did the chicken cross the road?\n\nTo get to the other side.')]
In [7]:
llm_result.generations[-1]Out [7]:
[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."), 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.')]
In [8]:
llm_result.llm_outputOut [8]:
{'token_usage': {'completion_tokens': 3903,
'total_tokens': 4023,
'prompt_tokens': 120}}In [9]:
llm.get_num_tokens("what a joke")Out [9]:
3
In [ ]: