promptslab / Promptify

Prompt Engineering | Prompt Versioning | Use GPT or other prompt based models to get structured output. Join our discord for Prompt-Engineering, LLMs and other latest research
https://discord.gg/m88xfYMbK6
Apache License 2.0
3.21k stars 238 forks source link

Error running README example #10

Closed abnerjacobsen closed 1 year ago

abnerjacobsen commented 1 year ago

Hi,

I'm trying to run the example in the README, but I'm getting an error.

The source code I used was this:

from promptify import OpenAI
from promptify import Prompter

sentence     =  """The patient is a 93-year-old female with a medical
                history of chronic right hip pain, osteoporosis,
                hypertension, depression, and chronic atrial
                fibrillation admitted for evaluation and management
                of severe nausea and vomiting and urinary tract
                infection"""

model        = OpenAI("sk-MYKEY")
nlp_prompter = Prompter(model)

result       = nlp_prompter.fit('ner.jinja', domain ='medical', text_input  = sentence)
print(result)

And the error that occurs is this:

File "./teste.py", line 15, in <module>
    result       = nlp_prompter.fit('ner.jinja', domain ='medical', text_input  = sentence)
  File "/home/abner/Devel/daschat/openai/promptify/.venv/lib/python3.8/site-packages/promptify/prompts/nlp/prompter.py", line 52, in fit
    prompt = self.generate_prompt(template_name, **prompt_kwargs)
  File "/home/abner/Devel/daschat/openai/promptify/.venv/lib/python3.8/site-packages/promptify/prompts/nlp/prompter.py", line 38, in generate_prompt
    assert len(variables_missing) == 0, f"Missing required variables in template {variables_missing}"
AssertionError: Missing required variables in template ['labels']

Any idea what I'm doing wrong?

Thanks.

monk1337 commented 1 year ago

Hi, You need to pass labels = None and eval(result['text']). Here is a working example

from promptify import OpenAI
from promptify import Prompter

sentence     =  """The patient is a 93-year-old female with a medical
                history of chronic right hip pain, osteoporosis,
                hypertension, depression, and chronic atrial
                fibrillation admitted for evaluation and management
                of severe nausea and vomiting and urinary tract
                infection"""

model        = OpenAI("sk-MYKEY")
nlp_prompter = Prompter(model)

result       = nlp_prompter.fit('ner.jinja', domain ='medical', text_input  = sentence, labels = None)
eval(result['text'])