Spaces:
Runtime error
Runtime error
fix: added proper types when interacting with toOpenAi
Browse files- src/components/GameCreator.tsx +16 -1
- src/services/api/index.ts +12 -2
- src/services/api/openai.ts +1 -1
src/components/GameCreator.tsx
CHANGED
@@ -279,11 +279,25 @@ export default function GameCreator() {
|
|
279 |
try {
|
280 |
setLoading(true);
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
const client = createClient(
|
283 |
formObject.openAIAPIKey as string
|
284 |
);
|
285 |
const answer = await toOpenAI({
|
286 |
-
|
|
|
|
|
|
|
|
|
|
|
287 |
client,
|
288 |
});
|
289 |
|
@@ -376,6 +390,7 @@ export default function GameCreator() {
|
|
376 |
Run
|
377 |
</Typography>
|
378 |
</Button>
|
|
|
379 |
</Stack>
|
380 |
</Stack>
|
381 |
|
|
|
279 |
try {
|
280 |
setLoading(true);
|
281 |
|
282 |
+
const {
|
283 |
+
command,
|
284 |
+
prompt,
|
285 |
+
temperature,
|
286 |
+
template,
|
287 |
+
model,
|
288 |
+
maxTokens,
|
289 |
+
} = formObject;
|
290 |
+
|
291 |
const client = createClient(
|
292 |
formObject.openAIAPIKey as string
|
293 |
);
|
294 |
const answer = await toOpenAI({
|
295 |
+
command: command as string,
|
296 |
+
prompt: prompt as string,
|
297 |
+
temperature: temperature as string,
|
298 |
+
template: template as string,
|
299 |
+
model: model as string,
|
300 |
+
maxTokens: maxTokens as string,
|
301 |
client,
|
302 |
});
|
303 |
|
|
|
390 |
Run
|
391 |
</Typography>
|
392 |
</Button>
|
393 |
+
<Box sx={{ flex: 1 }} />
|
394 |
</Stack>
|
395 |
</Stack>
|
396 |
|
src/services/api/index.ts
CHANGED
@@ -1,8 +1,18 @@
|
|
1 |
-
import { ChatCompletionRequestMessage } from "openai";
|
2 |
import { nanoid } from "nanoid";
|
3 |
import { extractCode, miniPrompt } from "@/utils/prompt";
|
4 |
import { systemMessage } from "@/constants";
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
export async function toOpenAI({
|
7 |
command = "CREATE_GAME",
|
8 |
prompt = "extend the code",
|
@@ -11,7 +21,7 @@ export async function toOpenAI({
|
|
11 |
model = "gpt-3.5-turbo",
|
12 |
maxTokens = "2048",
|
13 |
client = null,
|
14 |
-
}) {
|
15 |
if (client === null) {
|
16 |
throw new Error("OpenAI client is not defined");
|
17 |
}
|
|
|
1 |
+
import { ChatCompletionRequestMessage, OpenAIApi } from "openai";
|
2 |
import { nanoid } from "nanoid";
|
3 |
import { extractCode, miniPrompt } from "@/utils/prompt";
|
4 |
import { systemMessage } from "@/constants";
|
5 |
|
6 |
+
interface ToOpenAIProps {
|
7 |
+
command: string;
|
8 |
+
prompt: string;
|
9 |
+
temperature: string;
|
10 |
+
template: string;
|
11 |
+
model: string;
|
12 |
+
maxTokens: string;
|
13 |
+
client: OpenAIApi | null;
|
14 |
+
}
|
15 |
+
|
16 |
export async function toOpenAI({
|
17 |
command = "CREATE_GAME",
|
18 |
prompt = "extend the code",
|
|
|
21 |
model = "gpt-3.5-turbo",
|
22 |
maxTokens = "2048",
|
23 |
client = null,
|
24 |
+
}: ToOpenAIProps) {
|
25 |
if (client === null) {
|
26 |
throw new Error("OpenAI client is not defined");
|
27 |
}
|
src/services/api/openai.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import { Configuration, OpenAIApi } from "openai";
|
2 |
|
3 |
-
export const createClient = (apiKey: string) => {
|
4 |
return new OpenAIApi(new Configuration({ apiKey }));
|
5 |
};
|
|
|
1 |
import { Configuration, OpenAIApi } from "openai";
|
2 |
|
3 |
+
export const createClient = (apiKey: string): OpenAIApi => {
|
4 |
return new OpenAIApi(new Configuration({ apiKey }));
|
5 |
};
|