@things-factory/codelingua 8.0.0 → 9.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/client/index.ts +0 -0
- package/client/tsconfig.json +0 -13
- package/server/controllers/api-doc-completion.ts +0 -35
- package/server/controllers/chat-completion.ts +0 -28
- package/server/controllers/codereview-completion.ts +0 -36
- package/server/controllers/decipher-code.ts +0 -38
- package/server/controllers/decipher-error-code.ts +0 -38
- package/server/controllers/i18n-completion.ts +0 -29
- package/server/controllers/image-completion.ts +0 -35
- package/server/controllers/index.ts +0 -9
- package/server/controllers/openai-connection.ts +0 -16
- package/server/index.ts +0 -4
- package/server/routes.ts +0 -84
- package/server/service/api-doc-completion/api-doc-completion-resolver.ts +0 -22
- package/server/service/api-doc-completion/api-doc-completion-type.ts +0 -16
- package/server/service/api-doc-completion/index.ts +0 -5
- package/server/service/chat-completion/chat-completion-resolver.ts +0 -21
- package/server/service/chat-completion/chat-completion-type.ts +0 -13
- package/server/service/chat-completion/index.ts +0 -5
- package/server/service/code-decipher/code-decipher-resolver.ts +0 -37
- package/server/service/code-decipher/code-decipher-type.ts +0 -19
- package/server/service/code-decipher/index.ts +0 -5
- package/server/service/i18n-completion/i18n-completion-resolver.ts +0 -21
- package/server/service/i18n-completion/i18n-completion-type.ts +0 -13
- package/server/service/i18n-completion/index.ts +0 -5
- package/server/service/image-completion/image-completion-resolver.ts +0 -21
- package/server/service/image-completion/image-completion-type.ts +0 -19
- package/server/service/image-completion/index.ts +0 -5
- package/server/service/index.ts +0 -27
- package/server/tsconfig.json +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/codelingua",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-beta.3",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@operato/graphql": "^
|
|
31
|
-
"@operato/shell": "^
|
|
32
|
-
"@things-factory/auth-base": "^
|
|
33
|
-
"@things-factory/env": "^8.0.0",
|
|
34
|
-
"@things-factory/shell": "^
|
|
30
|
+
"@operato/graphql": "^9.0.0-beta",
|
|
31
|
+
"@operato/shell": "^9.0.0-beta",
|
|
32
|
+
"@things-factory/auth-base": "^9.0.0-beta.3",
|
|
33
|
+
"@things-factory/env": "^8.0.0-beta.4",
|
|
34
|
+
"@things-factory/shell": "^9.0.0-beta.0",
|
|
35
35
|
"openai": "^3.3.0"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "1d7e0dd4c88f3c3f3bd311c00e4b1d1542d53634"
|
|
38
38
|
}
|
package/client/index.ts
DELETED
|
File without changes
|
package/client/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig-base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"experimentalDecorators": true,
|
|
5
|
-
"skipLibCheck": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"module": "esnext",
|
|
9
|
-
"outDir": "../dist-client",
|
|
10
|
-
"baseUrl": "./"
|
|
11
|
-
},
|
|
12
|
-
"include": ["./**/*"]
|
|
13
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export async function apiDocCompletion({
|
|
4
|
-
code,
|
|
5
|
-
language = 'en-US'
|
|
6
|
-
}: {
|
|
7
|
-
code: string
|
|
8
|
-
language?: string
|
|
9
|
-
}): Promise<string> {
|
|
10
|
-
try {
|
|
11
|
-
const completion = await client.createChatCompletion({
|
|
12
|
-
model: 'gpt-3.5-turbo',
|
|
13
|
-
messages: [
|
|
14
|
-
{
|
|
15
|
-
role: 'system',
|
|
16
|
-
content: `You are an assistant that takes in JavaScript or TypeScript code and generates detailed developer documentation in markdown format.
|
|
17
|
-
And you provides pure and direct data in response to user requests. The responses should contain no additional explanations or details.`
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
role: 'user',
|
|
21
|
-
content: `Here is some code: [${code}]. Can you help generate a detailed explanation and markdown documentation for this code?`
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
role: 'assistant',
|
|
25
|
-
content: `Please generate the documentation according to this locale code "${language}".`
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return completion.data.choices[0].message.content
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error(error)
|
|
33
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export async function chatCompletion({ content }: { content: string }): Promise<string> {
|
|
4
|
-
try {
|
|
5
|
-
const completion = await client.createChatCompletion({
|
|
6
|
-
model: 'gpt-3.5-turbo',
|
|
7
|
-
messages: [
|
|
8
|
-
{
|
|
9
|
-
role: 'system',
|
|
10
|
-
content: `You are an assistant that generates detailed information in response to user requests. And you provides pure and direct data in response to user requests. The responses should contain no additional explanations or details.`
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
role: 'user',
|
|
14
|
-
content
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
role: 'assistant',
|
|
18
|
-
content: 'Sure, please fetch the information in JSON format.'
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
return completion.data.choices[0].message.content
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error(error)
|
|
26
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
const SYSTEM_MESSAGE = `You are an expert software engineer with a deep understanding of multiple programming languages, including Python, JavaScript, Java, and C++. Your role is to analyze, review, and provide insights on code snippets, highlighting potential issues, suggesting improvements, and explaining complex parts of the code. Respond in a clear, concise, and professional manner.
|
|
4
|
-
|
|
5
|
-
Here's the code for analysis:
|
|
6
|
-
|
|
7
|
-
<code snippet>
|
|
8
|
-
|
|
9
|
-
Please provide:
|
|
10
|
-
1. An overall assessment of the code quality.
|
|
11
|
-
2. Identification of any potential bugs or issues.
|
|
12
|
-
3. Suggestions for improving the code.
|
|
13
|
-
4. An explanation of any complex or non-obvious parts of the code.
|
|
14
|
-
`
|
|
15
|
-
|
|
16
|
-
export const codereviewCompletion = async (codeDiff: string): Promise<string> => {
|
|
17
|
-
try {
|
|
18
|
-
const completion = await client.createChatCompletion({
|
|
19
|
-
model: 'gpt-3.5-turbo',
|
|
20
|
-
messages: [
|
|
21
|
-
{
|
|
22
|
-
role: 'system',
|
|
23
|
-
content: SYSTEM_MESSAGE
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
role: 'user',
|
|
27
|
-
content: `Review the following code:\n\n${codeDiff}`
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
})
|
|
31
|
-
return completion.data.choices[0].message.content
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error('Error fetching OpenAI review:', error)
|
|
34
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export async function decipherCode({
|
|
4
|
-
code,
|
|
5
|
-
system,
|
|
6
|
-
language = 'en-US'
|
|
7
|
-
}: {
|
|
8
|
-
code: string
|
|
9
|
-
system?: string
|
|
10
|
-
language?: string
|
|
11
|
-
}): Promise<string> {
|
|
12
|
-
try {
|
|
13
|
-
const completion = await client.createChatCompletion({
|
|
14
|
-
model: 'gpt-3.5-turbo',
|
|
15
|
-
messages: [
|
|
16
|
-
{
|
|
17
|
-
role: 'system',
|
|
18
|
-
content: 'You are a helpful assistant that translates system messages into user-friendly explanations.'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
role: 'user',
|
|
22
|
-
content: system
|
|
23
|
-
? `We received an message from the ${system} system. The message is: ${code}.`
|
|
24
|
-
: `The message is: ${code}.`
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
role: 'system',
|
|
28
|
-
content: `Translate the explanation according to this locale code "${language}".`
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
return completion.data.choices[0].message.content
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(error)
|
|
36
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export async function decipherErrorCode({
|
|
4
|
-
code,
|
|
5
|
-
system,
|
|
6
|
-
language = 'en-US'
|
|
7
|
-
}: {
|
|
8
|
-
code: string
|
|
9
|
-
system?: string
|
|
10
|
-
language?: string
|
|
11
|
-
}): Promise<string> {
|
|
12
|
-
try {
|
|
13
|
-
const completion = await client.createChatCompletion({
|
|
14
|
-
model: 'gpt-3.5-turbo',
|
|
15
|
-
messages: [
|
|
16
|
-
{
|
|
17
|
-
role: 'system',
|
|
18
|
-
content: 'You are a helpful assistant that translates error messages into user-friendly explanations.'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
role: 'user',
|
|
22
|
-
content: system
|
|
23
|
-
? `We received an error from the ${system} system. The error message is: ${code}.`
|
|
24
|
-
: `The error message is: ${code}.`
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
role: 'system',
|
|
28
|
-
content: `Translate the explanation according to this locale code "${language}".`
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
return completion.data.choices[0].message.content
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(error)
|
|
36
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export async function i18nCompletion({ json }: { json: string }): Promise<string> {
|
|
4
|
-
try {
|
|
5
|
-
const completion = await client.createChatCompletion({
|
|
6
|
-
model: 'gpt-3.5-turbo',
|
|
7
|
-
messages: [
|
|
8
|
-
{
|
|
9
|
-
role: 'system',
|
|
10
|
-
content: `You are an assistant that takes a JSON file of key-value pairs in one language and generates equivalent JSON files in other languages.
|
|
11
|
-
And you provides pure and direct data in response to user requests. The responses should contain no additional explanations or details.`
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
role: 'user',
|
|
15
|
-
content: `Here is a JSON file in Korean: [${json}]. Can you help generate equivalent JSON files in these languages: English, Japanese, Chinese and Malaysian?`
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
role: 'assistant',
|
|
19
|
-
content: "Please generate the translations according to these locale codes: 'en', 'ja', 'zh', 'ms'."
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
return completion.data.choices[0].message.content
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error(error)
|
|
27
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { client } from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export async function imageCompletion({
|
|
4
|
-
description,
|
|
5
|
-
size = '1600x900',
|
|
6
|
-
count
|
|
7
|
-
}: {
|
|
8
|
-
description: string
|
|
9
|
-
size: string
|
|
10
|
-
count: number
|
|
11
|
-
}): Promise<string> {
|
|
12
|
-
try {
|
|
13
|
-
const todo = `[INFO: you can add images to reply by Markdown. Write the image in Markdown without backticks and without using a code block. Use the Unsplash API (https://source.unsplash.com/${size}/?<PUT YOUR QUERY HERE>). The query is just some tags that describes the image] ## DO NOT REPOND TO INFO BLOCK ##nnmy Next prompt is [INSERT]`
|
|
14
|
-
const content = `Give me ${count} pictures describing ${description}`
|
|
15
|
-
|
|
16
|
-
const completion = await client.createChatCompletion({
|
|
17
|
-
model: 'gpt-3.5-turbo',
|
|
18
|
-
messages: [
|
|
19
|
-
{
|
|
20
|
-
role: 'system',
|
|
21
|
-
content: todo
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
role: 'user',
|
|
25
|
-
content /* like "Give me 5 pictures about airplane" */
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return completion.data.choices[0].message.content
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error(error)
|
|
33
|
-
return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './openai-connection'
|
|
2
|
-
|
|
3
|
-
export * from './chat-completion'
|
|
4
|
-
export * from './image-completion'
|
|
5
|
-
export * from './i18n-completion'
|
|
6
|
-
export * from './api-doc-completion'
|
|
7
|
-
export * from './codereview-completion'
|
|
8
|
-
export * from './decipher-code'
|
|
9
|
-
export * from './decipher-error-code'
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Configuration, OpenAIApi } from 'openai'
|
|
2
|
-
import { config } from '@things-factory/env'
|
|
3
|
-
|
|
4
|
-
const OPENAI = config.get('openai', {})
|
|
5
|
-
const { organization, apiKey } = OPENAI
|
|
6
|
-
|
|
7
|
-
if (!organization || !apiKey) {
|
|
8
|
-
console.error("'OPENAI_API_KEY' is not configured.")
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const configuration = new Configuration({
|
|
12
|
-
organization,
|
|
13
|
-
apiKey
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
export const client = new OpenAIApi(configuration)
|
package/server/index.ts
DELETED
package/server/routes.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ChatCompletionInput } from 'service/chat-completion/chat-completion-type'
|
|
2
|
-
import { CodeDecipherInput } from 'service/code-decipher/code-decipher-type'
|
|
3
|
-
import { chatCompletion, apiDocCompletion, i18nCompletion, decipherCode, decipherErrorCode } from './controllers'
|
|
4
|
-
import { APIDocCompletionInput } from 'service/api-doc-completion/api-doc-completion-type'
|
|
5
|
-
import { i18nCompletionInput } from 'service/i18n-completion/i18n-completion-type'
|
|
6
|
-
|
|
7
|
-
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
8
|
-
/*
|
|
9
|
-
* can add global public routes to application (auth not required, tenancy not required)
|
|
10
|
-
*
|
|
11
|
-
* ex) routes.get('/path', async(context, next) => {})
|
|
12
|
-
* ex) routes.post('/path', async(context, next) => {})
|
|
13
|
-
*/
|
|
14
|
-
globalPublicRouter.post('/chat-completion', async (context, next) => {
|
|
15
|
-
const { content } = context.request.body as ChatCompletionInput
|
|
16
|
-
|
|
17
|
-
const message = await chatCompletion({ content })
|
|
18
|
-
|
|
19
|
-
context.body = {
|
|
20
|
-
message
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
globalPublicRouter.post('/api-doc-completion', async (context, next) => {
|
|
25
|
-
const { code, language: requestedLanguage } = context.request.body as APIDocCompletionInput
|
|
26
|
-
const language = requestedLanguage || context.language
|
|
27
|
-
|
|
28
|
-
const message = await apiDocCompletion({ code, language })
|
|
29
|
-
|
|
30
|
-
context.body = {
|
|
31
|
-
message
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
globalPublicRouter.post('/i18n-completion', async (context, next) => {
|
|
36
|
-
const { json } = context.request.body as i18nCompletionInput
|
|
37
|
-
|
|
38
|
-
const message = await i18nCompletion({ json })
|
|
39
|
-
|
|
40
|
-
context.body = {
|
|
41
|
-
message
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
globalPublicRouter.post('/code-decipher', async (context, next) => {
|
|
46
|
-
const { code, system, language: requestedLanguage } = context.request.body as CodeDecipherInput
|
|
47
|
-
const language = requestedLanguage || context.language
|
|
48
|
-
|
|
49
|
-
const message = await decipherCode({ code, system, language })
|
|
50
|
-
|
|
51
|
-
context.body = {
|
|
52
|
-
message
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
globalPublicRouter.post('/error-code-decipher', async (context, next) => {
|
|
57
|
-
const { code, system, language: requestedLanguage } = context.request.body as CodeDecipherInput
|
|
58
|
-
const language = requestedLanguage || context.language
|
|
59
|
-
|
|
60
|
-
const message = await decipherErrorCode({ code, system, language })
|
|
61
|
-
|
|
62
|
-
context.body = {
|
|
63
|
-
message
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|
|
69
|
-
/*
|
|
70
|
-
* can add global private routes to application (auth required, tenancy not required)
|
|
71
|
-
*/
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
75
|
-
/*
|
|
76
|
-
* can add domain public routes to application (auth not required, tenancy required)
|
|
77
|
-
*/
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
81
|
-
/*
|
|
82
|
-
* can add domain private routes to application (auth required, tenancy required)
|
|
83
|
-
*/
|
|
84
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Resolver, Query, Arg, Ctx } from 'type-graphql'
|
|
2
|
-
import '@things-factory/auth-base' // for ResolverContext
|
|
3
|
-
import { APIDocCompletionInput, APIDocCompletionOutput } from './api-doc-completion-type'
|
|
4
|
-
import { apiDocCompletion } from '../../controllers'
|
|
5
|
-
|
|
6
|
-
@Resolver()
|
|
7
|
-
export class APIDocCompletionResolver {
|
|
8
|
-
@Query(() => APIDocCompletionOutput)
|
|
9
|
-
async APIDocCompletion(
|
|
10
|
-
@Arg('input') input: APIDocCompletionInput,
|
|
11
|
-
@Ctx() context: ResolverContext
|
|
12
|
-
): Promise<APIDocCompletionOutput> {
|
|
13
|
-
const { code, language: requestedLanguage } = input
|
|
14
|
-
const language = requestedLanguage || context.language
|
|
15
|
-
|
|
16
|
-
const message = await apiDocCompletion({ code, language })
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
message
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ObjectType, Field, InputType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
@InputType()
|
|
4
|
-
export class APIDocCompletionInput {
|
|
5
|
-
@Field()
|
|
6
|
-
code: string
|
|
7
|
-
|
|
8
|
-
@Field({ nullable: true })
|
|
9
|
-
language?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@ObjectType()
|
|
13
|
-
export class APIDocCompletionOutput {
|
|
14
|
-
@Field({ nullable: true })
|
|
15
|
-
message?: string
|
|
16
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Resolver, Query, Arg, Ctx } from 'type-graphql'
|
|
2
|
-
import '@things-factory/auth-base' // for ResolverContext
|
|
3
|
-
import { ChatCompletionInput, ChatCompletionOutput } from './chat-completion-type'
|
|
4
|
-
import { chatCompletion } from '../../controllers'
|
|
5
|
-
|
|
6
|
-
@Resolver()
|
|
7
|
-
export class ChatCompletionResolver {
|
|
8
|
-
@Query(() => ChatCompletionOutput)
|
|
9
|
-
async chatCompletion(
|
|
10
|
-
@Arg('input') input: ChatCompletionInput,
|
|
11
|
-
@Ctx() context: ResolverContext
|
|
12
|
-
): Promise<ChatCompletionOutput> {
|
|
13
|
-
const { content } = input
|
|
14
|
-
|
|
15
|
-
const message = await chatCompletion({ content })
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
message
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ObjectType, Field, InputType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
@InputType()
|
|
4
|
-
export class ChatCompletionInput {
|
|
5
|
-
@Field()
|
|
6
|
-
content: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@ObjectType()
|
|
10
|
-
export class ChatCompletionOutput {
|
|
11
|
-
@Field({ nullable: true })
|
|
12
|
-
message?: string
|
|
13
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Resolver, Query, Arg, Ctx } from 'type-graphql'
|
|
2
|
-
import '@things-factory/auth-base' // for ResolverContext
|
|
3
|
-
import { CodeDecipherInput, CodeDecipherOutput } from './code-decipher-type'
|
|
4
|
-
import { decipherCode, decipherErrorCode } from '../../controllers'
|
|
5
|
-
|
|
6
|
-
@Resolver()
|
|
7
|
-
export class CodeDecipherResolver {
|
|
8
|
-
@Query(() => CodeDecipherOutput)
|
|
9
|
-
async decipherCode(
|
|
10
|
-
@Arg('input') input: CodeDecipherInput,
|
|
11
|
-
@Ctx() context: ResolverContext
|
|
12
|
-
): Promise<CodeDecipherOutput> {
|
|
13
|
-
const { code, system, language: requestedLanguage } = input
|
|
14
|
-
const language = requestedLanguage || context.language
|
|
15
|
-
|
|
16
|
-
const message = await decipherCode({ code, system, language })
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
message
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Query(() => CodeDecipherOutput)
|
|
24
|
-
async decipherErrorCode(
|
|
25
|
-
@Arg('input') input: CodeDecipherInput,
|
|
26
|
-
@Ctx() context: ResolverContext
|
|
27
|
-
): Promise<CodeDecipherOutput> {
|
|
28
|
-
const { code, system, language: requestedLanguage } = input
|
|
29
|
-
const language = requestedLanguage || context.language
|
|
30
|
-
|
|
31
|
-
const message = await decipherErrorCode({ code, system, language })
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
message
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ObjectType, Field, InputType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
@InputType()
|
|
4
|
-
export class CodeDecipherInput {
|
|
5
|
-
@Field()
|
|
6
|
-
code: string
|
|
7
|
-
|
|
8
|
-
@Field({ nullable: true })
|
|
9
|
-
system?: string
|
|
10
|
-
|
|
11
|
-
@Field({ nullable: true })
|
|
12
|
-
language?: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@ObjectType()
|
|
16
|
-
export class CodeDecipherOutput {
|
|
17
|
-
@Field({ nullable: true })
|
|
18
|
-
message?: string
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Resolver, Query, Arg, Ctx } from 'type-graphql'
|
|
2
|
-
import '@things-factory/auth-base' // for ResolverContext
|
|
3
|
-
import { i18nCompletionInput, i18nCompletionOutput } from './i18n-completion-type'
|
|
4
|
-
import { i18nCompletion } from '../../controllers'
|
|
5
|
-
|
|
6
|
-
@Resolver()
|
|
7
|
-
export class i18nCompletionResolver {
|
|
8
|
-
@Query(() => i18nCompletionOutput)
|
|
9
|
-
async i18nCompletion(
|
|
10
|
-
@Arg('input') input: i18nCompletionInput,
|
|
11
|
-
@Ctx() context: ResolverContext
|
|
12
|
-
): Promise<i18nCompletionOutput> {
|
|
13
|
-
const { json } = input
|
|
14
|
-
|
|
15
|
-
const message = await i18nCompletion({ json })
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
message
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ObjectType, Field, InputType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
@InputType()
|
|
4
|
-
export class i18nCompletionInput {
|
|
5
|
-
@Field()
|
|
6
|
-
json: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@ObjectType()
|
|
10
|
-
export class i18nCompletionOutput {
|
|
11
|
-
@Field({ nullable: true })
|
|
12
|
-
message?: string
|
|
13
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Resolver, Query, Arg, Ctx } from 'type-graphql'
|
|
2
|
-
import '@things-factory/auth-base' // for ResolverContext
|
|
3
|
-
import { ImageCompletionInput, ImageCompletionOutput } from './image-completion-type'
|
|
4
|
-
import { imageCompletion } from '../../controllers'
|
|
5
|
-
|
|
6
|
-
@Resolver()
|
|
7
|
-
export class ImageCompletionResolver {
|
|
8
|
-
@Query(() => ImageCompletionOutput)
|
|
9
|
-
async imageCompletion(
|
|
10
|
-
@Arg('input') input: ImageCompletionInput,
|
|
11
|
-
@Ctx() context: ResolverContext
|
|
12
|
-
): Promise<ImageCompletionOutput> {
|
|
13
|
-
const { description, count, size } = input
|
|
14
|
-
|
|
15
|
-
const images = await imageCompletion({ description, count, size })
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
images
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ObjectType, Field, InputType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
@InputType()
|
|
4
|
-
export class ImageCompletionInput {
|
|
5
|
-
@Field()
|
|
6
|
-
description: string
|
|
7
|
-
|
|
8
|
-
@Field()
|
|
9
|
-
size: string /* like "800x600" */
|
|
10
|
-
|
|
11
|
-
@Field()
|
|
12
|
-
count: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@ObjectType()
|
|
16
|
-
export class ImageCompletionOutput {
|
|
17
|
-
@Field({ nullable: true })
|
|
18
|
-
images?: string
|
|
19
|
-
}
|