Azure OpenAi API - Java vs Python inconsistency

Jack Campbell 0 Reputation points
2024-06-26T18:56:55.3366667+00:00

I using Azure openAI to create an artificial intelligence that creates JSON files. I originally wrote this in python but the requirements of the project changed requiring it to be in Java. Both have the same model and storage configuration but when testing with the same prompt, the python creates a JSON every time and the Java never has created one. I have checked and double checked every part of my program and they seem to be identical except for syntax. In debugging it seems like my system message is not being sent properly.

I would love to see the backend on the Azure side to see what it receives from me but I am unsure if that is possible. Any suggestions on how to debug or fix this inconsistency? Thank you!

Java code:


this.chatMessages = new ArrayList<>(); this.chatMessages.add(new ChatRequestSystemMessage(messageSystem));

this.chatMessages.add(new ChatRequestUserMessage(message));

this.searchConfiguration= new AzureSearchChatExtensionConfiguration(
new AzureSearchChatExtensionParameters(Chat.searchEndpoint, Chat.searchIndexName)
.setSemanticConfiguration(Chat.searchIndexName + "-semantic-configuration")
.setQueryType(AzureSearchQueryType.VECTOR_SEMANTIC_HYBRID)
.setFieldsMapping(
new AzureSearchIndexFieldMappingOptions()
.setContentFieldsSeparator("\n")
.setContentFields(List.of("chunk"))
.setFilepathField("title")
.setTitleField("file_name")
.setUrlField("experiment_id")
.setVectorFields(List.of("text_vector")))
.setInScope(true)
.setRoleInformation(messageSystem)
.setStrictness(2)
.setTopNDocuments(5)
.setAuthentication(new OnYourDataApiKeyAuthenticationOptions(Chat.searchKey))
.setEmbeddingDependency(new OnYourDataDeploymentNameVectorizationSource("text-embedding-ada-002"))
);

ChatCompletionsOptions options = new ChatCompletionsOptions(this.chatMessages)
                                 .setDataSources(List.of(Chat.searchConfiguration))
                                 .setModel(Chat.openaiDeployment)
                                 .setTemperature(0.0)
                                 .setTopP(1.0)
                                 .setMaxTokens(800);

this.currentResponse = this.openaiClient.getChatCompletions(Chat.openaiDeployment, options);
 

Python Code:


  self._message_history = [{"role": "system", "content": self._message_system}]

    self._message_history.append({"role": "user", "content": message})

    self._message_latest =

    self._openai_client.chat.completions.create(
        messages=self._message_history,
        model=self._openai_deployment,
        extra_body={
            "data_sources": [  
                {
                    "type": "azure_search",
                    "parameters": {
                        "endpoint": self._search_endpoint,
                        "index_name": self._search_index_name,
                        "semantic_configuration": self._search_index_name + "-semantic-configuration",
                        "query_type": "vectorSemanticHybrid",
                        "fields_mapping": {
                            "content_fields_separator": "\n",
                            "content_fields": [
                                "chunk"
                            ],
                            "filepath_field": "title",
                            "title_field": "file_name",
                            "url_field": "experiment_id",
                            "vector_fields": [
                                "text_vector"
                            ]
                        },
                        "in_scope": True,
                        "role_information": self._message_system,
                        "filter": None,
                        "strictness": 2,
                        "top_n_documents": 5,
                        "authentication": {
                            "type": "api_key",
                            "key": self._search_key
                        },
                        "embedding_dependency": {
                            "type": "deployment_name",
                            "deployment_name": "text-embedding-ada-002"
                        },
                        "key": self._search_key,
                        "indexName": self._search_index_name
                    }
                }
            ],
        },
        temperature=0,
        top_p=1,
        max_tokens=800,
        stop=None,
    )
Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
851 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,595 questions
0 comments No comments
{count} votes