mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
fix: get models openai
This commit is contained in:
parent
fd64ea07d0
commit
3fa6b1fcc5
@ -1,3 +1,11 @@
|
||||
# 2.0.6-rc (release candidate)
|
||||
|
||||
### Features
|
||||
|
||||
* Get models for OpenAI
|
||||
|
||||
### Fixed
|
||||
|
||||
# 2.0.5-rc (2024-08-01 18:01)
|
||||
|
||||
### Features
|
||||
|
File diff suppressed because one or more lines are too long
2
manager/dist/index.html
vendored
2
manager/dist/index.html
vendored
@ -5,7 +5,7 @@
|
||||
<link rel="icon" type="image/png" href="/assets/images/evolution-logo.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Evolution Manager</title>
|
||||
<script type="module" crossorigin src="/assets/index-BfneAfPP.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-Bq7txaly.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-DZ0gaAHg.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -79,6 +79,12 @@ export class OpenaiController {
|
||||
return this.openaiService.fetchSessions(instance, openaiBotId);
|
||||
}
|
||||
|
||||
public async getModels(instance: InstanceDto) {
|
||||
if (!configService.get<Openai>('OPENAI').ENABLED) throw new BadRequestException('Openai is disabled');
|
||||
|
||||
return this.openaiService.getModels(instance);
|
||||
}
|
||||
|
||||
public async ignoreJid(instance: InstanceDto, data: OpenaiIgnoreJidDto) {
|
||||
if (!configService.get<Openai>('OPENAI').ENABLED) throw new BadRequestException('Openai is disabled');
|
||||
|
||||
|
@ -146,6 +146,16 @@ export class OpenaiRouter extends RouterBroker {
|
||||
execute: (instance, data) => openaiController.ignoreJid(instance, data),
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.get(this.routerPath('getModels'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: instanceSchema,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => openaiController.getModels(instance),
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
});
|
||||
}
|
||||
|
@ -647,6 +647,42 @@ export class OpenaiService {
|
||||
}
|
||||
}
|
||||
|
||||
public async getModels(instance: InstanceDto) {
|
||||
const instanceId = await this.prismaRepository.instance
|
||||
.findFirst({
|
||||
where: {
|
||||
name: instance.instanceName,
|
||||
},
|
||||
})
|
||||
.then((instance) => instance.id);
|
||||
|
||||
if (!instanceId) throw new Error('Instance not found');
|
||||
|
||||
const defaultSettings = await this.prismaRepository.openaiSetting.findFirst({
|
||||
where: {
|
||||
instanceId: instanceId,
|
||||
},
|
||||
include: {
|
||||
OpenaiCreds: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!defaultSettings) throw new Error('Settings not found');
|
||||
|
||||
const { apiKey } = defaultSettings.OpenaiCreds;
|
||||
|
||||
try {
|
||||
this.client = new OpenAI({ apiKey });
|
||||
|
||||
const models: any = await this.client.models.list();
|
||||
|
||||
return models?.body?.data;
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new Error('Error fetching models');
|
||||
}
|
||||
}
|
||||
|
||||
public async ignoreJid(instance: InstanceDto, data: OpenaiIgnoreJidDto) {
|
||||
try {
|
||||
const instanceId = await this.prismaRepository.instance
|
||||
|
Loading…
Reference in New Issue
Block a user