File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
packages/ai-providers/server-ai-langchain Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 2828 "license" : " Apache-2.0" ,
2929 "devDependencies" : {
3030 "@langchain/core" : " ^0.3.0" ,
31- "@launchdarkly/server-sdk-ai" : " ^0.12.3 " ,
31+ "@launchdarkly/server-sdk-ai" : " ^0.13.0 " ,
3232 "@trivago/prettier-plugin-sort-imports" : " ^4.1.1" ,
3333 "@types/jest" : " ^29.5.3" ,
3434 "@typescript-eslint/eslint-plugin" : " ^6.20.0" ,
4848 },
4949 "peerDependencies" : {
5050 "@langchain/core" : " ^0.2.0 || ^0.3.0" ,
51- "@launchdarkly/server-sdk-ai" : " ^0.12.2 " ,
51+ "@launchdarkly/server-sdk-ai" : " ^0.13.0 " ,
5252 "langchain" : " ^0.2.0 || ^0.3.0"
5353 }
5454}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type {
1010 LDLogger ,
1111 LDMessage ,
1212 LDTokenUsage ,
13+ StructuredResponse ,
1314} from '@launchdarkly/server-sdk-ai' ;
1415
1516/**
@@ -79,6 +80,38 @@ export class LangChainProvider extends AIProvider {
7980 } ;
8081 }
8182
83+ /**
84+ * Invoke the LangChain model with structured output support.
85+ */
86+ async invokeStructuredModel (
87+ messages : LDMessage [ ] ,
88+ responseStructure : Record < string , unknown > ,
89+ ) : Promise < StructuredResponse > {
90+ // Convert LDMessage[] to LangChain messages
91+ const langchainMessages = LangChainProvider . convertMessagesToLangChain ( messages ) ;
92+
93+ // Get the LangChain response
94+ const response = await this . _llm
95+ . withStructuredOutput ( responseStructure )
96+ . invoke ( langchainMessages ) ;
97+
98+ // Using structured output doesn't support metrics
99+ const metrics = {
100+ success : true ,
101+ usage : {
102+ total : 0 ,
103+ input : 0 ,
104+ output : 0 ,
105+ } ,
106+ } ;
107+
108+ return {
109+ data : response ,
110+ rawResponse : JSON . stringify ( response ) ,
111+ metrics,
112+ } ;
113+ }
114+
82115 /**
83116 * Get the underlying LangChain model instance.
84117 */
You can’t perform that action at this time.
0 commit comments