Stream-With-And-Without-Genr

Fri 14 November 2025
from constants import OPENAI_API_KEY
!pip show langchain-openai | grep "Version:"
Version: 0.2.9
import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o-mini")
from langchain_core.output_parsers import (
    JsonOutputParser,
)


# A function that operates on finalized inputs
# rather than on an input_stream
def _extract_country_names(inputs):
    """A function …

Category: langchain

Read More

Streams

Fri 14 November 2025
from constants import OPENAI_API_KEY
!pip show langchain-openai | grep "Version:"
Version: 0.2.9
import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o-mini")
chunks = []
for chunk in model.stream("what color is the sky?"):
    chunks.append(chunk)
    print(chunk.content, end="|", flush=True)
|The| color …

Category: langchain

Read More

Streams-Retriever

Fri 14 November 2025
!python --version
Python 3.12.4
from constants import OPENAI_API_KEY
!pip show langchain-openai | grep "Version:"
Version: 0.2.9
import os
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o-mini")
!pip install faiss-cpu
Collecting faiss-cpu
  Downloading faiss_cpu-1.9.0.post1-cp312-cp312-manylinux_2_17_x86_64 …

Category: langchain

Read More

String-Split

Fri 14 November 2025

content = """
one
two
"""
# Split content into lines and skip empty lines
lines = [line for line in content.splitlines() if line.strip()]
print(lines)
['one', 'two']


Score: 0

Category: langchain

Read More

String-To-Dataframe

Fri 14 November 2025

title: "String to Dataframe" author: "Rj" date: 2019-04-22 description: "-" type: technical_note draft: false


import numpy as np
import pandas as pd
from io import StringIO
content = """
    1, 2
    3, 4
    5, 6
"""
content
'\n    1, 2\n    3, 4\n    5, 6\n'
df = pd.read_csv(StringIO(content), header=None …

Category: data-wrangling

Read More

Student-Hiring

Fri 14 November 2025
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier, export_graphviz
import pydotplus
from IPython.display import Image

# Create a custom student dataset
data = {
    "GPA": [3.5, 3.0, 3.8, 3.2, 3.6, 2.8, 3.9, 2.5, 3.1, 3.7],
    "Internship …

Category: pydotplus

Read More

Subplot Simple

Fri 14 November 2025

title: "Sub Plot Simple" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


import matplotlib.pyplot as plt

python_course_green = "#476042"
plt.figure(figsize=(6, 4))
plt.subplot(221) # equivalent to: plt.subplot(2, 2, 1)
<matplotlib.axes._subplots.AxesSubplot at 0x11365e1d0>
plt.text(0.5, # x coordinate, 0 …

Category: plot

Read More

Sum-As-New-Column

Fri 14 November 2025

title: "Sum as a new column" author: "Rj" date: 2019-04-22 description: "-" type: technical_note draft: false


import numpy as np
import pandas as pd
df = pd.read_csv('abc.csv')
df
student language science …

Category: data-wrangling

Read More

Sum-Of-All

Fri 14 November 2025

title: "Sum of All on NA" author: "Rj" date: 2019-04-22 description: "-" type: technical_note draft: false


import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10, 5))
df

Category: data-wrangling

Read More

Sys-Traceback-1

Fri 14 November 2025

import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml311; pyv: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0]'
print(pyu.ps2("haystack-ai ollama-haystack python-dotenv"))
haystack-ai==2.8.0
ollama-haystack is not installed in the current environment.
python-dotenv==0.21.0
import traceback
def divide_numbers …

Category: basics

Read More
Page 135 of 146

« Prev Next »