Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return multiple choices #576

Closed
kstathou opened this issue Apr 7, 2024 · 7 comments
Closed

Return multiple choices #576

kstathou opened this issue Apr 7, 2024 · 7 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@kstathou
Copy link

kstathou commented Apr 7, 2024

Describe the solution you'd like
Thanks a lot for making this library, it's been super helpful! I am working on a text classification task and I wanted to get multiple parsed responses from a single client.chat.completions.create call using OpenAI's n parameter.

The following would only parse the first completion I believe:

client.chat.completions.create_with_completion(
        model="gpt-3.5-turbo-0613",
        response_model=SinglePrediction,
        messages=[
            {
                "role": "user",
                "content": f"Classify the following text: {data}",
            },
        ],
        n=3,
    )

How would you recommend going on about it? Thank you!

@dosubot dosubot bot added enhancement New feature or request question Further information is requested labels Apr 7, 2024
@jxnl
Copy link
Owner

jxnl commented Apr 7, 2024

I think we can create a overload that does this thanks for the new sdk

@jxnl
Copy link
Owner

jxnl commented Apr 7, 2024

Will experiment with overloads.

@jxnl
Copy link
Owner

jxnl commented Apr 8, 2024

#578

@NicolaiLolansen
Copy link
Contributor

NicolaiLolansen commented Jun 3, 2024

#578

This was closed without merge, is this functionality working? It's a really nice feature to have if you want to extract multiple elements from a larger chunk of text, like menu items.

EDIT:

Reading https://python.useinstructor.com/examples/classification/#defining-the-structures_1 it seems like this can be solved by constructing your Pydantic models into a list of items:

class ItemType(str, Enum):
    MAIN_COURSE = "main_course"
    APPETIZER = "appetizer"
    DESSERT = "dessert"
    DRINK = "drink"

class MenuItem(BaseModel):
    name: str  # Name of the menu item
    item_type: ItemType  # Type of menu item (e.g., main course, appetizer, etc.)
    description: str  # Description of the menu item
    price: float  # Price of the menu item

class Menu(BaseModel):
    items: List[MenuItem]
   

In my limited testing, this works!

@josepablog
Copy link

Also interested in this feature

@NicolaiLolansen
Copy link
Contributor

NicolaiLolansen commented Jun 4, 2024

Also interested in this feature

@josepablog Did you look at the solution I posted? It seems to work very well for me.

@josepablog
Copy link

ohhh.. I didn't understand it at first.

I'll think about it, I think I may be able to solve my issue with prompting: I'm outputting a list to begin with, and I don't think a list of lists. I am just trying to make sure that the list is long enough.

thanks for getting back to me!

@jxnl jxnl closed this as completed Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants