Skip to content

Commit

Permalink
๐Ÿ› fix: fix azure tools calling (#3046)
Browse files Browse the repository at this point in the history
* ๐Ÿ› fix: desensitized azure endpoint

* ๐Ÿ› fix: fix azure tool calling

* โœ… test: fix test

* โœ… test: fix test
  • Loading branch information
arvinxx committed Jun 26, 2024
1 parent a5c348d commit b929985
Show file tree
Hide file tree
Showing 5 changed files with 643 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/libs/agent-runtime/azureOpenai/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('LobeAzureOpenAI', () => {
} catch (e) {
// Assert
expect(e).toEqual({
endpoint: 'https://test.openai.azure.com/',
endpoint: 'https://***.openai.azure.com/',
error: {
code: 'DeploymentNotFound',
message: 'Deployment not found',
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('LobeAzureOpenAI', () => {
} catch (e) {
// Assert
expect(e).toEqual({
endpoint: 'https://test.openai.azure.com/',
endpoint: 'https://***.openai.azure.com/',
errorType: 'AgentRuntimeError',
provider: 'azure',
error: {
Expand Down
17 changes: 14 additions & 3 deletions src/libs/agent-runtime/azureOpenai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ChatCompetitionOptions, ChatStreamPayload, ModelProvider } from '../typ
import { AgentRuntimeError } from '../utils/createError';
import { debugStream } from '../utils/debugStream';
import { StreamingResponse } from '../utils/response';
import { OpenAIStream } from '../utils/streams';
import { AzureOpenAIStream } from '../utils/streams';

export class LobeAzureOpenAI implements LobeRuntimeAI {
client: OpenAIClient;
Expand Down Expand Up @@ -47,7 +47,7 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
debugStream(debug).catch(console.error);
}

return StreamingResponse(OpenAIStream(prod, options?.callback), {
return StreamingResponse(AzureOpenAIStream(prod, options?.callback), {
headers: options?.headers,
});
} catch (e) {
Expand All @@ -72,7 +72,7 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
: AgentRuntimeErrorType.AgentRuntimeError;

throw AgentRuntimeError.chat({
endpoint: this.baseURL,
endpoint: this.maskSensitiveUrl(this.baseURL),
error,
errorType,
provider: ModelProvider.Azure,
Expand Down Expand Up @@ -103,4 +103,15 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
.toLowerCase()
.replaceAll(/(_[a-z])/g, (group) => group.toUpperCase().replace('_', ''));
};

private maskSensitiveUrl = (url: string) => {
// ไฝฟ็”จๆญฃๅˆ™่กจ่พพๅผๅŒน้… 'https://' ๅŽ้ขๅ’Œ '.openai.azure.com/' ๅ‰้ข็š„ๅ†…ๅฎน
const regex = /^(https:\/\/)([^.]+)(\.openai\.azure\.com\/.*)$/;

// ไฝฟ็”จๆ›ฟๆขๅ‡ฝๆ•ฐ
return url.replace(regex, (match, protocol, subdomain, rest) => {
// ๅฐ†ๅญๅŸŸๅๆ›ฟๆขไธบ '***'
return `${protocol}***${rest}`;
});
};
}
Loading

0 comments on commit b929985

Please sign in to comment.