forked from Mirror/ollama4j
		
	Added generateEmbeddings API
				
					
				
			This commit is contained in:
		@@ -293,12 +293,12 @@ public class OllamaAPI {
 | 
			
		||||
     *
 | 
			
		||||
     * @param model name of model to generate embeddings from
 | 
			
		||||
     * @param prompt text to generate embeddings for
 | 
			
		||||
     * @return embeddings as double[]
 | 
			
		||||
     * @return embeddings
 | 
			
		||||
     * @throws IOException
 | 
			
		||||
     * @throws ParseException
 | 
			
		||||
     * @throws OllamaBaseException
 | 
			
		||||
     */
 | 
			
		||||
    public double[] generateEmbeddings(String model, String prompt) throws IOException, ParseException, OllamaBaseException {
 | 
			
		||||
    public List<Double> generateEmbeddings(String model, String prompt) throws IOException, ParseException, OllamaBaseException {
 | 
			
		||||
        String url = this.host + "/api/embeddings";
 | 
			
		||||
        String jsonData = String.format("{\"model\": \"%s\", \"prompt\": \"%s\"}", model, prompt);
 | 
			
		||||
        final HttpPost httpPost = new HttpPost(url);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,18 +2,20 @@ package io.github.amithkoujalgi.ollama4j.core.models;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonProperty;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class EmbeddingResponse {
 | 
			
		||||
    @JsonProperty("embedding")
 | 
			
		||||
    private double[] embedding;
 | 
			
		||||
    private List<Double> embedding;
 | 
			
		||||
 | 
			
		||||
    public EmbeddingResponse() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double[] getEmbedding() {
 | 
			
		||||
    public List<Double> getEmbedding() {
 | 
			
		||||
        return embedding;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEmbedding(double[] embedding) {
 | 
			
		||||
    public void setEmbedding(List<Double> embedding) {
 | 
			
		||||
        this.embedding = embedding;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user