mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: add example
This commit is contained in:
parent
479028584e
commit
aa2ac7b5d3
2 changed files with 53 additions and 26 deletions
29
client/OpenAILikeClient.js
Normal file
29
client/OpenAILikeClient.js
Normal 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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue