Skip to content

Commit

Permalink
feat: refactor, cleanup move Role out of Message
Browse files Browse the repository at this point in the history
  • Loading branch information
astappiev committed Jul 29, 2024
1 parent a782f6b commit 6e7e662
Show file tree
Hide file tree
Showing 64 changed files with 333 additions and 337 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/publish-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
env:
MVN: mvn --show-version --batch-mode
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'

- name: Publish to GitHub Packages Apache Maven
run: $MVN -pl interweb-client -am deploy
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
- name: Publish to GitHub Packages Apache Maven
run: $MVN -pl interweb-client -am deploy
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ Interweb can be used in a wide range of applications, but was designed with the
Interweb currently supports the following data providers:

1. **Anthropic**:
- Interact with Anthropic's LLMs for natural language understanding and generation.
- Interact with Anthropic's LLMs for natural language understanding and generation.
2. **Bing**:
- Search: the web for images, videos, news, and more.
- Suggest: get related queries to enhance user search experience.
- Search: the web for images, videos, news, and more.
- Suggest: get related queries to enhance user search experience.
3. **Flickr**:
- Search: for photos and images.
- Describe: a media resource by url.
- Search: for photos and images.
- Describe: a media resource by url.
4. **Giphy**:
- Search: for variety of gifs in one of the largest gif libraries.
- Search: for variety of gifs in one of the largest gif libraries.
5. **Google**:
- Suggest: access related search queries from one of the world's leading search engines.
- Suggest: access related search queries from one of the world's leading search engines.
6. **Ipernity**:
- Search: discover photos and images within one of the largest non-commercial clubs.
- Describe: obtain photo information using its url.
- Search: discover photos and images within one of the largest non-commercial clubs.
- Describe: obtain photo information using its url.
7. **Ollama**:
- Interact with open-source LLMs for natural language understanding and generation.
- Interact with open-source LLMs for natural language understanding and generation.
8. **OpenAI**:
- Interact with OpenAI's ChatGPT for natural language understanding and generation.
- Interact with OpenAI's ChatGPT for natural language understanding and generation.
9. **SlideShare**:
- Search: find presentations and documents for various topics.
- Search: find presentations and documents for various topics.
10. **Vimeo**:
- Search: locate videos created by creative content creators.
- Describe: obtain video information using its url.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package de.l3s.interweb.connector.anthropic;

import jakarta.ws.rs.*;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

Expand All @@ -9,8 +12,8 @@
import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import de.l3s.interweb.connector.anthropic.entity.CompletionResponse;
import de.l3s.interweb.connector.anthropic.entity.CompletionBody;
import de.l3s.interweb.connector.anthropic.entity.CompletionResponse;
import de.l3s.interweb.core.ConnectorException;

@Path("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Uni<CompletionsResults> completions(CompletionsQuery query) throws Connec

AtomicInteger index = new AtomicInteger();
List<Choice> choices = response.getContent().stream().map(content -> {
Message message = new Message(Message.Role.assistant, content.getText());
Message message = new Message(Role.assistant, content.getText());
return new Choice(index.getAndIncrement(), response.getStopReason(), message);
}).toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import java.util.List;

import io.quarkus.runtime.annotations.RegisterForReflection;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.quarkus.runtime.annotations.RegisterForReflection;

import de.l3s.interweb.core.chat.CompletionsQuery;
import de.l3s.interweb.core.chat.Message;
import de.l3s.interweb.core.chat.Message.Role;
import de.l3s.interweb.core.chat.Role;

@JsonInclude(JsonInclude.Include.NON_NULL)
@RegisterForReflection
Expand All @@ -33,14 +33,14 @@ public CompletionBody(CompletionsQuery query) {
this.model = query.getModel();

this.messages = query.getMessages().stream()
.filter(m -> m.getRole() != Role.system)
.map(CompletionMessage::new)
.toList();
.filter(m -> m.getRole() != Role.system)
.map(CompletionMessage::new)
.toList();
this.system = query.getMessages().stream()
.filter(m -> m.getRole() == Role.system)
.findFirst()
.map(Message::getContent)
.orElse(null);
.filter(m -> m.getRole() == Role.system)
.findFirst()
.map(Message::getContent)
.orElse(null);

this.temperature = query.getTemperature();
this.topP = query.getTopP();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.l3s.interweb.connector.anthropic.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.quarkus.runtime.annotations.RegisterForReflection;

import com.fasterxml.jackson.annotation.JsonIgnore;

import de.l3s.interweb.core.chat.Message;

@RegisterForReflection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

import io.quarkus.runtime.annotations.RegisterForReflection;

import com.fasterxml.jackson.annotation.JsonProperty;

@RegisterForReflection
public class CompletionResponse {
private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import de.l3s.interweb.core.chat.Choice;
import de.l3s.interweb.core.chat.CompletionsQuery;
import de.l3s.interweb.core.chat.CompletionsResults;
import de.l3s.interweb.core.chat.Message;
import de.l3s.interweb.core.chat.Role;

@Disabled
@QuarkusTest
Expand All @@ -35,8 +35,8 @@ void validate() throws ConnectorException {
@Test
void completions() throws ConnectorException {
CompletionsQuery query = new CompletionsQuery();
query.addMessage("You are Interweb Assistant, a helpful chat bot. Your name is not Claude it is Interweb Assistant.", Message.Role.system);
query.addMessage("What is your name?", Message.Role.user);
query.addMessage("You are Interweb Assistant, a helpful chat bot. Your name is not Claude it is Interweb Assistant.", Role.system);
query.addMessage("What is your name?", Role.user);
query.setMaxTokens(100);
query.setModel("claude-3-haiku-20240307");

Expand All @@ -53,10 +53,10 @@ void completions() throws ConnectorException {
void jsonBody() throws JsonProcessingException {
CompletionsQuery query = new CompletionsQuery();
query.setModel("claude-3-haiku-20240307");
query.addMessage("You are Interweb Assistant, a helpful chat bot.", Message.Role.system);
query.addMessage("What is your name?", Message.Role.user);
query.addMessage("My name is Interweb Assistant.", Message.Role.assistant);
query.addMessage("Hi Interweb Assistant, I am a user.", Message.Role.user);
query.addMessage("You are Interweb Assistant, a helpful chat bot.", Role.system);
query.addMessage("What is your name?", Role.user);
query.addMessage("My name is Interweb Assistant.", Role.assistant);
query.addMessage("Hi Interweb Assistant, I am a user.", Role.user);

CompletionBody body = new CompletionBody(query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ private Uni<BingResponse> processQuery(SearchQuery query) {
if (query.getContentTypes().size() == 1) {
if (query.getContentTypes().contains(ContentType.image)) {
return searchClient.searchImages(
query.getQuery(),
query.getPerPage(FALLBACK_PER_PAGE_IMAGES),
query.getOffset(FALLBACK_PER_PAGE_IMAGES),
query.getLanguage(),
BingUtils.getMarket(query.getLanguage()),
BingUtils.createFreshness(null, query.getDateTo())
query.getQuery(),
query.getPerPage(FALLBACK_PER_PAGE_IMAGES),
query.getOffset(FALLBACK_PER_PAGE_IMAGES),
query.getLanguage(),
BingUtils.getMarket(query.getLanguage()),
BingUtils.createFreshness(null, query.getDateTo())
);
} else if (query.getContentTypes().contains(ContentType.video)) {
return searchClient.searchVideos(
query.getQuery(),
query.getPerPage(FALLBACK_PER_PAGE_VIDEOS),
query.getOffset(FALLBACK_PER_PAGE_VIDEOS),
query.getLanguage(),
BingUtils.getMarket(query.getLanguage()),
BingUtils.createFreshness(null, query.getDateTo())
query.getQuery(),
query.getPerPage(FALLBACK_PER_PAGE_VIDEOS),
query.getOffset(FALLBACK_PER_PAGE_VIDEOS),
query.getLanguage(),
BingUtils.getMarket(query.getLanguage()),
BingUtils.createFreshness(null, query.getDateTo())
);
}
}
Expand All @@ -96,13 +96,13 @@ private Uni<BingResponse> processQuery(SearchQuery query) {
}

return searchClient.search(
query.getQuery(),
query.getPerPage(FALLBACK_PER_PAGE_WEB),
query.getOffset(FALLBACK_PER_PAGE_WEB),
query.getLanguage(),
BingUtils.getMarket(query.getLanguage()),
BingUtils.createFreshness(query.getDateFrom(), query.getDateTo()),
answerTypes.isEmpty() ? null : answerTypes.stream().map(Enum::name).collect(Collectors.joining(","))
query.getQuery(),
query.getPerPage(FALLBACK_PER_PAGE_WEB),
query.getOffset(FALLBACK_PER_PAGE_WEB),
query.getLanguage(),
BingUtils.getMarket(query.getLanguage()),
BingUtils.createFreshness(query.getDateFrom(), query.getDateTo()),
answerTypes.isEmpty() ? null : answerTypes.stream().map(Enum::name).collect(Collectors.joining(","))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ enum ResponseFilter {
@GET
@Path("/search")
Uni<BingResponse> search(
@NotNull @QueryParam("q") String query,
@QueryParam("count") Integer count,
@QueryParam("offset") Integer offset,
@QueryParam("setLang") String language,
@QueryParam("mkt") String market,
@QueryParam("freshness") String freshness,
@QueryParam("responseFilter") String responseFilter
@NotNull @QueryParam("q") String query,
@QueryParam("count") Integer count,
@QueryParam("offset") Integer offset,
@QueryParam("setLang") String language,
@QueryParam("mkt") String market,
@QueryParam("freshness") String freshness,
@QueryParam("responseFilter") String responseFilter
);

/**
Expand All @@ -87,12 +87,12 @@ Uni<BingResponse> search(
@GET
@Path("/images/search")
Uni<BingResponse> searchImages(
@NotNull @QueryParam("q") String query,
@QueryParam("count") Integer count,
@QueryParam("offset") Integer offset,
@QueryParam("setLang") String language,
@QueryParam("mkt") String market,
@QueryParam("freshness") String freshness
@NotNull @QueryParam("q") String query,
@QueryParam("count") Integer count,
@QueryParam("offset") Integer offset,
@QueryParam("setLang") String language,
@QueryParam("mkt") String market,
@QueryParam("freshness") String freshness
);

/**
Expand All @@ -113,12 +113,12 @@ Uni<BingResponse> searchImages(
@Path("/videos/search")
@ClientQueryParam(name = "pricing", value = "free")
Uni<BingResponse> searchVideos(
@NotNull @QueryParam("q") String query,
@QueryParam("count") Integer count,
@QueryParam("offset") Integer offset,
@QueryParam("setLang") String language,
@QueryParam("mkt") String market,
@QueryParam("freshness") String freshness
@NotNull @QueryParam("q") String query,
@QueryParam("count") Integer count,
@QueryParam("offset") Integer offset,
@QueryParam("setLang") String language,
@QueryParam("mkt") String market,
@QueryParam("freshness") String freshness
);

@ClientExceptionMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.l3s.interweb.connector.bing;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

import java.time.LocalDate;

Expand All @@ -22,4 +22,4 @@ void createFreshness() {
void getMarket() {
assertEquals("uk-UA", BingUtils.getMarket("uk"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public Uni<DescribeResults> describe(DescribeQuery query) throws ConnectorExcept
@Override
public Uni<SearchConnectorResults> search(SearchQuery query) throws ConnectorException {
return searchClient.search(
query.getQuery(),
FlickrUtils.getMediaType(query),
DateUtils.toEpochSecond(query.getDateFrom()),
DateUtils.toEpochSecond(query.getDateTo()),
FlickrUtils.convertSort(query.getSort()),
query.getPage(),
query.getPerPage(fallbackPerPage)
query.getQuery(),
FlickrUtils.getMediaType(query),
DateUtils.toEpochSecond(query.getDateFrom()),
DateUtils.toEpochSecond(query.getDateTo()),
FlickrUtils.convertSort(query.getSort()),
query.getPage(),
query.getPerPage(fallbackPerPage)
).map(response -> {
SearchConnectorResults queryResult = new SearchConnectorResults();
queryResult.setTotalResults(response.getPhotos().getTotal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import de.l3s.interweb.connector.flickr.entity.SearchResponse;
import de.l3s.interweb.connector.flickr.entity.GetInfoResponse;
import de.l3s.interweb.connector.flickr.entity.SearchResponse;
import de.l3s.interweb.core.ConnectorException;

/**
Expand Down Expand Up @@ -49,13 +49,13 @@ public interface FlickrSearchClient {
@ClientQueryParam(name = "privacy_filter", value = "1")
@ClientQueryParam(name = "extras", value = "description,tags,owner_name,date_upload,views,media,o_dims,url_s,url_m,url_l,url_o")
Uni<SearchResponse> search(
@NotNull @QueryParam("text") String query,
@QueryParam("media") String media,
@QueryParam("min_upload_date") Integer minUploadDate,
@QueryParam("max_upload_date") Integer maxUploadDate,
@QueryParam("sort") String sort,
@QueryParam("page") Integer page,
@QueryParam("per_page") Integer perPage
@NotNull @QueryParam("text") String query,
@QueryParam("media") String media,
@QueryParam("min_upload_date") Integer minUploadDate,
@QueryParam("max_upload_date") Integer maxUploadDate,
@QueryParam("sort") String sort,
@QueryParam("page") Integer page,
@QueryParam("per_page") Integer perPage
);

/**
Expand All @@ -67,7 +67,7 @@ Uni<SearchResponse> search(
@GET
@ClientQueryParam(name = "method", value = "flickr.photos.getInfo")
Uni<GetInfoResponse> getInfo(
@NotNull @QueryParam("photo_id") String id
@NotNull @QueryParam("photo_id") String id
);

@ClientExceptionMapper
Expand Down
Loading

0 comments on commit 6e7e662

Please sign in to comment.