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.11k stars 232 forks source link

NER response is a string, should be list of dicts #8

Open sevenChrisK opened 1 year ago

sevenChrisK commented 1 year ago

The response for the NER template is a string representation of a list of dictionaries.

Currently this means the user first needs to parse and convert into list of dicts to use the output effectively.

monk1337 commented 1 year ago

Hi, Did you try the eval() method on response?

sevenChrisK commented 1 year ago

Hi the eval() method should normally work but sometimes the output string starts with a whitespace character that throws an exception.

Maybe the return should involve a step to strip whitespace?

monk1337 commented 1 year ago

We are working on a verifier step to check the response type.

abushoeb commented 11 months ago

@sevenChrisK thanks for reporting this. I encountered the same problem. A quick fix that worked for me was using strip().

import ast
response = nlp_prompter.fit('ner.jinja',
                                domain = 'medical',
                                text_input = text, 
                                labels = None)

print(ast.literal_eval(response['text'].strip()))