Thursday, 8 December 2022

How to extract required information using GPT-3 API

I tried the steps mentioned in this article.

https://matthewbilyeu.com/blog/2022-09-01/responding-to-recruiter-emails-with-gpt-3

There is a screenshot that says: Here's an example from the OpenAI Playground.

I typed all the text in "playground" but do not get similar response as shown in that image. I expected similar text like {"name":"William", "company":"BillCheese"} I am not sure how to configure the parameters in openAI web interface.


Update:

I used this code:

import json
import re, textwrap 
 
import openai
openai.api_key = 'xxx'

prompt = f"""
Hi Matt! This is Steve Jobs with Inforation Edge Limited ! I'm interested in having you join our team here. 
"""

completion = openai.Completion.create(
    model="text-davinci-002",
    prompt=textwrap.dedent(prompt),
    max_tokens=20,
    temperature=0,
)

try:
    json_str_response = completion.choices[0].text
    json_str_response_clean = re.search(r".*(\{.*\})", json_str_response).groups()[0]
    print (json.loads(json_str_response_clean))

except (AttributeError, json.decoder.JSONDecodeError) as exception:
    print("Could not decode completion response from OpenAI:")
    print(completion)
    raise exception

and got this error:

Could not decode completion response from OpenAI:
AttributeError: 'NoneType' object has no attribute 'groups'


from How to extract required information using GPT-3 API

No comments:

Post a Comment