guidance icon indicating copy to clipboard operation
guidance copied to clipboard

Exception Raised When Iterating More Than Once with OpenAI's Instruct Model

Open FCMHUB opened this issue 3 years ago • 2 comments

First of all, thank you for this amazing library.

Version 0.1.1

The bug An exception is raised when iterating more than once with OpenAI's instruct model. Exception: We have exceeded the maximum number of calls! 10

To Reproduce

from guidance import gen, models, instruction

gpt_instruct = models.OpenAI("gpt-3.5-turbo-instruct", api_key='sk-...')

with instruction():
    lm = gpt_instruct + "What are the smallest cats?"
    
lm += gen('smallest', stop=".")

with instruction():
    lm += "And the largest?"
    
lm += gen('largest', stop=".")

print (lm)

Could you please advise if there is an error in my approach or if this is a bug with the library?

FCMHUB avatar Nov 17 '23 13:11 FCMHUB

This is a scenario where better errors messages would help, so I'll leave this issue open until we add those. The core issue though is that you can't instruct the same model twice in a row. In your current code lm is appended with two sets of instructions, and OpenAI models (or any other instruct models) only support one set of instructions at the beginning. You could instead try:

from guidance import gen, models, instruction

gpt_instruct = models.OpenAI("gpt-3.5-turbo-instruct", api_key='sk-...')

with instruction():
    lm = gpt_instruct + "What are the smallest cats?"
    
lm += gen('smallest', stop=".")

with instruction():
    lm = gpt_instruct + "And the largest?"
    
lm += gen('largest', stop=".")

print (lm)

Note how I start with a blank state for the second instruction.

slundberg avatar Nov 17 '23 23:11 slundberg

I added a nice error message for this and also patched one other issue that really was block repeated call to OpenAI models. Thanks for posting!

slundberg avatar Nov 18 '23 00:11 slundberg