Skip to main content

OpenAI

Maven Dependency

Plain Java

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
<version>1.0.0-alpha1</version>
</dependency>

Spring Boot

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai-spring-boot-starter</artifactId>
<version>1.0.0-alpha1</version>
</dependency>

Creating OpenAiEmbeddingModel

Plain Java

EmbeddingModel model = OpenAiEmbeddingModel.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
...
.build();

Spring Boot

Add to the application.properties:

langchain4j.open-ai.embedding-model.api-key=${OPENAI_API_KEY}
langchain4j.open-ai.embedding-model.base-url=...
langchain4j.open-ai.embedding-model.custom-headers=...
langchain4j.open-ai.embedding-model.dimensions=...
langchain4j.open-ai.embedding-model.log-requests=...
langchain4j.open-ai.embedding-model.log-responses=...
langchain4j.open-ai.embedding-model.max-retries=...
langchain4j.open-ai.embedding-model.model-name=...
langchain4j.open-ai.embedding-model.organization-id=...
langchain4j.open-ai.embedding-model.proxy.host=...
langchain4j.open-ai.embedding-model.proxy.port=...
langchain4j.open-ai.embedding-model.proxy.type=...
langchain4j.open-ai.embedding-model.timeout=...
langchain4j.open-ai.embedding-model.user=...

Examples