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

Where to inject the few shot examples? #132

Closed
failable opened this issue Nov 3, 2023 · 2 comments
Closed

Where to inject the few shot examples? #132

failable opened this issue Nov 3, 2023 · 2 comments

Comments

@failable
Copy link

failable commented Nov 3, 2023

Where should I put the few shot examples into the prompt to improve accuracy? Should I put it in the model docstring or somewhere else? Can you provide an example?

Thanks.

@jxnl
Copy link
Owner

jxnl commented Nov 3, 2023

yeah The best place would be in the doc string via some examples like comments:

class Extract(BaseModle)
   """
   this represents correctly, extracted items out of XYZ 
   
   Examples:
   >>> " blah blah" -> Extract(...)
   >>> Extract(...)
    """

@jxnl jxnl closed this as completed Nov 8, 2023
@johngonzalez
Copy link

Hi friends. A elegant solution works for me using role function:
here discussion

from pydantic import BaseModel, Field

class User(BaseModel):
    name: str = Field(..., description="Nombre de la persona")
    age: int

example1 = User(name="Marcela", age=37).model_dump_json()
example2 = User(name="Kevin", age=17).model_dump_json()

few_shot_function_calling_example = client.chat.completions.create(
    model="prueba",
    messages=[
        {"role": "user", "content": "Mi nombre es Marcela, tengo 37 años"},
        {"role": "function", "name": "User", "content": example1},
        {"role": "user", "content": "Soy Kevin, mi edad es 17"},
        {"role": "function", "name": "User", "content": example2},
        {"role": "user", "content": "Mi nombre es John González, tengo 38 años"},
    ],
    response_model=User,
    temperature=0
)

print(few_shot_function_calling_example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants