Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dev langchain core(pt.2) #97

Merged
merged 9 commits into from
Apr 2, 2024
Prev Previous commit
Next Next commit
feat: refactor questionHandler.create in Chain class and remove unuse…
…d imports
  • Loading branch information
codeacme17 committed Apr 1, 2024
commit 93b0490801b3100402e6f19a995419c2b6696ce6
10 changes: 3 additions & 7 deletions next/langchain/chain/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Semaphore } from 'async-mutex'
import { Document } from 'langchain/document'
import { StringOutputParser } from '@langchain/core/output_parsers'
import {
Runnable,
RunnableConfig,
RunnableSequence,
} from '@langchain/core/runnables'
import { BaseMessageChunk } from '@langchain/core/messages'
import { RunnableSequence } from '@langchain/core/runnables'
import { IntergrationLlm } from '../llm'
import { choicePrompt } from '../prompt'
import {
Expand Down Expand Up @@ -108,9 +103,10 @@ export class Chain {
})

for (const question of splitQuestions(res, this.questionType)) {
console.log(question)
if (!isLegalQuestionStructure(question, this.questionType)) continue
const { currentRole } = this.profile
questionHandler.create(
await questionHandler.create(
docId,
this.questionType,
removePrefixNumbers(question),
Expand Down
16 changes: 6 additions & 10 deletions next/langchain/chain/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ export const isLegalQuestionStructure = (
content: string,
type: string
): boolean => {
if (!content || content.length < 12) {
return false
}
if (!content || content.length < 12) return false

if (type === 'choice') {
const pattern = /^-\s.+?\n\s*A\..+\n\s*B\..+\n\s*C\..+\n\s*D\..+$/
return pattern.test(content)
}
// if (type === 'choice') {
// const pattern = /^-\s.+?\n\s*A\..+\n\s*B\..+\n\s*C\..+\n\s*D\..+$/
// return pattern.test(content)
// }

if (type === 'blank') {
return content.includes('_____')
}
if (type === 'blank') return content.includes('_____')

return true
}
Expand Down