Skip to content

Commit

Permalink
migrating langchain4j-chatglm (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin7-1 authored Nov 18, 2024
1 parent 33513fe commit a0ffad8
Show file tree
Hide file tree
Showing 21 changed files with 773 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community</artifactId>
<version>0.37.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>langchain4j-community-clickhouse</artifactId>
<name>LangChain4j :: Community :: ClickHouse</name>
<name>LangChain4j :: Community :: Integration :: ClickHouse</name>

<properties>
<clickhouse.version>0.7.0</clickhouse.version>
Expand Down
13 changes: 12 additions & 1 deletion langchain4j-community-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,28 @@

<dependencyManagement>
<dependencies>

<!-- models -->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-chatglm</artifactId>
<version>${project.version}</version>
</dependency>

<!-- embedding stores -->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-clickhouse</artifactId>
<version>${project.version}</version>
</dependency>
<!-- web searchers -->

<!-- web search engines -->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-web-search-engine-searxng</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
77 changes: 77 additions & 0 deletions models/langchain4j-community-chatglm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community</artifactId>
<version>0.37.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>langchain4j-community-chatglm</artifactId>
<name>LangChain4j :: Community :: Integration :: ChatGLM</name>

<dependencies>

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
</dependency>

<!-- DEPENDENCY CONFLICT RESOLUTION FOR OKHTTP (START) -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<!-- DEPENDENCY CONFLICT RESOLUTION FOR OKHTTP (END) -->

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-tinylog</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package dev.langchain4j.community.model.chatglm;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import java.util.List;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_NULL)
@JsonNaming(SnakeCaseStrategy.class)
class ChatCompletionRequest {

private String prompt;
private Double temperature;
private Double topP;
private Integer maxLength;
private List<List<String>> history;

ChatCompletionRequest() {
}

ChatCompletionRequest(String prompt, Double temperature, Double topP, Integer maxLength, List<List<String>> history) {
this.prompt = prompt;
this.temperature = temperature;
this.topP = topP;
this.maxLength = maxLength;
this.history = history;
}

public String getPrompt() {
return prompt;
}

public void setPrompt(String prompt) {
this.prompt = prompt;
}

public Double getTemperature() {
return temperature;
}

public void setTemperature(Double temperature) {
this.temperature = temperature;
}

public Double getTopP() {
return topP;
}

public void setTopP(Double topP) {
this.topP = topP;
}

public Integer getMaxLength() {
return maxLength;
}

public void setMaxLength(Integer maxLength) {
this.maxLength = maxLength;
}

public List<List<String>> getHistory() {
return history;
}

public void setHistory(List<List<String>> history) {
this.history = history;
}

static Builder builder() {
return new Builder();
}

static class Builder {

private String prompt;
private Double temperature;
private Double topP;
private Integer maxLength;
private List<List<String>> history;

Builder prompt(String prompt) {
this.prompt = prompt;
return this;
}

Builder temperature(Double temperature) {
this.temperature = temperature;
return this;
}

Builder topP(Double topP) {
this.topP = topP;
return this;
}

Builder maxLength(Integer maxLength) {
this.maxLength = maxLength;
return this;
}

Builder history(List<List<String>> history) {
this.history = history;
return this;
}

ChatCompletionRequest build() {
return new ChatCompletionRequest(prompt, temperature, topP, maxLength, history);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.langchain4j.community.model.chatglm;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import java.util.List;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_NULL)
@JsonNaming(SnakeCaseStrategy.class)
class ChatCompletionResponse {

private String response;
private List<List<String>> history;
private Integer status;
private String time;

ChatCompletionResponse() {
}

ChatCompletionResponse(String response, List<List<String>> history, Integer status, String time) {
this.response = response;
this.history = history;
this.status = status;
this.time = time;
}

public String getResponse() {
return response;
}

public void setResponse(String response) {
this.response = response;
}

public List<List<String>> getHistory() {
return history;
}

public void setHistory(List<List<String>> history) {
this.history = history;
}

public Integer getStatus() {
return status;
}

public void setStatus(Integer status) {
this.status = status;
}

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.langchain4j.community.model.chatglm;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;

interface ChatGlmApi {

int OK = 200;

@POST(".")
@Headers({"Content-Type: application/json"})
Call<ChatCompletionResponse> chatCompletion(@Body ChatCompletionRequest chatCompletionRequest);
}
Loading

0 comments on commit a0ffad8

Please sign in to comment.