-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 fix: update message roles for specific Azure OpenAI models #6222
base: main
Are you sure you want to change the base?
Conversation
@cygnaw is attempting to deploy a commit to the LobeHub Team on Vercel. A member of the Team first needs to authorize it. |
👍 @hcygnaw Thank you for raising your pull request and contributing to our Community |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6222 +/- ##
==========================================
- Coverage 91.86% 91.83% -0.04%
==========================================
Files 684 684
Lines 62196 62311 +115
Branches 3095 2908 -187
==========================================
+ Hits 57137 57221 +84
- Misses 5059 5090 +31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -33,9 +33,28 @@ export class LobeAzureOpenAI implements LobeRuntimeAI { | |||
const { messages, model, ...params } = payload; | |||
// o1 series models on Azure OpenAI does not support streaming currently | |||
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true); | |||
|
|||
// Convert 'system' role to 'user' or 'developer' based on the model | |||
const systemToUserModels = new Set([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我感觉是不是反了?目前支持 develop 的反而是少数。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是抄的这边的代码。我只有o1-mini的模型可以用来测试,改了之后是可以跑通的
lobe-chat/src/libs/agent-runtime/openai/index.ts
Lines 10 to 40 in 3e8d9c5
export const pruneReasoningPayload = (payload: ChatStreamPayload) => { | |
// TODO: 临时写法,后续要重构成 model card 展示配置 | |
const disableStreamModels = new Set([ | |
'o1', | |
'o1-2024-12-17' | |
]); | |
const systemToUserModels = new Set([ | |
'o1-preview', | |
'o1-preview-2024-09-12', | |
'o1-mini', | |
'o1-mini-2024-09-12', | |
]); | |
return { | |
...payload, | |
frequency_penalty: 0, | |
messages: payload.messages.map((message: OpenAIChatMessage) => ({ | |
...message, | |
role: | |
message.role === 'system' | |
? systemToUserModels.has(payload.model) | |
? 'user' | |
: 'developer' | |
: message.role, | |
})), | |
presence_penalty: 0, | |
stream: !disableStreamModels.has(payload.model), | |
temperature: 1, | |
top_p: 1, | |
}; | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能照抄。
https://github.com/lobehub/lobe-chat/pull/5714/files
你自己看这里的变更,这个变换是加了约束的:
if (model.startsWith('o1') || model.startsWith('o3')) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据这篇帖子里的讨论,developer现在取代了过去的system。
我这边试过Azure的gpt-4o和gpt-4o-mini,都是能正常使用developer的role的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果这个provider 仅局限于 azure openai 的话估计没问题。但保不准有人用这个 provider 来调 phi-4 等其他模型吧?
@@ -33,9 +33,28 @@ export class LobeAzureOpenAI implements LobeRuntimeAI { | |||
const { messages, model, ...params } = payload; | |||
// o1 series models on Azure OpenAI does not support streaming currently | |||
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true); | |||
|
|||
// Convert 'system' role to 'user' or 'developer' based on the model | |||
const systemToUserModels = new Set([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能照抄。
https://github.com/lobehub/lobe-chat/pull/5714/files
你自己看这里的变更,这个变换是加了约束的:
if (model.startsWith('o1') || model.startsWith('o3')) {}
…lobe-chat into cygnaw/changesystemrole
.github/workflows/lobechatazure-AutoDeployTrigger-bdbe175d-28d2-43a7-a2db-f0a2225af446.yml
Outdated
Show resolved
Hide resolved
…2-43a7-a2db-f0a2225af446.yml
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
Fix #6201
将
system
role切换成user
role或者developer
role。📝 补充信息 | Additional Information
当使用 Azure OpenAI 的 O-series 模型(如 o1, o1-mini 等)时,如果设定了 system prompt 会导致以下错误: