Skip to content

Commit 7d3e877

Browse files
authored
Update java, python samples for param renames (#156)
* migrate to azure open ai * managed identity update for azure openai * add text completion tests * add file prompts tests * refactor and add unit tests * remove local dev test * add no build to test task * update out of proc worker and changelog * update powershell and node samples * update java library * update assistant message * remove constructor * update changelog files * remove reference to Microsoft.Azure.WebJobs.Script.Abstractions * address review comments * Input to Request, internalsvisible in csproj * use model default constants * null check * support reasoning models * update readme files * remove unintended file * update java samples * python files formatting and flake8 fixes * update changelog files and release variables * correct date format * update changelog dates * correct date format * update python samles * update java samples for reasoningmodel * update embeddings readme
1 parent 324436d commit 7d3e877

File tree

46 files changed

+391
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+391
-221
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Starting v0.13.0 for Microsoft.Azure.WebJobs.Extensions.OpenAI.Kusto, it will ma
99

1010
Starting v0.1.0 for Microsoft.Azure.WebJobs.Extensions.OpenAI.AzureAISearch, it will maintain its own [Changelog](./src/WebJobs.Extensions.OpenAI)
1111

12-
## v0.19.0 - Unreleased
12+
## v0.19.0 - 2025/05/05
1313

1414
### Breaking
1515

java-library/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## v0.5.0 - Unreleased
8+
## v0.5.0 - 2025/05/05
99

1010
### Breaking
1111

java-library/pom.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,14 @@
3737

3838
<developers>
3939
<developer>
40-
<id>amamounelsayed</id>
41-
<name>Ahmed El Sayed</name>
42-
<email>ahelsaye@microsoft.com</email>
40+
<id>vameru</id>
41+
<name>Varad Meru</name>
42+
<email>vameru@microsoft.com</email>
4343
</developer>
4444
<developer>
45-
<id>shreyas-gopalakrishna</id>
46-
<name>Shreyas Gopalakrishna</name>
47-
<email>[email protected]</email>
48-
</developer>
49-
<developer>
50-
<id>kamperiadis</id>
51-
<name>Kirstyn Joy Amperiadis</name>
52-
<email>[email protected]</email>
45+
<id>manvkaur</id>
46+
<name>Manvir Kaur</name>
47+
<email>[email protected]</email>
5348
</developer>
5449
</developers>
5550

java-library/src/main/java/com/microsoft/azure/functions/openai/annotation/assistant/AssistantPost.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@
132132
String maxTokens() default "100";
133133

134134
/**
135-
* Indicates whether the assistant uses a reasoning model.
135+
* Indicates whether the chat completion api uses a reasoning model.
136136
*
137-
* @return {@code true} if the assistant is based on a reasoning model; {@code false} otherwise.
137+
* @return {@code true} if the chat completion api is based on a reasoning model; {@code false} otherwise.
138138
*/
139139
boolean isReasoningModel() default false;
140140
}

java-library/src/main/java/com/microsoft/azure/functions/openai/annotation/search/SemanticSearch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ String systemPrompt() default "You are a helpful assistant. You are responding t
140140
String maxTokens() default "2048";
141141

142142
/**
143-
* Indicates whether the assistant uses a reasoning model.
143+
* Indicates whether the chat completion api uses a reasoning model.
144144
*
145-
* @return {@code true} if the assistant is based on a reasoning model; {@code false} otherwise.
145+
* @return {@code true} if the chat completion api is based on a reasoning model; {@code false} otherwise.
146146
*/
147-
boolean isReasoningModel();
147+
boolean isReasoningModel() default false;
148148
}

java-library/src/main/java/com/microsoft/azure/functions/openai/annotation/textcompletion/TextCompletion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
String maxTokens() default "100";
9393

9494
/**
95-
* Indicates whether the assistant uses a reasoning model.
95+
* Indicates whether the chat completion api uses a reasoning model.
9696
*
97-
* @return {@code true} if the assistant is based on a reasoning model; {@code false} otherwise.
97+
* @return {@code true} if the chat completion api is based on a reasoning model; {@code false} otherwise.
9898
*/
99-
boolean isReasoningModel();
99+
boolean isReasoningModel() default false;
100100
}

samples/assistant/java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<java.version>1.8</java.version>
1616
<azure.functions.maven.plugin.version>1.29.0</azure.functions.maven.plugin.version>
1717
<azure.functions.java.library.version>3.1.0</azure.functions.java.library.version>
18-
<azure-functions-java-library-openai>0.4.0-preview</azure-functions-java-library-openai>
18+
<azure-functions-java-library-openai>0.5.0-preview</azure-functions-java-library-openai>
1919
<functionAppName>azfs-java-openai-sample</functionAppName>
2020
</properties>
2121

