ChatCompletions create() doesn't type-check enums as role
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Xác định định nghĩa của ChatCompletionMessageParam và xem lại cuộc thảo luận trước đó trong issue #911. Sử dụng ví dụ được cung cấp làm trường hợp kiểm tra kiểu đầu tiên và coi công việc là hoàn tất khi trường hợp đó được chấp nhận, trong khi các dạng message chuyên biệt system, user, assistant, tool và function vẫn được hỗ trợ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- This is a feature request for the Python library
Describe the feature or improvement you're requesting
This was discussed previously @ #911, but just opening a new issue so that it's in the issue tracker.
The Bug
When calling,
role: Literal["system", "user", "assistant"] = ...
completion = await client.chat.completions.create(
model="gpt-4",
messages={"role": role, "content": "Hi"}
)
Reason
The main issue is that it's defined as an enum of typed dicts,
ChatCompletionMessageParam = Union[
ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam,
ChatCompletionAssistantMessageParam,
ChatCompletionToolMessageParam,
ChatCompletionFunctionMessageParam,
]
Of course, for tooling & functions, we need to know exactly whether or not it's a user or assistant message. But role: str, content: str is the most common use-case, so it would be nice if system/user/assistant can all use that kind of interface when necessary.
Additional context
Potential Solution
From https://github.com/openai/openai-python/issues/911#issuecomment-2038669860,
I think a very simple solution would be to add another type to the ChatCompletionMessageParam union.
Currently, we have
ChatCompletionMessageParam = Union[
ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam,
ChatCompletionAssistantMessageParam,
ChatCompletionToolMessageParam,
ChatCompletionFunctionMessageParam,
]
If instead we had,
ChatCompletionMessageParam = Union[
ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam,
ChatCompletionAssistantMessageParam,
ChatCompletionToolMessageParam,
ChatCompletionFunctionMessageParam,
ChatCompletionGenericMessageParam,
]
Where ChatCompletionGenericMessageParam was,
class ChatCompletionGenericMessageParam(TypedDict, total=False):
content: Required[Optional[str]]
role: Required[Literal["system", "user", "assistant"]]
- Under my understanding, adding an option to a Union does not break compatibility with anybody (Lmk if I'm wrong)
- This handles all possible situations (pydantic model, custom TypedDict with Literal, a mixture of both, etc).
- And, if the user wants to pass in a tool/FunctionCall/ChatCompletionContentPartParam, then obviously they need to use the other types and prove that it's specifically a system/user/etc.
- OpenAI can still internally type check safely, because it can write a type-safe function to convert
ChatCompletionGenericMessageParaminto aUnion[ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam,ChatCompletionAssistantMessageParam].
- Ngôn ngữ chính
- Python
- Star
- 32.2k
- Fork
- 5.8k
- Merge trung bình
- 12 giờ 29 phút
- Pull request đã merge (30 ngày)
- 112
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
openai/openai-python#4338 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
openai/openai-python#4337 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersCó thể đã có người làm @Rewaskc02-lang đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#4311 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#4310 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
openai/openai-python#4309 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
bad-antics/lateralus-lang#1140 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Groq: SQL fallback call sends tools with response_format, so a failed tool loop never recoversĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 3 ngày
-
fixture good first issue help wanted vendor:cisco
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100