openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

ChatML: name property should support '@' character

Open cancelself opened this issue 1 year ago • 2 comments

Describe the bug

Lots of existing usernames contain @ as namespace and prefixing. Complete understand why this is defined narrowly, but you are pushing a bunch of work on to developers and this surprised me.

File "/Users/dmp/Library/Python/3.9/lib/python/site-packages/openai/api_requestor.py", line 679, in interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: '@username' does not match '^[a-zA-Z0-9-]{1,64}$' - 'messages.6.name'

To Reproduce

image

`#add the user + message in the third argument whoiam = getpass.getuser() whoiam = "@" + whoiam prompt = {"role": "user", "content": sys.argv[3], "name": whoiam}

#talk to chatGPT completion = openai.ChatCompletion.create( model = "gpt-3.5-turbo", messages = chatml + [prompt] )`

Code snippets

#add the user + message in the third argument
whoiam = getpass.getuser()
whoiam = "@" + whoiam
prompt = {"role": "user", "content": sys.argv[3], "name": whoiam}

#talk to chatGPT
completion = openai.ChatCompletion.create(
  model = "gpt-3.5-turbo", 
  messages = chatml + [prompt]
)

OS

macOS

Python version

Python

Library version

openai-python

cancelself avatar Mar 14 '23 21:03 cancelself

Currently the chat API uses the role value to identify the "speaker" as the user, assistant, or system. Do you have a link to any documentation that mentions using the name value?

tanpinxi avatar Mar 16 '23 15:03 tanpinxi

@FizzyAgent see:

  • https://github.com/openai/openai-python/blob/main/chatml.md#few-shot-prompting
  • https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb (section 6) image

But I do agree that it's weird that it's not specified in the official documentation.

ghost avatar Mar 18 '23 05:03 ghost

In addition to @ character I would strongly suggest we enable:

  1. Space. A full name contains first name and space and last name.
  2. Any unicode characters.

Very useful for a multi user chatbot.

hzeng-otterai avatar Aug 01 '23 18:08 hzeng-otterai

ß should also be enabled. It is a very common char for a chatbot

lucajung avatar Sep 05 '23 17:09 lucajung

Thanks for filing, this feature request makes sense to me and I've pass it along to the backend teams.

I'm going to close this since it's not a limitation imposed in the Python library; if you'd like to continue to advocate for it, I recommend community.openai.com

rattrayalex avatar Nov 10 '23 04:11 rattrayalex