Skip to content

Commit 74960c0

Browse files
Merge pull request #262 from oracle/248-mcp-langchain-export
update to SpringAI export
2 parents 0f2e2cd + e12a7a7 commit 74960c0

File tree

11 files changed

+18
-15
lines changed

11 files changed

+18
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ src/client/spring_ai/target/classes/*
6969
api_server_key
7070
.env
7171

72+
optimizer_settings.json

docs/content/advanced/springai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export OPENAI_EMBEDDING_MODEL=text-embedding-3-small
4141
export OLLAMA_CHAT_MODEL="llama3.1"
4242
export OLLAMA_EMBEDDING_MODEL=mxbai-embed-large
4343
export OLLAMA_BASE_URL="http://<OLLAMA_SERVER>:11434"
44-
export CONTEXT_INSTR=" You are an assistant for question-answering tasks. Use the retrieved Documents and history to answer the question as accurately and comprehensively as possible. Keep your answer grounded in the facts of the Documents, be concise, and reference the Documents where possible. If you don't know the answer, just say that you are sorry as you don't haven't enough information. "
44+
export SYS_INSTR=" You are an assistant for question-answering tasks. Use the retrieved Documents and history to answer the question as accurately and comprehensively as possible. Keep your answer grounded in the facts of the Documents, be concise, and reference the Documents where possible. If you don't know the answer, just say that you are sorry as you don't haven't enough information. "
4545
export TOP_K=4
4646
export VECTOR_STORE=TEXT_EMBEDDING_3_SMALL_8191_1639_COSINE
4747
export PROVIDER=openai

src/client/content/config/tabs/settings.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,32 @@ def spring_ai_conf_check(ll_model: dict, embed_model: dict) -> str:
172172

173173
def spring_ai_obaas(src_dir, file_name, provider, ll_config, embed_config):
174174
"""Get the users CTX Prompt"""
175-
ctx_prompt = next(
175+
176+
sys_prompt = next(
176177
item["prompt"]
177178
for item in state.prompt_configs
178-
if item["name"] == state.client_settings["prompts"]["ctx"] and item["category"] == "ctx"
179+
if item["name"] == state.client_settings["prompts"]["sys"] and item["category"] == "sys"
179180
)
180-
181+
logger.info(f"Prompt used in export:\n{sys_prompt}")
181182
with open(src_dir / "templates" / file_name, "r", encoding="utf-8") as template:
182183
template_content = template.read()
183184

184185
database_lookup = st_common.state_configs_lookup("database_configs", "name")
185186

186187
formatted_content = template_content.format(
187188
provider=provider,
188-
ctx_prompt=f"{ctx_prompt}",
189+
sys_prompt=f"{sys_prompt}",
189190
ll_model=ll_config,
190191
vector_search=embed_config,
191192
database_config=database_lookup[state.client_settings["database"]["alias"]],
192193
)
193194

194195
if file_name.endswith(".yaml"):
195-
ctx_prompt = json.dumps(ctx_prompt, indent=True) # Converts it into a valid JSON string (preserving quotes)
196+
sys_prompt = json.dumps(sys_prompt, indent=True) # Converts it into a valid JSON string (preserving quotes)
196197

197198
formatted_content = template_content.format(
198199
provider=provider,
199-
ctx_prompt=ctx_prompt,
200+
sys_prompt=sys_prompt,
200201
ll_model=ll_config,
201202
vector_search=embed_config,
202203
database_config=database_lookup[state.client_settings["database"]["alias"]],

src/client/spring_ai/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export OPENAI_EMBEDDING_MODEL=text-embedding-3-small
3232
export OLLAMA_CHAT_MODEL="llama3.1"
3333
export OLLAMA_EMBEDDING_MODEL=mxbai-embed-large
3434
export OLLAMA_BASE_URL="http://<OLLAMA_SERVER>:11434"
35-
export CONTEXT_INSTR=" You are an assistant for question-answering tasks. Use the retrieved Documents and history to answer the question as accurately and comprehensively as possible. Keep your answer grounded in the facts of the Documents, be concise, and reference the Documents where possible. If you don't know the answer, just say that you are sorry as you don't haven't enough information. "
35+
export SYS_INSTR=" You are an assistant for question-answering tasks. Use the retrieved Documents and history to answer the question as accurately and comprehensively as possible. Keep your answer grounded in the facts of the Documents, be concise, and reference the Documents where possible. If you don't know the answer, just say that you are sorry as you don't haven't enough information. "
3636
export TOP_K=4
3737
export VECTOR_STORE=TEXT_EMBEDDING_3_SMALL_8191_1639_COSINE
3838
export PROVIDER=openai

src/client/spring_ai/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.4.5</version>
9+
<version>3.4.9</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.example</groupId>

src/client/spring_ai/src/main/java/org/springframework/ai/openai/samples/helloworld/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public String legacyTable(@Value("${aims.vectortable.name}") String table) {
3535
}
3636

3737
@Bean
38-
public String contextInstr(@Value("${aims.context_instr}") String instr) {
38+
public String contextInstr(@Value("${aims.sys_instr}") String instr) {
3939
return instr;
4040
}
4141

src/client/spring_ai/src/main/java/org/springframework/ai/openai/samples/helloworld/PromptBuilderService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ public Prompt buildPrompt(String message, String contextInstr, int topK) {
3737
3838
INSTRUCTIONS:""";
3939

40+
// That's a standard RAG instruction, provided for convenience to change the contextInstr coming by the Oracle AI Optimizer export
4041
String defaultInstr = """
4142
Answer the users question using the DOCUMENTS text above.
4243
Keep your answer ground in the facts of the DOCUMENTS.
4344
If the DOCUMENTS doesn’t contain the facts to answer the QUESTION, return:
4445
I'm sorry but I haven't enough information to answer.
4546
""";
4647

47-
template += "\n" + defaultInstr;
48+
template += "\n" + contextInstr;
4849

4950
List<Document> similarDocuments = vectorStore.similaritySearch(
5051
SearchRequest.builder().query(message).topK(topK).build());

src/client/spring_ai/src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spring:
5252
options:
5353
model: ${OLLAMA_EMBEDDING_MODEL}
5454
aims:
55-
context_instr: ${CONTEXT_INSTR}
55+
sys_instr: ${SYS_INSTR}
5656
vectortable:
5757
name: ${VECTOR_STORE}
5858
rag_params:

src/client/spring_ai/templates/obaas.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ spring:
4141
options:
4242
model: \"{vector_search[id]}\"
4343
aims:
44-
context_instr: \"{ctx_prompt}\"
44+
sys_instr: \"{sys_prompt}\"
4545
vectortable:
4646
name: {vector_search[vector_store]}
4747
rag_params:

src/client/spring_ai/templates/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export DB_USERNAME="{database_config[user]}"
3838
export DB_PASSWORD="{database_config[password]}"
3939
export DISTANCE_TYPE="{vector_search[distance_metric]}"
4040
export INDEX_TYPE="{vector_search[index_type]}"
41-
export CONTEXT_INSTR="{ctx_prompt}"
41+
export SYS_INSTR="{sys_prompt}"
4242
export TOP_K="{vector_search[top_k]}"
4343

4444
export VECTOR_STORE="{vector_search[vector_store]}"

0 commit comments

Comments
 (0)