Skip to content

Commit

Permalink
Add test for AI service resolution by name apache#6866
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger committed Dec 12, 2024
1 parent fc1accc commit 971dfa7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.langchain.it;

import java.util.function.Supplier;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import dev.langchain4j.service.UserMessage;
import io.quarkiverse.langchain4j.RegisterAiService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
import org.apache.camel.Handler;

@ApplicationScoped
@Named("aiServiceResolvedByName")
@RegisterAiService(chatLanguageModelSupplier = AiServiceResolvedByName.AiServiceResolvedByNameModelSupplier.class)
public interface AiServiceResolvedByName {

public static class AiServiceResolvedByNameModelSupplier implements Supplier<ChatLanguageModel> {
@Override
public ChatLanguageModel get() {
return (messages) -> {
return new Response<>(new AiMessage("AiServiceResolvedByName has been resolved"));
};
}
}

@UserMessage("Any prompt")
@Handler
String chatByName(String input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ public String aiServiceShouldBeResolvableByInterface() {
return producerTemplate.requestBody("direct:ai-service-should-be-resolvable-by-interface", "dummy-body", String.class);
}

@Path("/ai-service-should-be-resolvable-by-name")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String aiServiceShouldBeResolvableByName() {
return producerTemplate.requestBody("direct:ai-service-should-be-resolvable-by-name", "dummy-body", String.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ public void configure() {

from("direct:ai-service-should-be-resolvable-by-interface")
.bean(AiServiceResolvedByInterface.class);

from("direct:ai-service-should-be-resolvable-by-name")
.bean("aiServiceResolvedByName");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.is;
Expand All @@ -44,4 +45,14 @@ void aiServiceShouldBeResolvedByInterface() {
.statusCode(200)
.body(is("AiServiceResolvedByInterface has been resolved"));
}

@Test
@Disabled("https://github.com/apache/camel-quarkus/issues/6866")
void aiServiceShouldBeResolvedByName() {
RestAssured.given()
.get("/langchain4j/ai-service-should-be-resolvable-by-name")
.then()
.statusCode(200)
.body(is("AiServiceResolvedByName has been resolved"));
}
}

0 comments on commit 971dfa7

Please sign in to comment.