fix: refactor qwen mode

This commit is contained in:
ikechan8370 2024-03-12 18:18:06 +08:00
parent 32af7b9a74
commit b221098c37
6 changed files with 1505 additions and 1301 deletions

File diff suppressed because it is too large Load diff

1127
model/core.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -63,7 +63,7 @@ import * as types from './types.js';
import globalFetch from 'node-fetch';
var CHATGPT_MODEL = 'qwen-turbo'; // qwen-plus
var USER_LABEL_DEFAULT = 'User';
var ASSISTANT_LABEL_DEFAULT = '义千问';
var ASSISTANT_LABEL_DEFAULT = '义千问';
var QwenApi = /** @class */ (function () {
/**
* Creates a new client wrapper around Qwen's chat completion API, mimicing the official ChatGPT webapp's functionality as closely as possible.
@ -76,11 +76,11 @@ var QwenApi = /** @class */ (function () {
this._apiBaseUrl = apiBaseUrl;
this._debug = !!debug;
this._fetch = fetch;
this._completionParams = __assign({ model: CHATGPT_MODEL, parameters: __assign({ top_p: 0.5, top_k: 50, temperature: 1.0, seed: 114514, enable_search: true, result_format: "text", incremental_output: false }, parameters) }, completionParams);
this._completionParams = __assign({ model: CHATGPT_MODEL, parameters: __assign({ top_p: 0.5, top_k: 50, temperature: 1.0, seed: 114514, enable_search: true, result_format: "message", incremental_output: false }, parameters) }, completionParams);
this._systemMessage = systemMessage;
if (this._systemMessage === undefined) {
var currentDate = new Date().toISOString().split('T')[0];
this._systemMessage = "You are ChatGPT, a large language model trained by Qwen. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: ".concat(currentDate);
this._systemMessage = "You are Qwen, a large language model trained by Alibaba Cloud. Answer as concisely as possible.\nCurrent date: ".concat(currentDate);
}
this._getMessageById = getMessageById !== null && getMessageById !== void 0 ? getMessageById : this._defaultGetMessageById;
this._upsertMessage = upsertMessage !== null && upsertMessage !== void 0 ? upsertMessage : this._defaultUpsertMessage;
@ -120,7 +120,7 @@ var QwenApi = /** @class */ (function () {
* @param opts.timeoutMs - Optional timeout in milliseconds (defaults to no timeout)
* @param opts.onProgress - Optional callback which will be invoked every time the partial response is updated
* @param opts.abortSignal - Optional callback used to abort the underlying `fetch` call using an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
* @param completionParams - Optional overrides to send to the [Qwen chat completion API](https://platform.openai.com/docs/api-reference/chat/create). Options like `temperature` and `presence_penalty` can be tweaked to change the personality of the assistant.
* @param opts.completionParams - Optional overrides to send to the [Qwen chat completion API](https://platform.openai.com/docs/api-reference/chat/create). Options like `temperature` and `presence_penalty` can be tweaked to change the personality of the assistant.
*
* @returns The response from ChatGPT
*/
@ -128,7 +128,7 @@ var QwenApi = /** @class */ (function () {
if (opts === void 0) { opts = {}; }
if (role === void 0) { role = 'user'; }
return __awaiter(this, void 0, void 0, function () {
var parentMessageId, _a, messageId, timeoutMs, completionParams, conversationId, abortSignal, abortController, message, latestQuestion, _b, messages, maxTokens, numTokens, result, responseP;
var parentMessageId, _a, messageId, timeoutMs, completionParams, conversationId, abortSignal, abortController, message, latestQuestion, parameters, _b, messages, maxTokens, numTokens, result, responseP;
var _this = this;
return __generator(this, function (_c) {
switch (_c.label) {
@ -148,6 +148,9 @@ var QwenApi = /** @class */ (function () {
text: text,
};
latestQuestion = message;
parameters = Object.assign(this._completionParams.parameters, completionParams.parameters);
completionParams = Object.assign(this._completionParams, completionParams);
completionParams.parameters = parameters;
return [4 /*yield*/, this._buildMessages(text, role, opts, completionParams)];
case 1:
_b = _c.sent(), messages = _b.messages, maxTokens = _b.maxTokens, numTokens = _b.numTokens;
@ -158,28 +161,31 @@ var QwenApi = /** @class */ (function () {
conversationId: conversationId,
parentMessageId: messageId,
text: undefined,
functionCall: undefined,
conversation: []
};
this._completionParams.input = { messages: messages };
completionParams.input = { messages: messages };
responseP = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
var url, headers, body, res, reason, msg, error, response, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
var _a, _b, _c, _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
url = "".concat(this._apiBaseUrl, "/services/aigc/text-generation/generation");
headers = {
'Content-Type': 'application/json',
Authorization: "Bearer ".concat(this._apiKey)
};
body = __assign(__assign({}, this._completionParams), completionParams);
body = completionParams;
if (this._debug) {
console.log(JSON.stringify(body));
}
if (this._debug) {
console.log("sendMessage (".concat(numTokens, " tokens)"), body);
}
_a.label = 1;
_f.label = 1;
case 1:
_a.trys.push([1, 6, , 7]);
_f.trys.push([1, 6, , 7]);
return [4 /*yield*/, this._fetch(url, {
method: 'POST',
headers: headers,
@ -187,11 +193,11 @@ var QwenApi = /** @class */ (function () {
signal: abortSignal
})];
case 2:
res = _a.sent();
res = _f.sent();
if (!!res.ok) return [3 /*break*/, 4];
return [4 /*yield*/, res.text()];
case 3:
reason = _a.sent();
reason = _f.sent();
msg = "Qwen error ".concat(res.status || res.statusText, ": ").concat(reason);
error = new types.ChatGPTError(msg, { cause: res });
error.statusCode = res.status;
@ -199,18 +205,22 @@ var QwenApi = /** @class */ (function () {
return [2 /*return*/, reject(error)];
case 4: return [4 /*yield*/, res.json()];
case 5:
response = _a.sent();
response = _f.sent();
if (this._debug) {
console.log(response);
}
if (((_e = (_d = (_c = (_b = (_a = response.output) === null || _a === void 0 ? void 0 : _a.choices) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.tool_calls) === null || _e === void 0 ? void 0 : _e.length) > 0) {
// function call result
result.functionCall = response.output.choices[0].message.tool_calls[0].function;
}
if (response === null || response === void 0 ? void 0 : response.request_id) {
result.id = response.request_id;
}
result.detail = response;
result.text = response.output.text;
result.text = response.output.choices[0].message.content;
return [2 /*return*/, resolve(result)];
case 6:
err_1 = _a.sent();
err_1 = _f.sent();
return [2 /*return*/, reject(err_1)];
case 7: return [2 /*return*/];
}
@ -278,7 +288,8 @@ var QwenApi = /** @class */ (function () {
? messages.concat([
{
role: role,
content: text
content: text,
name: role === 'tool' ? opts.name : undefined
}
])
: messages;
@ -337,7 +348,8 @@ var QwenApi = /** @class */ (function () {
nextMessages = nextMessages.slice(0, systemMessageOffset).concat(__spreadArray([
{
role: parentMessageRole,
content: parentMessage.text
content: parentMessage.functionCall ? parentMessage.functionCall.arguments : parentMessage.text,
name: parentMessage.functionCall ? parentMessage.functionCall.name : undefined
}
], nextMessages.slice(systemMessageOffset), true));
parentMessageId = parentMessage.parentMessageId;

View file

@ -7,11 +7,12 @@ import * as tokenizer from './tokenizer'
import * as types from './types'
import globalFetch from 'node-fetch'
import {qwen, Role} from "./types";
import {openai} from "../openai/types";
const CHATGPT_MODEL = 'qwen-turbo' // qwen-plus
const USER_LABEL_DEFAULT = 'User'
const ASSISTANT_LABEL_DEFAULT = '义千问'
const ASSISTANT_LABEL_DEFAULT = '义千问'
export class QwenApi {
protected _apiKey: string
@ -64,7 +65,7 @@ export class QwenApi {
temperature: 1.0,
seed: 114514,
enable_search: true,
result_format: "text",
result_format: "message",
incremental_output: false,
...parameters
},
@ -75,7 +76,7 @@ export class QwenApi {
if (this._systemMessage === undefined) {
const currentDate = new Date().toISOString().split('T')[0]
this._systemMessage = `You are ChatGPT, a large language model trained by Qwen. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: ${currentDate}`
this._systemMessage = `You are Qwen, a large language model trained by Alibaba Cloud. Answer as concisely as possible.\nCurrent date: ${currentDate}`
}
this._getMessageById = getMessageById ?? this._defaultGetMessageById
@ -120,7 +121,7 @@ export class QwenApi {
* @param opts.timeoutMs - Optional timeout in milliseconds (defaults to no timeout)
* @param opts.onProgress - Optional callback which will be invoked every time the partial response is updated
* @param opts.abortSignal - Optional callback used to abort the underlying `fetch` call using an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
* @param completionParams - Optional overrides to send to the [Qwen chat completion API](https://platform.openai.com/docs/api-reference/chat/create). Options like `temperature` and `presence_penalty` can be tweaked to change the personality of the assistant.
* @param opts.completionParams - Optional overrides to send to the [Qwen chat completion API](https://platform.openai.com/docs/api-reference/chat/create). Options like `temperature` and `presence_penalty` can be tweaked to change the personality of the assistant.
*
* @returns The response from ChatGPT
*/
@ -129,7 +130,7 @@ export class QwenApi {
opts: types.SendMessageOptions = {},
role: Role = 'user',
): Promise<types.ChatMessage> {
const {
let {
parentMessageId,
messageId = uuidv4(),
timeoutMs,
@ -155,21 +156,30 @@ export class QwenApi {
const latestQuestion = message
let parameters = Object.assign(
this._completionParams.parameters,
completionParams.parameters
)
completionParams = Object.assign(this._completionParams, completionParams)
completionParams.parameters = parameters
const { messages, maxTokens, numTokens } = await this._buildMessages(
text,
role,
opts,
completionParams
)
console.log(`maxTokens: ${maxTokens}, numTokens: ${numTokens}`)
const result: types.ChatMessage = {
const result: types.ChatMessage & { conversation: qwen.ChatCompletionRequestMessage[] } = {
role: 'assistant',
id: uuidv4(),
conversationId,
parentMessageId: messageId,
text: undefined,
functionCall: undefined,
conversation: []
}
this._completionParams.input = { messages }
completionParams.input = { messages }
const responseP = new Promise<types.ChatMessage>(
async (resolve, reject) => {
const url = `${this._apiBaseUrl}/services/aigc/text-generation/generation`
@ -177,10 +187,7 @@ export class QwenApi {
'Content-Type': 'application/json',
Authorization: `Bearer ${this._apiKey}`
}
const body = {
...this._completionParams,
...completionParams
}
const body = completionParams
if (this._debug) {
console.log(JSON.stringify(body))
}
@ -212,12 +219,15 @@ export class QwenApi {
if (this._debug) {
console.log(response)
}
if (response.output?.choices?.[0]?.message?.tool_calls?.length > 0) {
// function call result
result.functionCall = response.output.choices[0].message.tool_calls[0].function
}
if (response?.request_id) {
result.id = response.request_id
}
result.detail = response
result.text = response.output.text
result.text = response.output.choices[0].message.content
return resolve(result)
} catch (err) {
return reject(err)
@ -283,7 +293,8 @@ export class QwenApi {
? messages.concat([
{
role,
content: text
content: text,
name: role === 'tool' ? opts.name : undefined
}
])
: messages
@ -338,7 +349,8 @@ export class QwenApi {
nextMessages = nextMessages.slice(0, systemMessageOffset).concat([
{
role: parentMessageRole,
content: parentMessage.text
content: parentMessage.functionCall ? parentMessage.functionCall.arguments : parentMessage.text,
name: parentMessage.functionCall ? parentMessage.functionCall.name : undefined
},
...nextMessages.slice(systemMessageOffset)
])

View file

@ -1,80 +1,82 @@
import Keyv from 'keyv'
import {openai} from "../openai/types";
export type Role = 'user' | 'assistant' | 'system'
export type Role = 'user' | 'assistant' | 'system' | 'tool'
export type FetchFn = typeof fetch
export type QWenAPIOptions = {
apiKey: string
apiKey: string
/** @defaultValue `'https://dashscope.aliyuncs.com/api/v1'` **/
apiBaseUrl?: string
/** @defaultValue `'https://dashscope.aliyuncs.com/api/v1'` **/
apiBaseUrl?: string
apiOrg?: string
apiOrg?: string
/** @defaultValue `false` **/
debug?: boolean
/** @defaultValue `false` **/
debug?: boolean
completionParams?: Partial<
Omit<qwen.CreateChatCompletionRequest, 'messages' | 'n' | 'stream'>
>
parameters?: qwen.QWenParameters,
completionParams?: Partial<
Omit<qwen.CreateChatCompletionRequest, 'messages' | 'n' | 'stream'>
>
parameters?: qwen.QWenParameters,
systemMessage?: string
systemMessage?: string
messageStore?: Keyv
getMessageById?: GetMessageByIdFunction
upsertMessage?: UpsertMessageFunction
messageStore?: Keyv
getMessageById?: GetMessageByIdFunction
upsertMessage?: UpsertMessageFunction
fetch?: FetchFn
fetch?: FetchFn
}
export type SendMessageOptions = {
/**
* function role name
*/
name?: string
messageId?: string
stream?: boolean
systemMessage?: string
parentMessageId?: string
conversationId?: string
timeoutMs?: number
onProgress?: (partialResponse: ChatMessage) => void
abortSignal?: AbortSignal
completionParams?: Partial<
Omit<qwen.CreateChatCompletionRequest, 'messages' | 'n' | 'stream'>
>
/**
* function role name
*/
name?: string
messageId?: string
stream?: boolean
systemMessage?: string
parentMessageId?: string
conversationId?: string
timeoutMs?: number
onProgress?: (partialResponse: ChatMessage) => void
abortSignal?: AbortSignal
completionParams?: Partial<
Omit<qwen.CreateChatCompletionRequest, 'messages' | 'n' | 'stream'>
>
}
export type MessageActionType = 'next' | 'variant'
export type SendMessageBrowserOptions = {
conversationId?: string
parentMessageId?: string
messageId?: string
action?: MessageActionType
timeoutMs?: number
onProgress?: (partialResponse: ChatMessage) => void
abortSignal?: AbortSignal
conversationId?: string
parentMessageId?: string
messageId?: string
action?: MessageActionType
timeoutMs?: number
onProgress?: (partialResponse: ChatMessage) => void
abortSignal?: AbortSignal
}
export interface ChatMessage {
id: string
text: string
role: Role
parentMessageId?: string
conversationId?: string
detail?:
| qwen.CreateChatCompletionResponse
| CreateChatCompletionStreamResponse
id: string
text: string
role: Role
parentMessageId?: string
conversationId?: string
detail?:
| qwen.CreateChatCompletionResponse
| CreateChatCompletionStreamResponse
functionCall?: qwen.FunctionCall
}
export class ChatGPTError extends Error {
statusCode?: number
statusText?: string
isFinal?: boolean
accountId?: string
statusCode?: number
statusText?: string
isFinal?: boolean
accountId?: string
}
/** Returns a chat message from a store by it's ID (or null if not found). */
@ -84,230 +86,289 @@ export type GetMessageByIdFunction = (id: string) => Promise<ChatMessage>
export type UpsertMessageFunction = (message: ChatMessage) => Promise<void>
export interface CreateChatCompletionStreamResponse
extends openai.CreateChatCompletionDeltaResponse {
usage: CreateCompletionStreamResponseUsage
extends openai.CreateChatCompletionDeltaResponse {
usage: CreateCompletionStreamResponseUsage
}
export interface CreateCompletionStreamResponseUsage
extends openai.CreateCompletionResponseUsage {
estimated: true
extends openai.CreateCompletionResponseUsage {
estimated: true
}
/**
* https://chat.openapi.com/backend-api/conversation
*/
export type ConversationJSONBody = {
/**
* The action to take
*/
action: string
/**
* The action to take
*/
action: string
/**
* The ID of the conversation
*/
conversation_id?: string
/**
* The ID of the conversation
*/
conversation_id?: string
/**
* Prompts to provide
*/
messages: Prompt[]
/**
* Prompts to provide
*/
messages: Prompt[]
/**
* The model to use
*/
model: string
/**
* The model to use
*/
model: string
/**
* The parent message ID
*/
parent_message_id: string
/**
* The parent message ID
*/
parent_message_id: string
}
export type Prompt = {
/**
* The content of the prompt
*/
content: PromptContent
/**
* The content of the prompt
*/
content: PromptContent
/**
* The ID of the prompt
*/
id: string
/**
* The ID of the prompt
*/
id: string
/**
* The role played in the prompt
*/
role: Role
/**
* The role played in the prompt
*/
role: Role
}
export type ContentType = 'text'
export type PromptContent = {
/**
* The content type of the prompt
*/
content_type: ContentType
/**
* The content type of the prompt
*/
content_type: ContentType
/**
* The parts to the prompt
*/
parts: string[]
/**
* The parts to the prompt
*/
parts: string[]
}
export type ConversationResponseEvent = {
message?: Message
conversation_id?: string
error?: string | null
message?: Message
conversation_id?: string
error?: string | null
}
export type Message = {
id: string
content: MessageContent
role: Role
user: string | null
create_time: string | null
update_time: string | null
end_turn: null
weight: number
recipient: string
metadata: MessageMetadata
id: string
content: MessageContent
role: Role
user: string | null
create_time: string | null
update_time: string | null
end_turn: null
weight: number
recipient: string
metadata: MessageMetadata
}
export type MessageContent = {
content_type: string
parts: string[]
content_type: string
parts: string[]
}
export type MessageMetadata = any
export namespace qwen {
export interface CreateChatCompletionDeltaResponse {
id: string
object: 'chat.completion.chunk'
created: number
model: string
choices: [
{
delta: {
role: Role
content?: string,
function_call?: {name: string, arguments: string}
}
index: number
finish_reason: string | null
}
]
}
export interface CreateChatCompletionDeltaResponse {
id: string
object: 'chat.completion.chunk'
created: number
model: string
choices: [
{
delta: {
role: Role
content?: string,
function_call?: { name: string, arguments: string }
}
index: number
finish_reason: string | null
}
]
}
/**
*
* @export
* @interface ChatCompletionRequestMessage
*/
export interface ChatCompletionRequestMessage {
/**
* The role of the author of this message.
* @type {string}
* @memberof ChatCompletionRequestMessage
*/
role: ChatCompletionRequestMessageRoleEnum
/**
* The contents of the message
* @type {string}
* @memberof ChatCompletionRequestMessage
*/
content: string
/**
*
* @export
* @interface ChatCompletionRequestMessage
* role为tool表示当前message为function_call的调用结果name是function的名称response中的tool_calls[i].function.name参数保持一致content为function的输出
*/
export interface ChatCompletionRequestMessage {
/**
* The role of the author of this message.
* @type {string}
* @memberof ChatCompletionRequestMessage
*/
role: ChatCompletionRequestMessageRoleEnum
/**
* The contents of the message
* @type {string}
* @memberof ChatCompletionRequestMessage
*/
content: string
}
name?: string
}
export declare const ChatCompletionRequestMessageRoleEnum: {
readonly System: 'system'
readonly User: 'user'
readonly Assistant: 'assistant'
}
export declare type ChatCompletionRequestMessageRoleEnum =
(typeof ChatCompletionRequestMessageRoleEnum)[keyof typeof ChatCompletionRequestMessageRoleEnum]
export interface FunctionCall {
name: string
arguments: string
}
export declare const ChatCompletionRequestMessageRoleEnum: {
readonly System: 'system'
readonly User: 'user'
readonly Assistant: 'assistant'
readonly Tool: 'tool'
}
export declare type ChatCompletionRequestMessageRoleEnum =
(typeof ChatCompletionRequestMessageRoleEnum)[keyof typeof ChatCompletionRequestMessageRoleEnum]
export interface QWenInput {
messages: Array<ChatCompletionRequestMessage>
}
export interface QWenInput {
messages: Array<ChatCompletionRequestMessage>
}
export interface QWenParameters {
result_format: string
top_p: number
top_k: number
seed: number
temperature: number
enable_search: boolean
incremental_output: boolean
}
export interface QWenParameters {
result_format: "text" | "message"
top_p: number
top_k: number
seed: number
temperature: number
enable_search: boolean
incremental_output: boolean
tools: Tools[]
}
export interface Tools {
type: "function"
function: QwenFunction
}
export interface QwenFunction {
name: string
description: string
parameters: QwenFunctionParameters
}
export interface QwenFunctionParameters {
type: "object"
properties: Properties;
required?: string[]
}
interface Properties {
[key: string]: Property;
}
interface Property {
type: string;
description?: string;
enum?: string[];
}
/**
*
* @export
* @interface CreateChatCompletionRequest
*/
export interface CreateChatCompletionRequest {
/**
* ID of the model to use. Currently, only `gpt-3.5-turbo` and `gpt-3.5-turbo-0301` are supported.
* @type {string}
* @memberof CreateChatCompletionRequest
*/
model: string
/**
* The messages to generate chat completions for, in the [chat format](/docs/guides/chat/introduction).
* @type {Array<ChatCompletionRequestMessage>}
* @memberof CreateChatCompletionRequest
*/
input?: QWenInput
parameters: QWenParameters
}
/**
*
* @export
* @interface CreateChatCompletionResponse
*/
export interface CreateChatCompletionResponse {
/**
*
* @export
* @interface CreateChatCompletionRequest
* @type {string}
* @memberof CreateChatCompletionResponse
*/
export interface CreateChatCompletionRequest {
/**
* ID of the model to use. Currently, only `gpt-3.5-turbo` and `gpt-3.5-turbo-0301` are supported.
* @type {string}
* @memberof CreateChatCompletionRequest
*/
model: string
/**
* The messages to generate chat completions for, in the [chat format](/docs/guides/chat/introduction).
* @type {Array<ChatCompletionRequestMessage>}
* @memberof CreateChatCompletionRequest
*/
input?: QWenInput
request_id: string
/**
*
* @type {QWenOutput}
* @memberof CreateChatCompletionResponse
*/
output: QWenOutput
/**
*
* @type {CreateCompletionResponseUsage}
* @memberof CreateChatCompletionResponse
*/
usage?: CreateCompletionResponseUsage
}
parameters: QWenParameters
}
export interface QWenOutput {
finish_reason: string
text?: string
choices?: Choice[]
}
export interface Choice {
finish_reason: string
message: ResponseMessage
}
export interface ResponseMessage {
role: Role
content: string
tool_calls: ToolCall[]
}
export interface ToolCall {
function: FunctionCall
type: "function"
}
/**
*
* @export
* @interface CreateCompletionResponseUsage
*/
export interface CreateCompletionResponseUsage {
/**
*
* @export
* @interface CreateChatCompletionResponse
* @type {number}
* @memberof CreateCompletionResponseUsage
*/
export interface CreateChatCompletionResponse {
/**
*
* @type {string}
* @memberof CreateChatCompletionResponse
*/
request_id: string
/**
*
* @type {QWenOutput}
* @memberof CreateChatCompletionResponse
*/
output: QWenOutput
/**
*
* @type {CreateCompletionResponseUsage}
* @memberof CreateChatCompletionResponse
*/
usage?: CreateCompletionResponseUsage
}
export interface QWenOutput {
finish_reason: string
text: string
}
input_tokens: number
/**
*
* @export
* @interface CreateCompletionResponseUsage
* @type {number}
* @memberof CreateCompletionResponseUsage
*/
export interface CreateCompletionResponseUsage {
/**
*
* @type {number}
* @memberof CreateCompletionResponseUsage
*/
input_tokens: number
/**
*
* @type {number}
* @memberof CreateCompletionResponseUsage
*/
output_tokens: number
}
output_tokens: number
}
}

View file

@ -176,7 +176,7 @@ export class ChatGPTAPI {
completionParams
)
console.log(`maxTokens: ${maxTokens}, numTokens: ${numTokens}`)
const result: types.ChatMessage & { conversation: openai.ChatCompletionRequestMessage[] }= {
const result: types.ChatMessage & { conversation: openai.ChatCompletionRequestMessage[] } = {
role: 'assistant',
id: uuidv4(),
conversationId,