Skip to content

Commit 2e020eb

Browse files
committed
feat: add github client
1 parent a6033b1 commit 2e020eb

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

backend/src/main/java/ch/xxx/aidoclibchat/adapter/client/GithubRestClient.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@
1212
*/
1313
package ch.xxx.aidoclibchat.adapter.client;
1414

15-
import java.util.List;
15+
import java.util.Arrays;
1616

1717
import org.springframework.stereotype.Component;
1818
import org.springframework.web.client.RestClient;
1919

2020
import ch.xxx.aidoclibchat.domain.model.dto.GithubClient;
21+
import ch.xxx.aidoclibchat.domain.model.dto.GithubSource;
2122

2223
@Component
2324
public class GithubRestClient implements GithubClient {
2425
private final RestClient restClient;
25-
26+
2627
public GithubRestClient(RestClient restClient) {
2728
this.restClient = restClient;
2829
}
29-
30-
public List<String> readSourceFile(String baseUrl, String url) {
30+
31+
public GithubSource readSourceFile(String baseUrl, String url) {
3132
var result = this.restClient.get().uri("{baseUrl}{url}", baseUrl, url).retrieve().body(String.class);
32-
return result.lines().toList();
33+
var sourceName = Arrays.asList(url.split("/")).reversed().get(0).split(".")[0].trim();
34+
var resultLines = result.lines().toList();
35+
var sourcePackage = resultLines.stream().filter(myLine -> myLine.contains("package")).findFirst().orElseThrow()
36+
.split(" ")[1].split(";")[0].trim();
37+
return new GithubSource(sourceName, sourcePackage, resultLines);
3338
}
3439
}

backend/src/main/java/ch/xxx/aidoclibchat/domain/model/dto/GithubClient.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
*/
1313
package ch.xxx.aidoclibchat.domain.model.dto;
1414

15-
import java.util.List;
16-
1715
public interface GithubClient {
1816
public static final String GITHUB_BASE_URL = "https://raw.githubusercontent.com";
1917

20-
List<String> readSourceFile(String baseUrl, String url);
18+
GithubSource readSourceFile(String baseUrl, String url);
2119
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2023 Sven Loesekann
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package ch.xxx.aidoclibchat.domain.model.dto;
14+
15+
import java.util.List;
16+
17+
public record GithubSource(String sourceName, String sourcePackage, List<String> lines) {
18+
19+
}

backend/src/main/resources/application-ollama.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spring.liquibase.change-log=classpath:/dbchangelog/db.changelog-master-ollama.xm
1313
# falcon model config free production use
1414
#spring.ai.ollama.chat.model=falcon:40b
1515
# beluga model config only for non production/commercial use
16-
spring.ai.ollama.chat.model=stable-beluga:13b
16+
#spring.ai.ollama.chat.model=stable-beluga:13b
1717

1818
# function calling
1919
#spring.ai.ollama.chat.model=mixtral:8x7b-text-v0.1-q6_K
@@ -26,6 +26,6 @@ spring.ai.ollama.chat.model=stable-beluga:13b
2626
#spring.ai.ollama.embedding.options.model=mxbai-embed-large:335m #test with Spring AI 1.0
2727

2828
# generate code
29-
#spring.ai.ollama.chat.model=granite-code:20b
29+
spring.ai.ollama.chat.model=granite-code:20b
3030
#spring.ai.ollama.chat.options.num-thread=8
3131
#spring.ai.ollama.chat.options.keep_alive=1s

0 commit comments

Comments
 (0)