-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cohere: Add CohereClient and CohereChatModel to support Chat #917
base: main
Are you sure you want to change the base?
Changes from 4 commits
912b9f4
f32aad6
32ef3c4
86781ec
2a02f86
f4791ce
308d79c
a1ea113
b31a642
dbf7844
54e72a5
27bf822
1e874fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public class ChatHistory { | ||
|
||
@NonNull | ||
CohereRole role; | ||
|
||
@NonNull | ||
String message; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@ToString | ||
public class Citation { | ||
Integer start; | ||
|
||
Integer end; | ||
|
||
String text; | ||
|
||
List<String> documentIds; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Builder | ||
public class CohereChatRequest { | ||
|
||
@NonNull | ||
String message; | ||
|
||
String model; | ||
|
||
boolean stream; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason primitives are used in this class? |
||
|
||
String preamble; | ||
|
||
List<ChatHistory> chatHistory; | ||
|
||
String conversationId; | ||
|
||
String promptTruncation; | ||
|
||
List<Connector> connectors; | ||
|
||
boolean searchQueriesOnly; | ||
|
||
List<Map<String, String>> documents; | ||
|
||
Double temperature; | ||
|
||
int maxTokens; | ||
|
||
Integer k; | ||
|
||
Double p; | ||
|
||
Double seed; | ||
|
||
List<String> stopSequences; | ||
|
||
Double frequencyPenalty; | ||
|
||
Double presencePenalty; | ||
|
||
List<Tool> tools; | ||
|
||
List<ToolResult> toolResults; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Getter | ||
public class CohereChatResponse { | ||
|
||
String text; | ||
|
||
String generationId; | ||
|
||
List<Citation> citations; | ||
|
||
List<Map<String, String>> documents; | ||
|
||
boolean isSearchRequired; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason primitives are used in this class? |
||
|
||
List<SearchQuery> searchQueries; | ||
|
||
List<SearchResult> searchResults; | ||
|
||
String finishReason; | ||
|
||
List<ToolCall> toolCalls; | ||
|
||
List<ChatHistory> chatHistory; | ||
|
||
Meta meta; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
public enum CohereRole { | ||
|
||
CHATBOX, | ||
|
||
SYSTEM, | ||
|
||
USER | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
import java.util.Map; | ||
|
||
@Builder | ||
public class Connector { | ||
|
||
@NonNull | ||
String id; | ||
|
||
String userAccessToken; | ||
|
||
boolean continueOnFailure; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason primitives are used in this class? |
||
|
||
Map<String, String> options; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public class ParameterDefinition { | ||
|
||
String description; | ||
|
||
@NonNull | ||
String type; | ||
|
||
boolean required; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason primitives are used in this class? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SearchQuery { | ||
|
||
String text; | ||
|
||
String generationId; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class SearchResult { | ||
|
||
SearchQuery searchQuery; | ||
|
||
Connector connector; | ||
|
||
List<String> documentIds; | ||
|
||
String errorMessage; | ||
|
||
boolean continueOnFailure; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason primitives are used in this class? |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
import java.util.Map; | ||
|
||
@Builder | ||
public class Tool { | ||
|
||
@NonNull | ||
String name; | ||
|
||
@NonNull | ||
String description; | ||
|
||
Map<String, ParameterDefinition> parameterDefinitions; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Builder; | ||
|
||
import java.util.Map; | ||
|
||
@Builder | ||
public class ToolCall { | ||
String name; | ||
Map<String, String> parameters; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.langchain4j.model.cohere; | ||
|
||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Builder | ||
public class ToolResult { | ||
|
||
ToolCall call; | ||
List<Map<String, String>> outputs; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: we are now changing the way classes are organized in the modules. Could you please use the following structure (inside the
internal
package)?