researchgpt icon indicating copy to clipboard operation
researchgpt copied to clipboard

ChatGPT API

Open goldengrape opened this issue 1 year ago • 3 comments

I tried:

r = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", 
            messages=prompt, 
            temperature=0.4, 
            max_tokens=1500)

in main-local.py but doesn't work

goldengrape avatar Mar 04 '23 07:03 goldengrape

prompt should be rewritten as an array of dictionaries. Example:

prompt=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
        {"role": "user", "content": "Where was it played?"}
    ]

magicgh avatar Mar 04 '23 15:03 magicgh

@magicgh

cool! this works:

        messages=[
            {
            "role": "user",
            "content": prompt
            }
        ]
        r = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", 
            messages=messages, 
            temperature=0.4, 
            max_tokens=1500)
        
        answer=(
                r["choices"][0]
                .get("message")
                .get("content")
                .encode("utf8")
                .decode()
            )

goldengrape avatar Mar 04 '23 19:03 goldengrape

@magicgh

cool! this works:

        messages=[
            {
            "role": "user",
            "content": prompt
            }
        ]
        r = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", 
            messages=messages, 
            temperature=0.4, 
            max_tokens=1500)
        
        answer=(
                r["choices"][0]
                .get("message")
                .get("content")
                .encode("utf8")
                .decode()
            )

Hi, I have implemented this in my fork. You can have a try!

MrPeterJin avatar Mar 05 '23 07:03 MrPeterJin