This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define API key and endpoint | |
$ApiKey = "sk-12345" | |
$ApiEndpoint = "http://localhost:11434/v1/chat/completions" | |
<# | |
System message. | |
You can use this to give the AI instructions on what to do, how to act or how to respond to future prompts. | |
Default value for ChatGPT = "You are a helpful assistant." | |
#> | |
$AiSystemMessage = "You are a helpful AI assistant." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
base_dir=~/.ollama/models | |
manifest_dir=$base_dir/manifests/registry.ollama.ai | |
blob_dir=$base_dir/blobs | |
publicmodels_dir=~/llm-models | |
find "$publicmodels_dir" -type l -exec rm {} + | |
mkdir -p "$publicmodels_dir" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install scikit-learn numpy ollama | |
import ollama | |
import numpy as np | |
from sklearn.metrics.pairwise import cosine_similarity | |
text1 = ollama.embeddings(model='nomic-embed-text', prompt='The sky is blue because of rayleigh scattering') | |
text2 = ollama.embeddings(model='nomic-embed-text', prompt='The sky is cloudy and grey today') | |
vec1 = np.array(text1['embedding']).reshape(1, -1) | |
vec2 = np.array(text2['embedding']).reshape(1, -1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import requests | |
from langchain.llms import Ollama | |
from langchain.document_loaders import WebBaseLoader | |
from langchain.text_splitter import RecursiveCharacterTextSplitter | |
from langchain.embeddings import GPT4AllEmbeddings | |
from langchain.vectorstores import Chroma | |
from langchain.chains import RetrievalQA | |
def main(args): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install chromadb==0.4.15 # need to pin to this version for current langchain version | |
from langchain.llms import Ollama | |
from langchain.document_loaders import WebBaseLoader | |
from langchain.text_splitter import RecursiveCharacterTextSplitter | |
from langchain.embeddings import GPT4AllEmbeddings | |
from langchain.vectorstores import Chroma | |
from langchain.chains import RetrievalQA | |
ollama = Ollama(base_url='http://localhost:11434', model='zephyr:latest') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.express as px | |
import matplotlib.pyplot as plt | |
from collections import Counter | |
import re | |
import sys | |
import nltk | |
from nltk.corpus import stopwords | |
def plot_word_frequencies_matplot(file_path, top): | |
# Load stop words |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
from bs4 import BeautifulSoup | |
from urllib.parse import urljoin, urlparse | |
def is_valid(url, base_url): | |
parsed = urlparse(url) | |
return bool(parsed.netloc) and parsed.netloc == urlparse(base_url).netloc | |
def is_binary(url): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from langchain.chat_models import ChatOllama | |
from langchain.callbacks.manager import CallbackManager | |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler | |
from langchain.schema import HumanMessage | |
chat_model = ChatOllama(model="mistral", base_url = "http://localhost:11434", callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])) | |
#chat_model = ChatOllama(model="mistral") | |
messages = [ | |
HumanMessage(content="Why is the sky blue?") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sentence_transformers import SentenceTransformer | |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2') | |
embeddings = model.encode("A fat tuxedo cat") | |
print(embeddings) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sentence_transformers import SentenceTransformer, util | |
model = SentenceTransformer('all-MiniLM-L6-v2') | |
# Two lists of sentences | |
sentences1 = ['The cat sits outside', | |
'A man is playing guitar', | |
'The new movie is awesome', | |
'Jim can run very fast', | |
'My goldfish is hungry'] |
NewerOlder