Skip to content

Commit e10c90c

Browse files
committed
feat(core): add injection dependencies and update variable configuration in sentiment analysis workflow
1 parent 59c481b commit e10c90c

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

packages/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ export const name = 'cortexluna'
2424
export interface Config {}
2525

2626
export const Config: CordisSchema<Config> = CordisSchema.object({})
27+
28+
export const inject = ['http']

packages/openai-compatible/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"provider"
4747
],
4848
"dependencies": {
49-
"cortexluna": "^0.0.1",
5049
"zod": "3.24.2"
5150
},
5251
"devDependencies": {
@@ -65,7 +64,7 @@
6564
},
6665
"cordis": {
6766
"description": {
68-
"zh": "ChatLuna OpenAI 风格模型提供器"
67+
"zh": "CortexLuna OpenAI 风格模型提供器"
6968
},
7069
"service": {
7170
"required": [

packages/openai-compatible/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function apply(ctx: Context, config: Config) {
6969
}
7070

7171
export const name = '@cortexluna/openai-compatible'
72+
export const inject = ['cortex_luna', 'http']
7273

7374
type FetchResponse = globalThis.Response
7475

packages/workflow/tests/sentiment.spec.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { openaiCompatible } from '@cortexluna/openai-compatible'
1111
import {
1212
bindPromptTemplate,
1313
bindPromptTemplateToObject,
14-
generatateObject,
1514
promptTemplate
1615
} from 'cortexluna'
1716

@@ -42,12 +41,17 @@ describe('Sentiment Analysis Workflow', () => {
4241
type IfNodeInput = Record<string, unknown>
4342
type IfNodeOutput = Record<string, boolean>
4443

45-
type VariableConfig = { name: string; type: 'input' | 'context' } | string
44+
type VariableConfig =
45+
| { name: string; type: 'input' | 'context' }
46+
| string
4647

4748
const ifNode: NodeDefinition<IfNodeInput, IfNodeOutput> = {
4849
inputSchema: (node: WorkflowNode) => {
4950
const config = node.config as
50-
| { expressions: Record<string, string>; variables?: VariableConfig[] }
51+
| {
52+
expressions: Record<string, string>
53+
variables?: VariableConfig[]
54+
}
5155
| undefined
5256
if (!config) return z.record(z.unknown())
5357

@@ -62,9 +66,11 @@ describe('Sentiment Analysis Workflow', () => {
6266
const varConfig = config.variables?.find(
6367
(vc) => (typeof vc === 'string' ? vc : vc.name) === v
6468
)
65-
if (!varConfig ||
66-
(typeof varConfig === 'string') ||
67-
varConfig.type === 'input') {
69+
if (
70+
!varConfig ||
71+
typeof varConfig === 'string' ||
72+
varConfig.type === 'input'
73+
) {
6874
inputFields[v] = z.unknown()
6975
}
7076
})
@@ -84,7 +90,10 @@ describe('Sentiment Analysis Workflow', () => {
8490
},
8591
run: async (input, context, node) => {
8692
const config = node?.config as
87-
| { expressions: Record<string, string>; variables?: VariableConfig[] }
93+
| {
94+
expressions: Record<string, string>
95+
variables?: VariableConfig[]
96+
}
8897
| undefined
8998
if (!config)
9099
throw new Error('If node requires config with expressions')
@@ -95,8 +104,12 @@ describe('Sentiment Analysis Workflow', () => {
95104
// Resolve variables from context if specified
96105
if (config.variables) {
97106
config.variables.forEach((varConfig) => {
98-
if (typeof varConfig === 'object' && varConfig.type === 'context') {
99-
evalContext[varConfig.name] = context.variables[varConfig.name]
107+
if (
108+
typeof varConfig === 'object' &&
109+
varConfig.type === 'context'
110+
) {
111+
evalContext[varConfig.name] =
112+
context.variables[varConfig.name]
100113
}
101114
})
102115
}
@@ -230,9 +243,7 @@ describe('Sentiment Analysis Workflow', () => {
230243
if1: 'multisentiment === true',
231244
elseif1: 'multisentiment === false'
232245
},
233-
variables: [
234-
{ name: 'multisentiment', type: 'context' }
235-
]
246+
variables: [{ name: 'multisentiment', type: 'context' }]
236247
}
237248
},
238249
{

0 commit comments

Comments
 (0)