Skip to content

Commit aab1df1

Browse files
committed
Fix: issues with endpoints
1 parent 9f925be commit aab1df1

File tree

5 files changed

+55
-88
lines changed

5 files changed

+55
-88
lines changed

admin/src/api/completions/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { request } from '@strapi/helper-plugin';
22

33
const completions = {
4-
create: async ({ model, prompt, temperature, maxTokens }) => {
4+
create: async ({ model, messages, temperature, maxTokens }) => {
55
const data = await request(`/open-ai/completions`, {
66
method: 'POST',
7-
body: { model, prompt, temperature, maxTokens },
7+
body: { model, messages, temperature, maxTokens },
88
});
99
return data;
1010
},

admin/src/components/CMEditView/RightLinksCompo/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ const RightLinksCompo = () => {
126126

127127
const handlePromptSubmit = () => {
128128
if (model && prompt && temperature && maxTokens) {
129+
const messages = [{ role: 'user', content: prompt }];
129130
setGenerateCompletionText('Generating completion...');
130131
completionAPI
131-
.create({ model, prompt, temperature, maxTokens })
132+
.create({ model, messages, temperature, maxTokens })
132133
.then((data) => {
133-
console.log(data);
134134
setCompletion(data?.choices[0]?.text.trim());
135135
setFinishReason(data?.choices[0]?.finish_reason);
136+
})
137+
.finally(() => {
136138
setGenerateCompletionText('Generate');
137139
});
138140
}
@@ -242,10 +244,7 @@ const RightLinksCompo = () => {
242244
paddingLeft={4}
243245
background="neutral0"
244246
>
245-
<Button
246-
paddingTop={4}
247-
onClick={() => handlePromptSubmit()}
248-
>
247+
<Button onClick={() => handlePromptSubmit()}>
249248
{generateCompletionText}
250249
</Button>
251250
</Box>

server/controllers/completions.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module.exports = ({ strapi }) => {
44
const completionService = strapi.plugins['open-ai'].services.completions;
55

66
const createCompletion = async (ctx) => {
7-
const { model, prompt, temperature, maxTokens } = ctx.request.body;
7+
const { model, messages, temperature, maxTokens } = ctx.request.body;
88

9-
if (model && prompt && temperature && maxTokens) {
9+
if (model && messages && temperature && maxTokens) {
1010
try {
1111
return completionService.createCompletion({
1212
model,
13-
prompt,
13+
messages,
1414
temperature,
1515
maxTokens,
1616
});
@@ -19,7 +19,7 @@ module.exports = ({ strapi }) => {
1919
ctx.throw(500, err);
2020
}
2121
}
22-
return ctx.throw(400, 'Either the prompt, temperature, model or maxToken parameter is missing');
22+
return ctx.throw(400, 'Either the messages, temperature, model or maxToken parameter is missing');
2323
};
2424

2525
return {

server/services/completions.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@
33
const fetch = require('node-fetch');
44

55
module.exports = ({ strapi }) => {
6-
const createCompletion = async ({ model, prompt, temperature, maxTokens }) => {
6+
const createCompletion = async ({
7+
model,
8+
messages,
9+
temperature,
10+
maxTokens,
11+
}) => {
712
try {
8-
const response = await fetch(`https://api.openai.com/v1/completions`, {
9-
method: 'POST',
10-
headers: {
11-
'Content-Type': 'application/json',
12-
Authorization: `Bearer ${strapi
13-
.plugin('open-ai')
14-
.config('API_TOKEN')}`,
15-
},
16-
body: JSON.stringify({ model, prompt, temperature, max_tokens: maxTokens }),
17-
});
13+
const response = await fetch(
14+
`https://api.openai.com/v1/chat/completions`,
15+
{
16+
method: 'POST',
17+
headers: {
18+
'Content-Type': 'application/json',
19+
Authorization: `Bearer ${strapi
20+
.plugin('open-ai')
21+
.config('API_TOKEN')}`,
22+
},
23+
body: JSON.stringify({
24+
model,
25+
messages,
26+
temperature,
27+
max_tokens: maxTokens,
28+
}),
29+
}
30+
);
1831

1932
const res = await response.json();
2033
return res;

server/services/settings.js

+20-65
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,27 @@ module.exports = ({ strapi }) => {
1717
temperature: 1,
1818
maxTokens: 16,
1919
models: [
20-
'babbage',
21-
'ada',
22-
'davinci',
20+
'dall-e-3',
21+
'whisper-1',
22+
'davinci-002',
23+
'babbage-002',
24+
'dall-e-2',
25+
'gpt-3.5-turbo-16k',
26+
'tts-1-hd-1106',
27+
'tts-1-hd',
28+
'gpt-3.5-turbo-1106',
29+
'gpt-3.5-turbo-instruct-0914',
30+
'gpt-3.5-turbo-instruct',
31+
'tts-1',
32+
'gpt-3.5-turbo-0301',
33+
'tts-1-1106',
34+
'gpt-3.5-turbo-0125',
35+
'text-embedding-3-large',
36+
'gpt-3.5-turbo',
37+
'text-embedding-3-small',
38+
'gpt-3.5-turbo-0613',
2339
'text-embedding-ada-002',
24-
'babbage-code-search-code',
25-
'text-similarity-babbage-001',
26-
'text-davinci-001',
27-
'curie-instruct-beta',
28-
'babbage-code-search-text',
29-
'babbage-similarity',
30-
'curie-search-query',
31-
'code-search-babbage-text-001',
32-
'code-cushman-001',
33-
'code-search-babbage-code-001',
34-
'code-davinci-002',
35-
'text-ada-001',
36-
'text-similarity-ada-001',
37-
'text-davinci-insert-002',
38-
'ada-code-search-code',
39-
'text-davinci-002',
40-
'ada-similarity',
41-
'text-davinci-003',
42-
'code-search-ada-text-001',
43-
'text-search-ada-query-001',
44-
'text-curie-001',
45-
'text-davinci-edit-001',
46-
'davinci-search-document',
47-
'ada-code-search-text',
48-
'text-search-ada-doc-001',
49-
'code-davinci-edit-001',
50-
'davinci-instruct-beta',
51-
'text-babbage-001',
52-
'text-similarity-curie-001',
53-
'code-search-ada-code-001',
54-
'ada-search-query',
55-
'text-search-davinci-query-001',
56-
'curie-similarity',
57-
'davinci-search-query',
58-
'text-davinci-insert-001',
59-
'babbage-search-document',
60-
'ada-search-document',
61-
'curie',
62-
'text-search-babbage-doc-001',
63-
'text-search-curie-doc-001',
64-
'text-search-curie-query-001',
65-
'babbage-search-query',
66-
'text-search-davinci-doc-001',
67-
'text-search-babbage-query-001',
68-
'curie-search-document',
69-
'text-similarity-davinci-001',
70-
'audio-transcribe-001',
71-
'davinci-similarity',
72-
'cushman:2020-05-03',
73-
'ada:2020-05-03',
74-
'babbage:2020-05-03',
75-
'curie:2020-05-03',
76-
'davinci:2020-05-03',
77-
'if-davinci-v2',
78-
'if-curie-v2',
79-
'if-davinci:3.0.0',
80-
'davinci-if:3.0.0',
81-
'davinci-instruct-beta:2.0.0',
82-
'text-ada:001',
83-
'text-davinci:001',
84-
'text-curie:001',
85-
'text-babbage:001',
40+
'gpt-3.5-turbo-16k-0613',
8641
],
8742
};
8843
await pluginStore.set({ key: 'settings', value });

0 commit comments

Comments
 (0)