generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support JSON for consuming orchestration (#346)
* execute orchestration from JSON input * union type in contructor * fix: Changes from lint * update README.md * fix: Changes from lint * changes and added tests * fix: Changes from lint * rename * updated docs * fix: Changes from lint * refactored tests and doc changes * refactor: change model and endpoint * fix: Changes from lint * fix: construct completion post request tests * fix: testcd '/Users/I563080/Dev/ai-sdk-js' * chore: minor formatting --------- Co-authored-by: cloud-sdk-js <[email protected]> Co-authored-by: Junjie Tang <[email protected]> Co-authored-by: Zhongpin Wang <[email protected]>
- Loading branch information
1 parent
4e82eb5
commit 17a1eea
Showing
11 changed files
with
261 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sap-ai-sdk/orchestration': minor | ||
--- | ||
|
||
[New Functionality] Add support for using a JSON configuration obtained from AI Launchpad to consume orchestration service. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/orchestration/src/orchestration-completion-post-request-from-json.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { constructCompletionPostRequestFromJson } from './orchestration-client.js'; | ||
|
||
describe('construct completion post request from JSON', () => { | ||
it('should throw an error when invalid JSON is provided', () => { | ||
const invalidJsonConfig = '{ "module_configurations": {}, '; | ||
|
||
expect(() => | ||
constructCompletionPostRequestFromJson(invalidJsonConfig) | ||
).toThrow('Could not parse JSON'); | ||
}); | ||
|
||
it('should construct completion post request from JSON', () => { | ||
const jsonConfig = `{ | ||
"module_configurations": { | ||
"llm_module_config": { | ||
"model_name": "gpt-35-turbo-16k", | ||
"model_params": { | ||
"max_tokens": 50, | ||
"temperature": 0.1 | ||
} | ||
}, | ||
"templating_module_config": { | ||
"template": [{ "role": "user", "content": "Hello!" }] | ||
} | ||
} | ||
}`; | ||
|
||
const expectedCompletionPostRequestFromJson: Record<string, any> = { | ||
input_params: {}, | ||
messages_history: [], | ||
orchestration_config: JSON.parse(jsonConfig) | ||
}; | ||
|
||
const completionPostRequestFromJson: Record<string, any> = | ||
constructCompletionPostRequestFromJson(jsonConfig); | ||
|
||
expect(expectedCompletionPostRequestFromJson).toEqual( | ||
completionPostRequestFromJson | ||
); | ||
}); | ||
|
||
it('should construct completion post request from JSON with input params and message history', () => { | ||
const jsonConfig = `{ | ||
"module_configurations": { | ||
"llm_module_config": { | ||
"model_name": "gpt-35-turbo-16k", | ||
"model_params": { | ||
"max_tokens": 50, | ||
"temperature": 0.1 | ||
} | ||
}, | ||
"templating_module_config": { | ||
"template": [ | ||
{ | ||
"role": "user", | ||
"content": "Give me {{?number}} words that rhyme with my name." | ||
} | ||
] | ||
} | ||
} | ||
}`; | ||
const inputParams = { number: '3' }; | ||
|
||
const messagesHistory = [ | ||
{ | ||
role: 'system', | ||
content: | ||
'You are a helpful assistant who remembers all details the user shares with you.' | ||
}, | ||
{ | ||
role: 'user', | ||
content: 'Hi! Im Bob' | ||
}, | ||
{ | ||
role: 'assistant', | ||
content: | ||
"Hi Bob, nice to meet you! I'm an AI assistant. I'll remember that your name is Bob as we continue our conversation." | ||
} | ||
]; | ||
|
||
const expectedCompletionPostRequestFromJson: Record<string, any> = { | ||
input_params: inputParams, | ||
messages_history: messagesHistory, | ||
orchestration_config: JSON.parse(jsonConfig) | ||
}; | ||
|
||
const completionPostRequestFromJson: Record<string, any> = | ||
constructCompletionPostRequestFromJson(jsonConfig, { | ||
inputParams, | ||
messagesHistory | ||
}); | ||
|
||
expect(expectedCompletionPostRequestFromJson).toEqual( | ||
completionPostRequestFromJson | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"module_configurations": { | ||
"llm_module_config": { | ||
"model_name": "gpt-4o", | ||
"model_params": {}, | ||
"model_version": "latest" | ||
}, | ||
"templating_module_config": { | ||
"template": [ | ||
{ | ||
"role": "user", | ||
"content": "SAP" | ||
}, | ||
{ | ||
"role": "system", | ||
"content": "When given the name of a company, provide the year of it's establishment." | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.