DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Ethics in the Age of AI: The Human and Moral Impact of AI
  • Efficient Ticket Management Using LangChain and Large Language Models
  • Lost in Translation: Gaps of GPT-3.5 in South Asian and Middle Eastern Languages
  • ChatGPT Integration With Python: Unleashing the Power of AI Conversation

Trending

  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • Segmentation Violation and How Rust Helps Overcome It
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Accurate Quantitative Analysis With ChatGPT and Azure AI Hub

Accurate Quantitative Analysis With ChatGPT and Azure AI Hub

I asked ChatGPT the question, ‘9.9 or 9.11, which is bigger?’ ChatGPT alone answered incorrectly, but with the help of Python, it provided the correct answer: 9.9.

By 
Sanjeev Kumar user avatar
Sanjeev Kumar
·
Mar. 27, 25 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
2.7K Views

Join the DZone community and get the full member experience.

Join For Free

LLMs are not very good at quantitative analysis. For example, when I asked ChatGPT, "Which number is bigger, 9.9 or 9.11?" it incorrectly responded with 9.11.

In another example, I have an Excel file containing a large amount of quantitative data. The maximum word count for a single prompt that ChatGPT can handle is around 4,000 words (approximately 16,000 characters). If I try to query this data, it may not fit within the context window. 

I can store the file in a data source and train ChatGPT to use that data source for user queries (check this article if you want to learn how to train ChatGPT on private data). However, since the file contains quantitative data, there is a chance that I might receive incorrect answers for complex queries.

How can such a problem be resolved? The answer likely involves a combination of data analysis using Python and LLMs.

Let's help ChatGPT provide the correct answer to “9.9 or 9.11, which number is bigger.”

A Step-by-Step Guide

Log in with https://ai.azure.com and click on Create project.

Click on Create project


Give the Project a name; here, I named it LLM_Python, and clicked on Create.

Give the Project a name


Now, it is time to deploy an LLM like ChatGPT. Click on Models + endpoints.

Click on Models + endpoints


Click on Deploy base model.

Click on Deploy base model

Select the LLM of your choice. I have selected gtp-4o-mini. Next, click on Confirm.

Select the LLM of your choice

Click on Deploy. This step completes the deployment of LLM, which is gpt-4o-min in this example.

Deploy the LLM


Click on Prompt flow.

Click on Prompt flow


Click on + Create.

Click on + Create

Click on Create on Standard flow.

Click on Create on Standard flow


Wait a couple of minutes because the new flow takes some time to propagate. Give a Folder name (I have given it codefolder) and then click on Create.

Create a new flow


The prompt is ready now. To customize the programming, click on the delete button under the red circle.

Click on the delete button to customize the programming


Click on + Add input.

Click on + Add input


I selected Question for Input name and 9.9 or 9.11 which number is bigger? for the Value. Basically, this is a user question to chat-4o-mini (LLM).

Select Question and 9.9 or 9.11 which number is bigger?


Now click on + LLM and provide the node name, I gave node name FirstLLMCall and clicked on Add.

Now click on + LLM and provide the node name


Select the highlighted values as per your project and provide instructions to the LLM for what you want it to do. I want the LLM to extract two numbers from the user input. Below are the instructions for gpt-40-mini (LLM):

#system:

You are a helpful assistant.

#user:

Extract the two numbers from the following question: "{{user_query}}".

Return only a valid JSON object without any extra formatting or explanations.

Ensure it is properly structured like this:

JSON
 
{
  "num1": 19.9,
  "num2": 19.11
}


Add the prompt


Click on Start compute session. It will take around 10 minutes to complete.

Click on Start compute session


Once Start compute session changes to Compute session running, click on Validate and parse input.

Click on Validate and parse input


Select ${inputs.Question} from Value box. It stores user input and passes it to LLM.

Select ${inputs.Question} from Value box


Click on + Python to write code to get greater value from user-provided numbers.

Click on + Python


Provide a node name for Python; I gave it PythonCode. Next, click on Add.

Provide a node name for Python


Copy and paste the below Python code in the PythonCode prompt:

Python
 
import json
from promptflow import tool
@tool
def find_max_number(input_json: str) -> str:
    """
    This function takes a JSON string with two numbers,
    finds the maximum, and returns the result as a JSON string.
    """
    # Read extracted numbers from the previous ChatGPT output
    input_data = json.loads(input_json)
    num1 = float(input_data["num1"])
    num2 = float(input_data["num2"])

    # Find the maximum number
    max_number = max(num1, num2)

    # Return the result in JSON format
    output_json = json.dumps({"num1": num1, "num2": num2, "max_number": max_number})
    return output_json


Paste the Python code


Click on Validate and parse input.

Click on Validate and parse input


Now, select $FirstLLMCall.output in Value.

Select $FirstLLMCall.output


We need another instance of an LLM to provide answers to user questions based on the output of the above Python code. Click on LLM to proceed.

Click on LLM


I gave the node the name AnsweringLLM and clicked on Add.

Give the node name and click Add


Select values for AnsweringLLM.

Select values for AnsweringLLM


Write code on AnsweringLLM and click on Validate and parse input.

#system:

You are a helpful assistant.

# user:

The numbers extracted are {{num1}} and {{num2}}. The bigger number is {{max_number}}.

Give your answer in 1 line only.

Write code on AnsweringLLM and click on Validate and parse input


Select inputs for the AnsweringLLM.

Select inputs


Click on + Add output, as the user will be provided output from AnsweringLLM.

Click on + Add output

In the Answer value, select ${AnsweringLLM.output}.

Select ${AnsweringLLM.output}

Below is the flow of requests:

Flow of requests


Click on Save and then Run.

Click on Save and then Run


Now, click on View outputs to check what was the answer to the user question.

Click on View outputs


We got the correct answers this time.

The correct answer!


Summary

When we asked the question, ‘9.9 or 9.11, which number is bigger?’ The answer was 9.11. This indicates that ChatGPT was unable to provide the correct answer for quantitative data, but with the help of Python, ChatGPT provided the correct answer, so in such a situation, it is better to use Python with LLM.

AI Python (language) ChatGPT large language model

Opinions expressed by DZone contributors are their own.

Related

  • Ethics in the Age of AI: The Human and Moral Impact of AI
  • Efficient Ticket Management Using LangChain and Large Language Models
  • Lost in Translation: Gaps of GPT-3.5 in South Asian and Middle Eastern Languages
  • ChatGPT Integration With Python: Unleashing the Power of AI Conversation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!