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
""" | |
# OpenAI Chat Completions Serialization Example | |
## Description | |
This code snippet demonstrates how to serialize the response from the OpenAI Chat Completions API into a JSON format which is useful for sending using REST. | |
It includes a helper function, `serialize_completion`, that takes the completion response object and converts it into a JSON-compatible dictionary. | |
## Usage | |
To use this code, you will need to have a .env file in the same directory as this script with your openai key: | |
OPENAI_API_KEY = "sk-your_key_here" |
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
""" | |
Title: Directory Loader using Unstructured API with Error Handling and LangChain Document Output | |
Description: A class for loading documents from a directory using the LangChain format. | |
It supports recursive loading and conversion of documents to the LangChain Document class using the UnstructuredClient API. | |
The class includes built-in error handling and outputs documents in the same style as the LangChain Document class. | |
To use, get a free unstructured API key here: https://unstructured.io/api-key | |
Author: @CivilEngineerUK |
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 pydantic import BaseModel, Field | |
from typing import Optional, List | |
from instructor import OpenAISchema | |
import json | |
class Variable(BaseModel): | |
name: str = Field(..., description="Name of the variable in markdown math") | |
description: str = Field(..., description="Description of the variable") | |
unit: Optional[str] = Field(None, description="Unit of the variable") |
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
""" | |
Title: Asynchronous OpenAI API Wrapper with Error Handling | |
Description: A Python script to interact with the OpenAI API asynchronously, with built-in error handling and retry logic. | |
This script is designed to handle multiple prompts with the ability to define custom functions for more complex queries. | |
Created from guidance at: https://platform.openai.com/docs/guides/gpt/function-calling | |
Updated: rev 1 - 16/11/2023 for new end point and gpt-4-1106-preview [openai==1.2.4] | |
- includes structural engineering beam formula schema and use of Pydantic and instructor |
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
#' R_interact_Excel | |
#' | |
#' Allows a spreadsheet to be modified programatically and the | |
#' output from any number of dependent cells returned as a \code{tibble}. | |
#' Uses the \code{RDCOMClient}, \code{dplyr} and \code{stringr} packages | |
#' | |
#' @param file_location file location of the spreadsheet to modify. The | |
#' spreadsheet should be \code{.xls} format | |
#' @param input_values a vector of values corresponding to the cells to be modified | |
#' @param input_cells a character vector of the input cells |