I am learning about different concepts and architectures used in the LLM/AI space and one of them is Retrieval-Augmented Generation. As always I prefer learning concepts by tinkering with them and here is my first attempt at learning about RAG and Vector Databases.
Continue reading Learning about RAG and Vector DatabasesTag Archives: Python
Streamlit Langchain Quickstart App with Azure OpenAI
While there is a QuickStart example on the Streamlit site that shows how to connect to OpenAI using LangChain I thought it would make sense to create Streamlit Langchain Quickstart App with Azure OpenAI.
Continue reading Streamlit Langchain Quickstart App with Azure OpenAIStop pandas truncating output width …
I’m new to pandas (the first time touched it was 45 minutes ago), but I was wondering how can I stop pandas from truncating output width.
You know that annoying ...
at the end of a field?!
So there is a magic display.max_colwidth
option (and many other wonderful options).
Create a free pod index in Pinecone using Python
Pinecone documentation is quite good, but when I wanted to create a free pod index in Pinecone using Python I didn’t know what parameters I should supply.
Specifically, I couldn’t understand what values would be the values for environment
and pod_type
After a bit of digging (looking at the WebUI) here is how to do it
from pinecone import Pinecone, PodSpec pc = Pinecone(api_key='<<PINECONE_API_KEY>>') pc.create_index( name="example-index", dimension=1536, metric="cosine", spec=PodSpec( environment='gcp-starter', pod_type='s1.x1' ) )
My first GenAI use-case
A couple of months ago my wife asked me if I could build her “something” to create a nice image with some thank-you text that she could send to her boutique customers. This is how my first GenAI use-case was born :-).
There are probably definitely services that can do it, but hey that was an opportunity to learn, so I jumped straight into it.
The Gen AI part turned out to be the easy one, but if you want to skip the rest you can jump straight to it.
Continue reading My first GenAI use-caseGetting ImageAnalysisResultDetails in Azure AI Vision Python SDK
Getting ImageAnalysisResultDetails in Azure AI Vision Python SDK.
Sometimes when using Azure AI Python SDK you will not get the expected result, meaning that the reason property of the result of the analyze method of the ImageAnalyzer class the property will not be equal to sdk.ImageAnalysisResultReason.ANALYZED.
Phew, that’s a mouthful, easier to show it code:
Continue reading Getting ImageAnalysisResultDetails in Azure AI Vision Python SDKFormat Scrapy Export
Here is how you can format Scrapy export of your items
For all of these options make sure that your spider actually yields some results in your parse
method.
Python – Test Network Connection
The below will return True/False
import socket def test_connection(host="8.8.8.8", port=53, timeout=3): try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True except Exception as ex: #print ex.message return False destination_host = "mymachine.company" destination_port = 9997 timeout = 2 test_result = test_connection(destination_host, destination_port, timeout)
Or you can use this version to return the Exception in case connection has failed
import socket def test_connection(host="8.8.8.8", port=53, timeout=3): try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True, None except Exception as ex: #print ex.message return False, ex.message destination_host = "mymachine.company" destination_port = 9997 timeout = 2 test_result, ex = test_connection(destination_host, destination_port, timeout)
Python – Get local machine IP
Here is how to use Python – to Get local machine IP
import socket def get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: # doesn't even have to be reachable s.connect(('10.255.255.255', 1)) IP = s.getsockname()[0] except: IP = '127.0.0.1' finally: s.close() return IP