mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-09 11:25:21 +03:00
4.1 KiB
4.1 KiB
In [1]:
from langchain import LLMChain, OpenAI, Cohere, HuggingFaceHub, Prompt
from langchain.model_laboratory import ModelLaboratoryIn [2]:
llms = [
OpenAI(temperature=0),
Cohere(model="command-xlarge-20221108", max_tokens=20, temperature=0),
HuggingFaceHub(repo_id="google/flan-t5-xl", model_kwargs={"temperature":1})
]In [3]:
model_lab = ModelLaboratory(llms)In [4]:
model_lab.compare("What color is a flamingo?")[1mInput:[0m
What color is a flamingo?
[1mOpenAI[0m
Params: {'model': 'text-davinci-002', 'temperature': 0.0, 'max_tokens': 256, 'top_p': 1, 'frequency_penalty': 0, 'presence_penalty': 0, 'n': 1, 'best_of': 1}
[104m
Flamingos are pink.[0m
[1mCohere[0m
Params: {'model': 'command-xlarge-20221108', 'max_tokens': 20, 'temperature': 0.0, 'k': 0, 'p': 1, 'frequency_penalty': 0, 'presence_penalty': 0}
[103m
Pink[0m
[1mHuggingFaceHub[0m
Params: {'repo_id': 'google/flan-t5-xl', 'temperature': 1}
[101mpink[0m
In [5]:
prompt = Prompt(template="What is the capital of {state}?", input_variables=["state"])
model_lab_with_prompt = ModelLaboratory(llms, prompt=prompt)In [6]:
model_lab_with_prompt.compare("New York")[1mInput:[0m
New York
[1mOpenAI[0m
Params: {'model': 'text-davinci-002', 'temperature': 0.0, 'max_tokens': 256, 'top_p': 1, 'frequency_penalty': 0, 'presence_penalty': 0, 'n': 1, 'best_of': 1}
[104m
The capital of New York is Albany.[0m
[1mCohere[0m
Params: {'model': 'command-xlarge-20221108', 'max_tokens': 20, 'temperature': 0.0, 'k': 0, 'p': 1, 'frequency_penalty': 0, 'presence_penalty': 0}
[103m
The capital of New York is Albany.[0m
[1mHuggingFaceHub[0m
Params: {'repo_id': 'google/flan-t5-xl', 'temperature': 1}
[101mst john s[0m
In [ ]: