mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 09:55:21 +03:00
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