Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/msa-ez/platform
Browse files Browse the repository at this point in the history
  • Loading branch information
kibum0405 committed Jan 8, 2025
2 parents fea5aec + 2b46823 commit e7cdedf
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<script>
import ESActionsUtil from "../../modeling/generators/es-ddl-generators/modules/ESActionsUtil";
import TokenCounterTest from "../../modeling/generators/utils/TokenCounter/tests";
import ESValueSummaryGeneratorTest from "../../modeling/generators/es-generators/ESValueSummaryGenerator/tests";
import ESValueSummarizeWithFilterTest from "../../modeling/generators/es-generators/helpers/ESValueSummarizeWithFilter/tests";
import TokenCounterTest from "../../modeling/generators/utils/TokenCounter/TokenCounterTest";
import ESValueSummaryGeneratorTest from "../../modeling/generators/es-generators/ESValueSummaryGenerator/ESValueSummaryGeneratorTest";
import ESValueSummarizeWithFilterTest from "../../modeling/generators/es-generators/helpers/ESValueSummarizeWithFilter/ESValueSummarizeWithFilterTest";

export default {
name: "es-test-terminal",
Expand Down Expand Up @@ -1031,8 +1031,8 @@ export default {
TokenCounterTest.test()
},

_ESSummaryGeneratorTest() {
ESValueSummaryGeneratorTest.test(this.value)
async _ESSummaryGeneratorTest() {
await ESValueSummaryGeneratorTest.test(this.value)
},

async _TempTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ class ESAliasTransManager {
if(this.UUIDToAliasDic[element.id])
return this.UUIDToAliasDic[element.id]

let aliasToUse = `${getFrontId(element)}-${changeCase.camelCase(element.name)}`
let i = 1
const baseAlias = `${getFrontId(element)}-${changeCase.camelCase(element.name)}`
let aliasToUse = baseAlias
let i = 2

while(this.aliasToUUIDDic[aliasToUse]) {
aliasToUse = `${aliasToUse}-${i}`
aliasToUse = `${baseAlias}-${i}`
i++
}
return aliasToUse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,61 @@ class ESValueSummaryGenerator extends FormattedJSONAIGenerator{
constructor(client){
super(client);

this.checkInputParamsKeys = ["context", "esValue", "keysToFilter", "maxTokens", "tokenCalcModel"]
this.checkInputParamsKeys = ["context", "esValue", "keysToFilter", "maxTokens", "tokenCalcModel", "esAliasTransManager"]
this.progressCheckStrings = ["overviewThoughts", "result"]
}


onGenerateBefore(inputParams){
if(inputParams.keysToFilter.includes("id"))
throw new Error("id 속성은 정렬에 사용되기 때문에 필터링에서 제외되어야 합니다.")
static async getSummarizedESValueWithMaxTokenSummarize(context, esValue, keysToFilter, maxTokens, tokenCalcModel, esAliasTransManager){
const summarizedESValue = ESValueSummarizeWithFilter.getSummarizedESValue(
esValue, keysToFilter, esAliasTransManager
)

const tokenCount = TokenCounter.getTokenCount(JSON.stringify(summarizedESValue), tokenCalcModel)
if(tokenCount <= maxTokens)
return summarizedESValue


return new Promise((resolve, reject) => {
const esValueSummaryGenerator = new ESValueSummaryGenerator({
input: {
"context": context,
"esValue": esValue,
"keysToFilter": keysToFilter,
"maxTokens": maxTokens,
"tokenCalcModel": tokenCalcModel,
"esAliasTransManager": esAliasTransManager
},

onModelCreated: (returnObj) => {

},

onGenerationSucceeded: (returnObj) => {
resolve(returnObj.modelValue.summary)
},

onRetry: (returnObj) => {
reject(returnObj.errorMessage)
}
})

esValueSummaryGenerator.generate()
})
}

onInputParamsCheckBefore(inputParams) {
inputParams.esValue = JSON.parse(JSON.stringify(inputParams.esValue))
this.esAliasTransManager = new ESAliasTransManager(inputParams.esValue)
if(!inputParams.esAliasTransManager)
inputParams.esAliasTransManager = new ESAliasTransManager(inputParams.esValue)
}

onGenerateBefore(inputParams){
if(inputParams.keysToFilter.includes("id"))
throw new Error("id 속성은 정렬에 사용되기 때문에 필터링에서 제외되어야 합니다.")

inputParams.summarizedESValue = ESValueSummarizeWithFilter.getSummarizedESValue(
inputParams.esValue, inputParams.keysToFilter, this.esAliasTransManager
inputParams.esValue, inputParams.keysToFilter, inputParams.esAliasTransManager
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const ESValueSummaryGenerator = require("./ESValueSummaryGenerator")
const { libraryEsValue } = require("./mocks");
const { ESValueSummarizeWithFilter } = require("../helpers")
const ESAliasTransManager = require("../../es-ddl-generators/modules/ESAliasTransManager")
const { TokenCounter } = require("../../utils")

class ESValueSummaryGeneratorTest {
static async test(esValue=null) {
if(!esValue) esValue = JSON.parse(JSON.stringify(libraryEsValue));

const esAliasTransManager = new ESAliasTransManager(esValue)


const summariezedESValue = ESValueSummarizeWithFilter.getSummarizedESValue(
esValue, [], esAliasTransManager
)
console.log(summariezedESValue)
console.log("[*] 전체 ESValue 토큰 수 :", TokenCounter.getTokenCount(JSON.stringify(summariezedESValue), "gpt-4o"))


const summary = await ESValueSummaryGenerator.getSummarizedESValueWithMaxTokenSummarize(
"도서 관련 커맨드 생성 작업을 수행해야 함",
esValue,
[],
800,
"gpt-4o",
esAliasTransManager
)
console.log("[*] 요약된 ESValue :", summary)
console.log("[*] 요약된 ESValue 토큰 수 :", TokenCounter.getTokenCount(JSON.stringify(summary), "gpt-4o"))
}
}

module.exports = ESValueSummaryGeneratorTest;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { TokenCounter } = require("../../../utils")

class ESValueSummarizeWithFilter {
/**
* getSummarizedESValue()에서 반환될 값에 대한 상세한 입력 프롬프트 가이드 반환
Expand Down Expand Up @@ -156,18 +154,6 @@ The approximate structure is as follows.
}`
}

static async getSummarizedESValueWithMaxTokenSummarize(esValue, keysToFilter=[], esAliasTransManager=null, maxTokens=800, tokenCalcModel="gpt-4o"){
const summarizedESValue = this.getSummarizedESValue(
esValue, keysToFilter, esAliasTransManager
)

const tokenCount = TokenCounter.getTokenCount(JSON.stringify(summarizedESValue), tokenCalcModel)
if(tokenCount < maxTokens)
return summarizedESValue

throw new Error("토큰 수가 초과되었습니다.")
}

/**
* 주어진 이벤트스토밍에서 위치 데이터등을 제외한 핵심 정보들만 추출해서 LLM에게 입력 데이터로 제공
* keysToFilter: 일부 경우에는 properties와 같은 구체적인 속성들이 불필요할 수 있음. 이런 경우에 제외시킬 키값을 배열로 전달
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ class ESValueSummarizeWithFilterTest {
esAliasTransManager
)
console.log(summaryWithFilter)


console.log("[*] 3. 토큰 수 초과시 자동 요약 기능을 포함한 요약 요청")
const summaryWithAutoSummarize = await ESValueSummarizeWithFilter.getSummarizedESValueWithMaxTokenSummarize(
esValue,
[],
esAliasTransManager,
800,
"gpt-4o"
)
console.log(summaryWithAutoSummarize)
}
}

Expand Down

0 comments on commit e7cdedf

Please sign in to comment.