samples/assistant/java/src/main/java/com/azfs/AssistantApis.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ public HttpResponseMessage postUserResponse(
108108
route = "assistants/{assistantId}")
109109
HttpRequestMessage<Optional<String>> request,
110110
@BindingName("assistantId") String assistantId,
111-
@AssistantPost(name="newMessages", id = "{assistantId}", model = "%CHAT_MODEL_DEPLOYMENT_NAME%", userMessage = "{Query.message}", chatStorageConnectionSetting = DEFAULT_CHATSTORAGE, collectionName = DEFAULT_COLLECTION) AssistantState state,
111+
@AssistantPost(name="newMessages", id = "{assistantId}", chatModel = "%CHAT_MODEL_DEPLOYMENT_NAME%", userMessage = "{Query.message}", chatStorageConnectionSetting = DEFAULT_CHATSTORAGE, collectionName = DEFAULT_COLLECTION) AssistantState state,
112112
final ExecutionContext context) {
113113

114-
List<ChatMessage> recentMessages = state.getRecentMessages();
114+
List<AssistantMessage> recentMessages = state.getRecentMessages();
115115
String response = recentMessages.isEmpty() ? "No response returned." : recentMessages.get(recentMessages.size() - 1).getContent();
116116

117117
return request.createResponseBuilder(HttpStatus.OK)

samples/assistant/java/src/main/java/com/azfs/AssistantSkills.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public List<TodoItem> getTodos(
6060
}
6161

6262
private TodoManager createTodoManager() {
63-
String cosmosDbConnectionEndpoint = System.getenv("CosmosDbConnectionEndpoint").trim();
63+
String cosmosDbConnectionEndpoint = System.getenv("CosmosDbConnectionEndpoint");
6464

6565
if (cosmosDbConnectionEndpoint == null || cosmosDbConnectionEndpoint.isEmpty()) {
6666
return new InMemoryTodoManager();
@@ -69,7 +69,7 @@ private TodoManager createTodoManager() {
6969
.build();
7070

7171
CosmosClient cosmosClient = new CosmosClientBuilder()
72-
.endpoint(cosmosDbConnectionEndpoint)
72+
.endpoint(cosmosDbConnectionEndpoint.trim())
7373
.credential(credential)
7474
.buildClient();
7575
return new CosmosDbTodoManager(cosmosClient);

samples/assistant/python/assistant_apis.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
DEFAULT_CHAT_STORAGE_SETTING = "AzureWebJobsStorage"
77
DEFAULT_CHAT_COLLECTION_NAME = "ChatState"
88

9+
910
@apis.function_name("CreateAssistant")
1011
@apis.route(route="assistants/{assistantId}", methods=["PUT"])
1112
@apis.assistant_create_output(arg_name="requests")
12-
def create_assistant(req: func.HttpRequest, requests: func.Out[str]) -> func.HttpResponse:
13+
def create_assistant(
14+
req: func.HttpRequest, requests: func.Out[str]
15+
) -> func.HttpResponse:
1316
assistantId = req.route_params.get("assistantId")
1417
instructions = """
1518
Don't make assumptions about what values to plug into functions.
@@ -19,27 +22,44 @@ def create_assistant(req: func.HttpRequest, requests: func.Out[str]) -> func.Htt
1922
"id": assistantId,
2023
"instructions": instructions,
2124
"chatStorageConnectionSetting": DEFAULT_CHAT_STORAGE_SETTING,
22-
"collectionName": DEFAULT_CHAT_COLLECTION_NAME
25+
"collectionName": DEFAULT_CHAT_COLLECTION_NAME,
2326
}
2427
requests.set(json.dumps(create_request))
2528
response_json = {"assistantId": assistantId}
26-
return func.HttpResponse(json.dumps(response_json), status_code=202, mimetype="application/json")
29+
return func.HttpResponse(
30+
json.dumps(response_json), status_code=202, mimetype="application/json"
31+
)
2732

2833

2934
@apis.function_name("PostUserQuery")
3035
@apis.route(route="assistants/{assistantId}", methods=["POST"])
31-
@apis.assistant_post_input(arg_name="state", id="{assistantId}", user_message="{Query.message}", model="%CHAT_MODEL_DEPLOYMENT_NAME%", chat_storage_connection_setting=DEFAULT_CHAT_STORAGE_SETTING, collection_name=DEFAULT_CHAT_COLLECTION_NAME)
36+
@apis.assistant_post_input(
37+
arg_name="state",
38+
id="{assistantId}",
39+
user_message="{Query.message}",
40+
chat_model="%CHAT_MODEL_DEPLOYMENT_NAME%",
41+
chat_storage_connection_setting=DEFAULT_CHAT_STORAGE_SETTING,
42+
collection_name=DEFAULT_CHAT_COLLECTION_NAME,
43+
)
3244
def post_user_response(req: func.HttpRequest, state: str) -> func.HttpResponse:
3345
# Parse the JSON string into a dictionary
3446
data = json.loads(state)
3547

3648
# Extract the content of the recentMessage
37-
recent_message_content = data['recentMessages'][0]['content']
38-
return func.HttpResponse(recent_message_content, status_code=200, mimetype="text/plain")
49+
recent_message_content = data["recentMessages"][0]["content"]
50+
return func.HttpResponse(
51+
recent_message_content, status_code=200, mimetype="text/plain"
52+
)
3953

4054

4155
@apis.function_name("GetChatState")
4256
@apis.route(route="assistants/{assistantId}", methods=["GET"])
43-
@apis.assistant_query_input(arg_name="state", id="{assistantId}", timestamp_utc="{Query.timestampUTC}", chat_storage_connection_setting=DEFAULT_CHAT_STORAGE_SETTING, collection_name=DEFAULT_CHAT_COLLECTION_NAME)
57+
@apis.assistant_query_input(
58+
arg_name="state",
59+
id="{assistantId}",
60+
timestamp_utc="{Query.timestampUTC}",
61+
chat_storage_connection_setting=DEFAULT_CHAT_STORAGE_SETTING,
62+
collection_name=DEFAULT_CHAT_COLLECTION_NAME,
63+
)
4464
def get_chat_state(req: func.HttpRequest, state: str) -> func.HttpResponse:
4565
return func.HttpResponse(state, status_code=200, mimetype="application/json")

0 commit comments

Comments
 (0)