Skip to content

Commit

Permalink
Merge branch 'main' into openapi/with-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesDuboisSAP authored Aug 14, 2024
2 parents d275a4b + 01c80eb commit c543046
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
mvn $MVN_ARGS
env:
# See "End-to-end test application instructions" on the README.md to update the secret
aicore: ${{ secrets.AICORE_SERVICE_KEY }}
AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }}

- name: "Start Application Locally"
run: |
Expand All @@ -53,7 +53,7 @@ jobs:
done
env:
# See "End-to-end test application instructions" on the README.md to update the secret
aicore: ${{ secrets.AICORE_SERVICE_KEY }}
AICORE_SERVICE_KEY: ${{ secrets.AICORE_SERVICE_KEY }}

- name: "Health Check"
# print response body with headers to stdout. q:body only O:print -:stdout S:headers
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,16 @@ For more customization, creating a [HeaderProvider](https://sap.github.io/cloud-

### Set AI Core credentials as environment variable

- Running the application locally without a service binding will throw:

`Could not find any matching service bindings for service identifier 'aicore'`
- Go into the BTP Cockpit
- Instances and Subscriptions -> Instances -> AI Core -> View Credentials -> Copy JSON
- Set it as an environment variable `aicore` in your IDE
- Set it as an environment variable `AICORE_SERVICE_KEY` in your IDE

Or in your terminal:
```shell
export aicore='{ "serviceurls": { "AI_API_URL": ...'
export AICORE_SERVICE_KEY='{ "serviceurls": { "AI_API_URL": ...'
```

### Run the Spring Boot application
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/com/sap/ai/sdk/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static String getOrchestrationDeployment(@Nonnull final String resourceG

/**
* <b>Requires an AI Core service binding OR a service key in the environment variable {@code
* aicore}.</b>
* AICORE_SERVICE_KEY}.</b>
*
* @return a generic <code>AI Core</code> ApiClient.
*/
Expand Down Expand Up @@ -115,13 +115,13 @@ public static ApiClient getClient(@Nonnull final Destination destination) {

/**
* <b>Requires an AI Core service binding OR a service key in the environment variable {@code
* aicore}.</b>
* AICORE_SERVICE_KEY}.</b>
*
* @return a destination pointing to the AI Core service.
*/
@Nonnull
public static Destination getDestination() {
final var serviceKey = System.getenv("aicore");
final var serviceKey = System.getenv("AICORE_SERVICE_KEY");
final var serviceKeyPresent = serviceKey != null;
final var aiCoreBindingPresent =
DefaultServiceBindingAccessor.getInstance().getServiceBindings().stream()
Expand Down Expand Up @@ -160,7 +160,7 @@ public static Destination getDestination() {
private static void addServiceBinding(@Nonnull final String serviceKey) {
log.info(
"""
Found a service key in environment variable "aicore".
Found a service key in environment variable "AICORE_SERVICE_KEY".
Using a service key is recommended for local testing only.
Bind the AI Core service to the application for productive usage.""");

Expand All @@ -169,7 +169,7 @@ private static void addServiceBinding(@Nonnull final String serviceKey) {
credentials = new ObjectMapper().readValue(serviceKey, new TypeReference<>() {});
} catch (JsonProcessingException e) {
throw new AiCoreCredentialsInvalidException(
"Error in parsing service key from the \"aicore\" environment variable.", e);
"Error in parsing service key from the \"AICORE_SERVICE_KEY\" environment variable.", e);
}

final var binding =
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/com/sap/ai/sdk/core/CoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CoreTest {
@Test
@SneakyThrows
void getDestinationWithoutEnvVarFailsLocally() {
variables.set("aicore", null);
variables.set("AICORE_SERVICE_KEY", null);
assertThatThrownBy(Core::getDestination)
.isExactlyInstanceOf(DestinationAccessException.class)
.hasMessage("Could not find any matching service bindings for service identifier 'aicore'");
Expand All @@ -28,17 +28,17 @@ void getDestinationWithoutEnvVarFailsLocally() {
@Test
@SneakyThrows
void getDestinationWithBrokenEnvVarFailsLocally() {
variables.set("aicore", "");
variables.set("AICORE_SERVICE_KEY", "");
assertThatThrownBy(Core::getDestination)
.isExactlyInstanceOf(Core.AiCoreCredentialsInvalidException.class)
.hasMessage("Error in parsing service key from the \"aicore\" environment variable.");
.hasMessage("Error in parsing service key from the \"AICORE_SERVICE_KEY\" environment variable.");
}

@Test
@SneakyThrows
void getDestinationWithEnvVarSucceedsLocally() {
variables.set(
"aicore",
"AICORE_SERVICE_KEY",
"""
{
"clientid": "",
Expand Down

0 comments on commit c543046

Please sign in to comment.