Skip to content

Commit 7fc6da6

Browse files
Merge branch 'azure_model' into dev
2 parents 47a03fe + 1d4c415 commit 7fc6da6

File tree

6 files changed

+31
-159
lines changed

6 files changed

+31
-159
lines changed

src/assets/models-list.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ const azure_models: {
9191
}, {
9292
value: 'text-embedding-ada-002',
9393
name: 'text-embedding-ada-002',
94-
}, {
95-
value: 'text-embedding-ada-002',
96-
name: 'text-embedding-ada-002',
9794
}]
9895

9996
export {

src/chat.completion/ChatCompletionHandler.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { ChatCompletionMessage } from '@/openai/type/chat.completion.messag
66
import { handleChatCompletionPrecondition } from '@/openai/handler/ChatHandler'
77
import openAIServices from '@/openai/logic/services'
88
import ChatCompletionParser from '@/openai/parser/ChatCompletionParser'
9-
import AzureChatCompletionParser from '@/openai/parser/AzureChatCompletionParser'
109
import ChatCompletionParserByGroq from '@/groq/parser/ChatCompletionParser'
1110
import useEditorStore from '@/store/editor-store'
1211
import handleChatVisionPrecondition from '@/openai/handler/VisionHandler'
@@ -161,25 +160,13 @@ class ChatCompletionHandler {
161160
if (chatCompletionResponse.data !== null) {
162161
let gptContent = ''
163162

164-
const platform = window.localStorage.getItem('platform') ?? 'openai'
165-
if (platform === 'openai') {
166-
parserResult = await ChatCompletionParser(chatCompletionResponse.data!, (text) => {
167-
gptContent += text
168-
resultCallback(text)
169-
}, (tool_call_id, fname, args, isDone) => {
170-
needFunctionResult = true
171-
functionCallingResultCallback(tool_call_id, fname, args, isDone)
172-
})
173-
}
174-
else {
175-
parserResult = await AzureChatCompletionParser(chatCompletionResponse.data!, (text) => {
176-
gptContent += text
177-
resultCallback(text)
178-
}, (tool_call_id, fname, args, isDone) => {
179-
needFunctionResult = true
180-
functionCallingResultCallback(tool_call_id, fname, args, isDone)
181-
})
182-
}
163+
parserResult = await ChatCompletionParser(chatCompletionResponse.data!, (text) => {
164+
gptContent += text
165+
resultCallback(text)
166+
}, (tool_call_id, fname, args, isDone) => {
167+
needFunctionResult = true
168+
functionCallingResultCallback(tool_call_id, fname, args, isDone)
169+
})
183170

184171
if (parserResult)
185172
markResult = await this.markMessageCompletedAsync(messageInfo, gptContent)
@@ -213,17 +200,9 @@ class ChatCompletionHandler {
213200

214201
let title = ''
215202

216-
const platform = window.localStorage.getItem('platform') ?? 'openai'
217-
if (platform === 'openai') {
218-
await ChatCompletionParser(chatCompletionResponse.data!, (text) => {
219-
title += text
220-
}, () => { })
221-
}
222-
else {
223-
await AzureChatCompletionParser(chatCompletionResponse.data!, (text) => {
224-
title += text
225-
}, () => { })
226-
}
203+
await ChatCompletionParser(chatCompletionResponse.data!, (text) => {
204+
title += text
205+
}, () => { })
227206
this.updateConversationTitleByIdAsync(title, messageInfo.conversation_id)
228207
}
229208

src/openai/logic/services.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,26 @@ import chatFunctionCallingController from '@/chat.function.calling/ChatFunctionC
44
import type { ChatCompletionMessage } from '@/openai/type/chat.completion.message'
55
import type { OpenAIPayloadInfo } from '@/openai/type/openai.payload'
66
import type { OpenAIRequestResult } from '@/openai/type/openai.response.result'
7-
import { apiKey, azureApiKey, azureBaseURL, baseURL, gptModel, temperature, topP } from '@/store/localstorage'
7+
import { apiKey, azureApiKey, azureBaseURL, azureModel, baseURL, gptModel, temperature, topP } from '@/store/localstorage'
88

99
class OpenAIServices {
1010
private controller = new AbortController()
1111

1212
private async getOpenAIPayload(): Promise<OpenAIPayloadInfo | null> {
13-
return {
14-
apikey: apiKey.value,
15-
model: gptModel.value,
16-
} as OpenAIPayloadInfo
13+
const platform = window.localStorage.getItem('platform') ?? 'openai'
14+
15+
if (platform === 'openai') {
16+
return {
17+
apikey: apiKey.value,
18+
model: gptModel.value,
19+
} as OpenAIPayloadInfo
20+
}
21+
else {
22+
return {
23+
apikey: azureApiKey.value,
24+
model: azureModel.value,
25+
} as OpenAIPayloadInfo
26+
}
1727
}
1828

1929
public cancelRequest() {
@@ -79,26 +89,17 @@ class OpenAIServices {
7989
const fetchPayload = {
8090
headers: {
8191
'Content-Type': 'application/json',
82-
'Authorization': '',
83-
'api-key': '',
92+
'Authorization': openAIPayload.apikey,
93+
'api-key': openAIPayload.apikey,
8494
},
8595
method: 'POST',
8696
body: fetchBody,
8797
signal,
8898
}
8999

90-
let url = ''
91-
92100
const platform = window.localStorage.getItem('platform') ?? 'openai'
93101

94-
if (platform === 'openai') {
95-
url = `${baseURL.value}chat/completions`
96-
fetchPayload.headers.Authorization = `Bearer ${openAIPayload?.apikey}`
97-
}
98-
else {
99-
url = `${azureBaseURL.value}openai/deployments/gpt3-turbo/chat/completions?api-version=2024-02-15-preview`
100-
fetchPayload.headers['api-key'] = azureApiKey.value
101-
}
102+
const url = platform === 'openai' ? `${baseURL.value}chat/completions` : `${azureBaseURL.value}openai/deployments/gpt3-turbo/chat/completions?api-version=2024-02-15-preview`
102103

103104
return new Promise<OpenAIRequestResult>((resolve) => {
104105
fetch(url, fetchPayload)

src/openai/parser/AzureChatCompletionParser.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/openai/parser/ChatCompletionParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ export default async function ChatCompletionParser(response: Response, callback:
3838

3939
const myData = parserStreamText(a.trim())
4040

41-
if (!myData)
41+
if (!myData || !myData.choices || myData.choices.length === 0)
4242
return
4343

44-
isDone = a.startsWith('data: [DONE]') || myData.choices[0].finish_reason === 'stop'
44+
const finish_reason: string = myData.choices[0]?.finish_reason ?? ''
45+
isDone = a.startsWith('data: [DONE]') || (finish_reason === 'stop')
4546

4647
const value = myData.choices[0].delta?.content ?? ''
4748
if (value && value.length > 0)

src/openai/type/azure.completion.chunk.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)