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: Support JSON for consuming orchestration #346

Merged
merged 25 commits into from
Dec 20, 2024

Conversation

shibeshduw
Copy link
Contributor

Context

SAP/ai-sdk-js-backlog#179.

This PR adds a executeFromJSON method that allows users to copy/download the JSON from the Launchpad and use it directly with the SDK. Type safety is not checked as the user takes the responsibility for testing the JSON they use.

Definition of Done

  • Code is tested (Unit, E2E)
  • Error handling created / updated & covered by the tests above
  • [ ] Documentation updated
  • (Optional) Aligned changes with the Java SDK
  • [ ] (Optional) Release notes updated

@@ -36,7 +36,11 @@ export class OrchestrationClient {
prompt?: Prompt,
requestConfig?: CustomRequestConfig
): Promise<OrchestrationResponse> {
const body = constructCompletionPostRequest(this.config, prompt);
const body: CompletionPostRequest | Record<string, any> =
Copy link
Contributor

@deekshas8 deekshas8 Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[req] You don't need to cast body to Record<string, any>. If you parse the JSON string, it will essentially be of type CompletionPostRequest (or some subtype), but you can just add the prompt to it right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I was also considering the scenario where perhaps a spec change adds additional parameters which have not been adopted yet in our SDK. Since we are not checking for type safety, it can possibly provide users with a way to run their configurations still. Any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide users with a way to run their configurations

Yes, this is one of the use cases we want to cover with this approach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, adding Record or not won't have any effect on user, because this body is just a local variable, which will never affect any user.

I would also remove Record<string, any> unless we want to be 100% strictly correct and say the JSON object parsed from the string can have breaking changes.

No strong opinion and I see both points. In the end the type for body does not matter, and return type from constructCompletionFromJson is just for our own concern. The method is internal.

Copy link
Contributor Author

@shibeshduw shibeshduw Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. However, I still feel like it reads well to have it since it is explicitly clear to a technical user that the object can contain properties aside from those in CompletionPostRequest. Plus, removing it here would also mean that the return type for constructCompletionFromJson is also of type CompletionPostRequest which, strictly speaking, might not be the case.
But I guess I will defer to your judgement on this @deekshas8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also fine if you remove the type from here completely. Because:

  1. Removing Record<string, any> is a misrepresentation of the type of body, since we are not enforcing adherence of type returned from constructCompletionFromJson to CompletionPostRequest
  2. body is not used after this point for any local operations for which type-safety might be needed. Also, the data property of execute function is any which makes the union typing here moot.

I would maybe document that body can have additional types for clarity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for documentation, since we now need to be able to dynamically add streaming options, we actually do need some degree of type safety 😬

packages/orchestration/README.md Outdated Show resolved Hide resolved
sample-code/src/orchestration.ts Outdated Show resolved Hide resolved
sample-code/src/orchestration.ts Outdated Show resolved Hide resolved
sample-code/src/server.ts Outdated Show resolved Hide resolved
// Or alternatively, you can also provide the JSON configuration as a plain string in the code directly.
// const jsonConfig = 'YOUR_JSON_CONFIG'

const response = await new OrchestrationClient(jsonConfig).chatCompletion();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the API 👍

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good. Some minor stuff.

packages/orchestration/README.md Outdated Show resolved Hide resolved
packages/orchestration/README.md Outdated Show resolved Hide resolved
packages/orchestration/src/orchestration-client.ts Outdated Show resolved Hide resolved
packages/orchestration/src/orchestration-client.ts Outdated Show resolved Hide resolved
sample-code/src/orchestration.ts Outdated Show resolved Hide resolved
sample-code/src/orchestration.ts Outdated Show resolved Hide resolved
packages/orchestration/src/orchestration-client.ts Outdated Show resolved Hide resolved
packages/orchestration/src/orchestration-client.ts Outdated Show resolved Hide resolved
sample-code/src/server.ts Outdated Show resolved Hide resolved
@@ -36,7 +36,11 @@ export class OrchestrationClient {
prompt?: Prompt,
requestConfig?: CustomRequestConfig
): Promise<OrchestrationResponse> {
const body = constructCompletionPostRequest(this.config, prompt);
const body: CompletionPostRequest | Record<string, any> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also fine if you remove the type from here completely. Because:

  1. Removing Record<string, any> is a misrepresentation of the type of body, since we are not enforcing adherence of type returned from constructCompletionFromJson to CompletionPostRequest
  2. body is not used after this point for any local operations for which type-safety might be needed. Also, the data property of execute function is any which makes the union typing here moot.

I would maybe document that body can have additional types for clarity

@jjtang1985 jjtang1985 dismissed deekshas8’s stale review December 20, 2024 09:12

Shibesh would be off, and said it should be ready to merge.

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ZhongpinWang ZhongpinWang merged commit 17a1eea into main Dec 20, 2024
10 checks passed
@ZhongpinWang ZhongpinWang deleted the orchestration-from-json branch December 20, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants