forked from spring-cloud-services-samples/acme-fitness-store
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ef4a1b
commit 656bb23
Showing
11 changed files
with
961 additions
and
833 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 62 additions & 1 deletion
63
apps/acme-assist/src/main/java/com/example/acme/assist/config/FitAssistConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,82 @@ | ||
package com.example.acme.assist.config; | ||
|
||
import com.azure.ai.openai.OpenAIClientBuilder; | ||
import com.azure.core.credential.AzureKeyCredential; | ||
import com.example.acme.assist.AzureOpenAIClient; | ||
import com.example.acme.assist.vectorstore.CosmosDBVectorStore; | ||
import org.springframework.ai.embedding.EmbeddingClient; | ||
import org.springframework.ai.vectorstore.impl.SimplePersistentVectorStore; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
|
||
import java.io.IOException; | ||
|
||
@Configuration | ||
public class FitAssistConfiguration { | ||
|
||
@Value("${spring.ai.azure.openai.embedding-model}") | ||
private String embeddingDeploymentId; | ||
|
||
@Value("${spring.ai.azure.openai.deployment-name}") | ||
private String chatDeploymentId; | ||
|
||
@Value("${spring.ai.azure.openai.endpoint}") | ||
private String endpoint; | ||
|
||
@Value("${spring.ai.azure.openai.api-key}") | ||
private String apiKey; | ||
|
||
@Value("${vector-store.file}") | ||
private String cosmosVectorJsonFile; | ||
|
||
@Value("${spring.data.mongodb.enabled}") | ||
private String cosmosEnabled; | ||
|
||
//@Autowired | ||
private MongoTemplate mongoTemplate; | ||
public FitAssistConfiguration(MongoTemplate mongoTemplate) { | ||
this.mongoTemplate = mongoTemplate; | ||
} | ||
|
||
|
||
|
||
@Value("classpath:/vector_store.json") | ||
private Resource vectorDbResource; | ||
@Bean | ||
public SimplePersistentVectorStore simpleVectorStore(EmbeddingClient embeddingClient) { | ||
SimplePersistentVectorStore simpleVectorStore = new SimplePersistentVectorStore(embeddingClient); | ||
simpleVectorStore.load(vectorDbResource); | ||
if (cosmosEnabled.equals("false")) { | ||
simpleVectorStore.load(vectorDbResource); | ||
} | ||
return simpleVectorStore; | ||
} | ||
|
||
@Bean | ||
public CosmosDBVectorStore vectorStore() throws IOException { | ||
CosmosDBVectorStore store = null; | ||
if (cosmosEnabled.equals("true")) { | ||
store = new CosmosDBVectorStore(mongoTemplate); | ||
String currentPath = new java.io.File(".").getCanonicalPath(); | ||
String path = currentPath + cosmosVectorJsonFile.replace("\\", "//"); | ||
store.loadFromJsonFile(path); | ||
} | ||
else { | ||
store = new CosmosDBVectorStore(null); | ||
} | ||
return store; | ||
} | ||
|
||
@Bean | ||
public AzureOpenAIClient AzureOpenAIClient() { | ||
var innerClient = new OpenAIClientBuilder() | ||
.endpoint(endpoint) | ||
.credential(new AzureKeyCredential(apiKey)) | ||
.buildClient(); | ||
return new AzureOpenAIClient(innerClient, embeddingDeploymentId, chatDeploymentId); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 13 additions & 2 deletions
15
apps/acme-assist/src/main/java/com/example/acme/assist/vectorstore/MetaData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
package com.example.acme.assist.vectorstore;public class MetaData { | ||
} | ||
package com.example.acme.assist.vectorstore; | ||
|
||
public class MetaData { | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
private String name; | ||
} |
Oops, something went wrong.