This file contains 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
# source: https://platform.openai.com/docs/guides/gpt/function-calling | |
import openai | |
import json | |
# Example dummy function hard coded to return the same weather | |
# In production, this could be your backend API or an external API | |
def get_current_weather(location, unit="fahrenheit"): | |
"""Get the current weather in a given location""" | |
weather_info = { | |
"location": location, |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
def get_dataset_partitions_pd(df, train_split=0.8, val_split=0.1, test_split=0.1, target_variable=None): | |
assert (train_split + test_split + val_split) == 1 | |
# Only allows for equal validation and test splits | |
assert val_split == test_split | |
# Shuffle | |
df_sample = df.sample(frac=1, random_state=12) |
This file contains 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 fpdf | |
def make_pdf(text): | |
"""Makes a PDF file from the given text.""" | |
# Create a new FPDF object. | |
pdf = fpdf.FPDF() | |
# Add a page to the PDF object. | |
pdf.add_page() |
This file contains 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 openai import OpenAI | |
client = OpenAI() | |
def get_response(prompt_question): | |
response = client.chat.completions.create( | |
model="gpt-3.5-turbo-16k", | |
messages=[{"role": "system", "content": "You are a helpful research and\ | |
programming assistant"}, | |
{"role": "user", "content": prompt_question}] |
This file contains 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 tiktoken | |
def get_num_tokens(prompt, model="gpt-3.5-turbo"): | |
"""Calculates the number of tokens in a text prompt""" | |
enc = tiktoken.encoding_for_model("gpt-3.5-turbo") | |
return len(enc.encode(prompt)) | |
This file contains 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.document_loaders import PyPDFLoader | |
loader = PyPDFLoader('./jung1.pdf') | |
pdf_doc = loader.load_and_split() | |
for page in pdf_doc: | |
print(page.page_content) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 re | |
text = """https://www.notion.so/enkrateialog/44a8f633dda74aa0b26b89ad960015fa?v=9be485bc35f44c68a9399f880844a45d | (7) Reference Sources | |
https://chat.openai.com/?model=gpt-4-plugins | ChatGPT | |
... (remaining text) ...""" | |
urls = re.findall(r'(https?://\S+)', text) | |
print(urls) |
NewerOlder