User Profile
AmanKumar
New Member
Joined 1 year ago
User Widgets
Contributions
api connection issues from local to fabric notebook
When I am using my local flask api in fabric notebook I am getting this error. from flask import Flask, request, jsonify import openai from openai import AzureOpenAI # Configuration for Azure OpenAI API # Initialize Flask app app = Flask(__name__) # Initialize the Azure OpenAI client client = AzureOpenAI( azure_endpoint=ENDPOINT_URL, api_key=API_KEY, api_version=API_VERSION, ) # System message for OpenAI GPT MESSAGES = [ {"role": "system", "content": """you are a food concierge. your job is to tell me how long a product will last in my fridge or pantry. I will tell you the name of an edible product, you will simply respond to the amount of days that I can expect the product to be good to eat for from the date of purchase. for example if I ask "eggs" you would respond with "fridge: 20-30 days". Always respond in amount of days."""} ] @app.route('/get_expiry', methods=['POST']) def get_expiry(): # Retrieve product name from POST request JSON data = request.get_json() if not data or 'product' not in data: return jsonify({"error": "Please provide a product name"}), 400 product = data['product'] # Add product to the messages for OpenAI model MESSAGES.append({"role": "user", "content": product}) try: # Call the Azure OpenAI API to get the expiry information completion = client.chat.completions.create( model=MODEL_NAME, messages=MESSAGES, temperature=0.2 ) # Extract and return the result expirytext = completion.choices[0].message.content return jsonify({"product": product, "expiry": expirytext}), 200 except Exception as e: return jsonify({"error": str(e)}), 500 # Run the Flask app if __name__ == '__main__': app.run(debug=True) import requests import json # Define the API endpoint url = 'https://127.0.0.1:5000/get_expiry' # Create the payload with the product name data = { 'product': 'Milk' # Replace with the actual product you want to inquire about } # Send the POST request with JSON data response = requests.post(url, json=data) # Check the response if response.status_code == 200: result = response.json() print(f"Product: {result['product']}") print(f"Expiry Information: {result['expiry']}") else: print(f"Error: {response.json()['error']}") ConnectionError: HTTPSConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /get_expiry (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7bbf00902110>: Failed to establish a new connection: [Errno 111] Connection refused'))Solved1.9KViews1like5Comments
Data Privacy
Microsoft Fabric Community and Privacy
To learn more about how we manage your data, please review the Microsoft Fabric Community Data Privacy guide.