Skip to content
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

Merged
merged 6 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Trigger auto deployment for lobechatazure

# When this action will be executed
on:
# Automatically trigger it when detected changes in repo
push:
branches:
[ cygnaw/changesystemrole ]
paths:
- '**'
- '.github/workflows/lobechatazure-AutoDeployTrigger-bdbe175d-28d2-43a7-a2db-f0a2225af446.yml'

# Allow manual trigger
workflow_dispatch:

jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
id-token: write #This is required for requesting the OIDC JWT Token
contents: read #Required when GH token is used to authenticate with private repo

steps:
- name: Checkout to the branch
uses: actions/checkout@v2

- name: Azure Login
uses: azure/login@v1
with:
client-id: ${{ secrets.LOBECHATAZURE_AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.LOBECHATAZURE_AZURE_TENANT_ID }}
subscription-id: ${{ secrets.LOBECHATAZURE_AZURE_SUBSCRIPTION_ID }}

- name: Build and push container image to registry
uses: azure/container-apps-deploy-action@v2
with:
appSourcePath: ${{ github.workspace }}
_dockerfilePathKey_: _dockerfilePath_
registryUrl:
registryUsername: ${{ secrets.LOBECHATAZURE_REGISTRY_USERNAME }}
registryPassword: ${{ secrets.LOBECHATAZURE_REGISTRY_PASSWORD }}
containerAppName: lobechatazure
resourceGroup: lc_RG
imageToBuild: default/[parameters('containerAppName')]:${{ github.sha }}
_buildArgumentsKey_: |
_buildArgumentsValues_


21 changes: 20 additions & 1 deletion src/libs/agent-runtime/azureOpenai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
'o1-preview',
'o1-preview-2024-09-12',
'o1-mini',
'o1-mini-2024-09-12',
]);

const updatedMessages = messages.map((message) => ({
...message,
role:
(model.includes('o1') || model.includes('o3')) && message.role === 'system'
? [...systemToUserModels].some((sub) => model.includes(sub))
? 'user'
: 'developer'
: message.role,
}));

try {
const response = await this.client.chat.completions.create({
messages: messages as OpenAI.ChatCompletionMessageParam[],
messages: updatedMessages as OpenAI.ChatCompletionMessageParam[],
model,
...params,
max_completion_tokens: null,
Expand Down