langchain icon indicating copy to clipboard operation
langchain copied to clipboard

gpt turbo patch DEMO

Open FergusFettes opened this issue 2 years ago • 6 comments

Not a serious PR, just a demo.

Using the normal completions endpoint with Chat models.

With this patch, you can use the summarizing chains and agents with gpt-3.5-turbo and gpt-4.

FergusFettes avatar Mar 20 '23 17:03 FergusFettes

this is cool -- wonder if we can get fake batching behavior in here too, e.g.:

batch_messages = [
    [
        SystemMessage(content="You are a helpful assistant that translates English to French."),
        HumanMessage(content="Translate this sentence from English to French. I love programming.")
    ],
    [
        SystemMessage(content="You are a helpful assistant that translates English to French."),
        HumanMessage(content="Translate this sentence from English to French. I love artificial intelligence.")
    ],
]
result = chat.generate(batch_messages)

from: https://github.com/hwchase17/langchain/blob/a581bce37919b7f0e18c85c4b7043ee92c21364c/docs/modules/chat/getting_started.ipynb#L143

colindotfun avatar Mar 21 '23 21:03 colindotfun

Well yeah, you can do that just with

from langchain.chains.llm import LLMChain
from langchain.llms.openai import OpenAI
from langchain.prompts.prompt import PromptTemplate

llm = OpenAI(temperature=0, model="gpt-3.5-turbo")

template = """
You are a helpful assistant that translates English to French. Translate this sentence from English to French: {text}
"""
prompt = PromptTemplate(input_variables=["text"], template=template)
llm_chain = LLMChain(llm=llm, prompt=prompt)
response = llm_chain.generate(
    [
        {"text": "I love AI"},
        {"text": "I love the ocean"},
    ]
)

for g in response.generations:
    print(g[0].text)

> Je t'aime l'IA
> J'aime l'océan

I think the whole 'ChatCompletions' endpoint was just a smokescreen so nobody noticed they dropped logprobs, I wouldn't pay attention to it. There is no real benefit of eg. the system message atm.

FergusFettes avatar Mar 22 '23 11:03 FergusFettes

yeah, i mean within the MapReduceChain when using turbo, as per: https://github.com/hwchase17/langchain/issues/1643#issuecomment-1474851219

colindotfun avatar Mar 22 '23 16:03 colindotfun

I guess with async and a for loop you could roll your own batching yeah :). Might just mean you would hit rate limits faster though.

FergusFettes avatar Mar 22 '23 23:03 FergusFettes

any chance of getting this merged @iltoga @hwchase17

ChrisPF123 avatar Apr 24 '23 20:04 ChrisPF123

sorry @ChrisPF123 I don't have privileges to merge pr on this repo

iltoga avatar Apr 30 '23 01:04 iltoga

Is this the only solution in order to use turbo for summarization? Or is there an official way?

Thanks.

deedeeharris avatar May 15 '23 18:05 deedeeharris

stale, should be using ChatOpenAI for this these days. closing, let me know if i'm missing something!

baskaryan avatar Aug 08 '23 20:08 baskaryan