From 2e020ebf8f279a2781f1f31df1e35fda01195a39 Mon Sep 17 00:00:00 2001 From: Angular2guy Date: Sun, 7 Jul 2024 09:56:04 +0200 Subject: [PATCH] feat: add github client --- .../adapter/client/GithubRestClient.java | 15 ++++++++++----- .../domain/model/dto/GithubClient.java | 4 +--- .../domain/model/dto/GithubSource.java | 19 +++++++++++++++++++ .../resources/application-ollama.properties | 4 ++-- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubSource.java diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/GithubRestClient.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/GithubRestClient.java index 89c047e..12f3afc 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/GithubRestClient.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/GithubRestClient.java @@ -12,23 +12,28 @@ */ package ch.xxx.aidoclibchat.adapter.client; -import java.util.List; +import java.util.Arrays; import org.springframework.stereotype.Component; import org.springframework.web.client.RestClient; import ch.xxx.aidoclibchat.domain.model.dto.GithubClient; +import ch.xxx.aidoclibchat.domain.model.dto.GithubSource; @Component public class GithubRestClient implements GithubClient { private final RestClient restClient; - + public GithubRestClient(RestClient restClient) { this.restClient = restClient; } - - public List readSourceFile(String baseUrl, String url) { + + public GithubSource readSourceFile(String baseUrl, String url) { var result = this.restClient.get().uri("{baseUrl}{url}", baseUrl, url).retrieve().body(String.class); - return result.lines().toList(); + var sourceName = Arrays.asList(url.split("/")).reversed().get(0).split(".")[0].trim(); + var resultLines = result.lines().toList(); + var sourcePackage = resultLines.stream().filter(myLine -> myLine.contains("package")).findFirst().orElseThrow() + .split(" ")[1].split(";")[0].trim(); + return new GithubSource(sourceName, sourcePackage, resultLines); } } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubClient.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubClient.java index 6e7ee35..706f24c 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubClient.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubClient.java @@ -12,10 +12,8 @@ */ package ch.xxx.aidoclibchat.domain.model.dto; -import java.util.List; - public interface GithubClient { public static final String GITHUB_BASE_URL = "https://raw.githubusercontent.com"; - List readSourceFile(String baseUrl, String url); + GithubSource readSourceFile(String baseUrl, String url); } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubSource.java b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubSource.java new file mode 100644 index 0000000..5d651cd --- /dev/null +++ b/backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubSource.java @@ -0,0 +1,19 @@ +/** + * Copyright 2023 Sven Loesekann + Licensed 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 ch.xxx.aidoclibchat.domain.model.dto; + +import java.util.List; + +public record GithubSource(String sourceName, String sourcePackage, List lines) { + +} diff --git a/backend/src/main/resources/application-ollama.properties b/backend/src/main/resources/application-ollama.properties index fdaf2c6..072c0d5 100644 --- a/backend/src/main/resources/application-ollama.properties +++ b/backend/src/main/resources/application-ollama.properties @@ -13,7 +13,7 @@ spring.liquibase.change-log=classpath:/dbchangelog/db.changelog-master-ollama.xm # falcon model config free production use #spring.ai.ollama.chat.model=falcon:40b # beluga model config only for non production/commercial use -spring.ai.ollama.chat.model=stable-beluga:13b +#spring.ai.ollama.chat.model=stable-beluga:13b # function calling #spring.ai.ollama.chat.model=mixtral:8x7b-text-v0.1-q6_K @@ -26,6 +26,6 @@ spring.ai.ollama.chat.model=stable-beluga:13b #spring.ai.ollama.embedding.options.model=mxbai-embed-large:335m #test with Spring AI 1.0 # generate code -#spring.ai.ollama.chat.model=granite-code:20b +spring.ai.ollama.chat.model=granite-code:20b #spring.ai.ollama.chat.options.num-thread=8 #spring.ai.ollama.chat.options.keep_alive=1s \ No newline at end of file