fix: add example

This commit is contained in:
ikechan8370 2024-10-11 23:07:09 +08:00
parent 479028584e
commit aa2ac7b5d3
2 changed files with 53 additions and 26 deletions

View file

@ -0,0 +1,29 @@
import { BaseClient } from './BaseClient.js'
export class OpenAILikeClient extends BaseClient {
constructor (props) {
super(props)
this.model = props.model
this.key = props.key
this.baseUrl = props.baseUrl
this.debug = props.debug
}
async sendMessageRaw (text, opt = {}) {
const messages = await this.getHistory(opt.parentMessageId, opt.conversationId)
const response = await fetch(this.baseUrl, {
method: 'POST',
headers: {
'Content-Type': 'application-json',
Authorization: `Bearer ${this.key}`
},
body: JSON.stringify({
model: this.model,
messages,
stream: false,
...opt.completionParams || {}
})
})
return await response.json()
}
}