Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Feature/add dimension in embedding #472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.theokanning.openai.embedding;

/**
* Enum to represent the available OpenAI embedding models
*/
public enum EmbeddingModel {

TEXT_EMBEDDING_ADA_002("text-embedding-ada-002", 2),
TEXT_EMBEDDING_V3_SMALL("text-embedding-3-small", 3),
TEXT_EMBEDDING_V3_LARGE("text-embedding-3-large", 3),
;

private final String modelName;
private final Integer generation;

/**
* Constructor.
*
* @param modelName the value of the enum
*/
EmbeddingModel(String modelName, Integer generation) {
this.modelName = modelName;
this.generation = generation;
}

/**
* Method to return enum from a string value.
*
* @param value the value to convert to an enum
* @return the enum value
*/
public static EmbeddingModel fromValue(String value) {
for (EmbeddingModel b : EmbeddingModel.values()) {
if (b.modelName.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

/**
* Method to return the value of the enum.
*
* @return the value of the enum
*/
public Integer getGeneration() {
return generation;
}

/**
* Method to return the value of the enum.
*
* @return the value of the enum
*/
@Override
public String toString() {
return modelName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,27 @@ public class EmbeddingRequest {
* A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse.
*/
String user;

/**
* The number of dimensions to be used by the model to represent each input text as the feature
* vector.
*/
@Setter(AccessLevel.NONE)
Integer dimensions = null;

/**
* Set the number of dimensions to be used by the model to represent each input text as the feature vector.
*
* @param dimensions The number of dimensions to be used by the model. Only supported for models from or after
* third generation.
*/
public void setDimensions(Integer dimensions) {
EmbeddingModel embeddingModel = EmbeddingModel.fromValue(this.model);

if (embeddingModel.getGeneration() > 2) {
this.dimensions = dimensions;
} else {
this.dimensions = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public interface OpenAiApi {
@POST("/v1/engines/{engine_id}/completions")
Single<CompletionResult> createCompletion(@Path("engine_id") String engineId, @Body CompletionRequest request);

@Deprecated
@POST("/v1/edits")
Single<EditResult> createEdit(@Body EditRequest request);

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.theokanning.openai-gpt3-java
VERSION_NAME=0.18.2
VERSION_NAME=0.18.3

POM_URL=https://github.com/theokanning/openai-java
POM_SCM_URL=https://github.com/theokanning/openai-java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.junit.jupiter.api.Assertions.assertNotNull;

@Deprecated
public class EditTest {

String token = System.getenv("OPENAI_TOKEN");
Expand Down