Skip to content

Commit

Permalink
Merge pull request #278 from FullStackWithLawrence/next
Browse files Browse the repository at this point in the history
Release Pydantic refactor
  • Loading branch information
lpm0073 authored Jan 27, 2024
2 parents a4a0a38 + dc59a36 commit 088db2c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 12 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
## [0.10.3](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.10.2...v0.10.3) (2024-01-27)


### Bug Fixes

* force a new release ([7c88275](https://github.com/FullStackWithLawrence/aws-openai/commit/7c88275ef2041744f6fbf46e28c73ef803b5e1e5))
* force a new release ([bf6fa8f](https://github.com/FullStackWithLawrence/aws-openai/commit/bf6fa8f5c72541706023cde47bb378a65e126087))
- force a new release ([7c88275](https://github.com/FullStackWithLawrence/aws-openai/commit/7c88275ef2041744f6fbf46e28c73ef803b5e1e5))
- force a new release ([bf6fa8f](https://github.com/FullStackWithLawrence/aws-openai/commit/bf6fa8f5c72541706023cde47bb378a65e126087))

## [0.10.2](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.10.1...v0.10.2) (2024-01-23)

Expand Down
2 changes: 1 addition & 1 deletion api/terraform/python/openai_api/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# DO NOT EDIT.
# Managed via automated CI/CD in .github/workflows/semanticVersionBump.yml.
__version__ = "0.10.3"
__version__ = "0.10.4"
51 changes: 50 additions & 1 deletion api/terraform/python/openai_api/lambda_openai_function/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
# OpenAI Function Calling examples

## Sample usage

The following screenshots demonstrate the two Function Calling Python functions that are included in this project, for real-time weather data, and to include additional information in ChatGPT responses based on user prompt search terms and a custom JSON dict that is returned to ChatGPT via a Python API call.

![Terraform init](https://raw.githubusercontent.com/FullStackWithLawrence/aws-openai/main/doc/img/openai-function-calling-example.png "Function Calling example")

![Terraform init](https://raw.githubusercontent.com/FullStackWithLawrence/aws-openai/main/doc/img/openai-function-calling-cloudwatch.png "Function Calling Cloudwatch")

## function_weather.py

Fully implements the "[get_current_weather()](https://platform.openai.com/docs/guides/function-calling)" from The official OpenAI API documentation. OpenAI's documentation provides scaffolding for this feature, but falls short of actually providing code that retrieves location-based current weather forecasts.

## function_refers_to.py

This module demonstrates an alternative implementation of prompt behavior modification involving both Function Calling, plus, dynamic modifications to the system prompt. This example relies on [lambda_config.yaml](./lambda_config.yaml) for personalization data.
This module demonstrates an alternative implementation of prompt behavior modification involving both Function Calling, plus, dynamic modifications to the system prompt. The module passes a customized configuration object to `get_additional_info()` based on a configurable set of search terms that it looks for in the user prompt. The function works with multiple customized configurations. That is, it maintains a list of custom configurations, and user prompts including search terms associated with multiple custom configurations will result in prompt configuration multiple "Function Calling" apis. The custom configurations are persisted both inside this repository in the [config](./config/) folder as well as via a remote AWS S3 bucket that Terraform creates and configures for you automatically. Custom configurations are data-driven via a standardized yaml format. Use [example-configuration.yaml](./config/example-configuration.yaml) as a template to create your own custom configurations. Storing these in the AWS S3 bucket is preferable to keeping these inside your repo.

### Example custom configurations

The following two sample custom configurations are included in this project:

1. [Everlasting Gobstopper](./config/everlasting-gobstopper.yaml): An example of a consumer product, complete with pricing information and coupon codes.
2. [Lawrence McDaniel](./config/lawrence-mcdaniel.yaml): Similar in functionality to a personal web site, this configuration demonstrates how you can get ChatGPT to showcase your professional profile, including your job and project history, your project portfolio, skill set and context-sensitive contact information.

### Custom Configuration Yaml format

```yaml
meta_data:
config_path: aws_openai/lambda_openai_function/custom_configs/example-configuration.yaml
name: ExampleConfiguration
description: an example custom configuration.
version: 0.1.0
author: Lawrence McDaniel
prompting:
search_terms:
strings:
- example function calling configuration
pairs:
- - Example
- configuration
- - example
- function calling
system_prompt: >
Your job is to provide helpful technical information about the OpenAI API Function Calling feature. You should include the following information in your response:
"Congratulations!!! OpenAI API Function Calling chose to call this function. Here is the additional information that you requested:"
function_calling:
function_description: an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
additional_information:
about: >
This is some sample text that will be returned ChatGPT if it opts to invoke the get_additional_info() function.
In an API call, you can describe functions and have the model intelligently choose to output a JSON object containing arguments to call one or many functions. The Chat Completions API does not call the function; instead, the model generates JSON that you can use to call the function in your code.
The latest models (gpt-3.5-turbo-1106 and gpt-4-1106-preview) have been trained to both detect when a function should to be called (depending on the input) and to respond with JSON that adheres to the function signature more closely than previous models. With this capability also comes potential risks. We strongly recommend building in user confirmation flows before taking actions that impact the world on behalf of users (sending an email, posting something online, making a purchase, etc).
links:
- documentation: https://platform.openai.com/docs/guides/function-calling
- website: https://openai.com/
- wikipedia: https://en.wikipedia.org/wiki/OpenAI
```
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
---
# ------------------------------------------------------------
# 1. Required field: meta_data.
# Each of these fields is required.
# ------------------------------------------------------------
meta_data:
config_path: aws_openai/lambda_openai_function/custom_configs/example-configuration.yaml
name: ExampleConfiguration
description: an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
description: A 'hello world' style custom configuration. This is an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
version: 0.1.0
author: Lawrence McDaniel

# ------------------------------------------------------------
# 2. Required field: prompting
# These fields are used to modify the behavior of the AI. If the user prompt contains any of the search terms, then the system prompt will be used to generate the response.
# This module additionally makes limited use of natural language processing to attempt to account for variations in the user prompt and common misspellings.
# ------------------------------------------------------------
prompting:
#------------------------------------------------------------
# search terms that will trigger the chatbot to use this customized configuration.
Expand All @@ -15,14 +25,25 @@ prompting:
pairs:
- - Example
- configuration
- - example
- function calling
#------------------------------------------------------------
# if this module is able to locate any of the search terms in the user prompt
# then this system prompt text will will be added.
#------------------------------------------------------------
system_prompt: >
Your job is to provide helpful technical information about the OpenAI API Function Calling feature. You should include the following information in your response:
"Congratulations!!! OpenAI API Function Calling chose to call this function. Here is the additional information that you requested:"
# ------------------------------------------------------------
# 3. Required field: function_calling
# These fields are used to modify the behavior of the AI. If the user prompt contains any of the search terms, then an OpenAI Function Calling API for
# get_additional_info() will be added to the user prompt, and the following dictionary will be returned by the function. Note that the contents of
# this dictionary are free form and can include any yaml-compliant data you want returned to OpenAPI API Function Calling.
# OpenAI API Function Calling will return this dictionary to ChatGPT as a JSON object, which it will incorporate into the response at its
# own discretion.
# ------------------------------------------------------------
function_calling:
#------------------------------------------------------------
# if this module is able to locate any of the search terms in the user prompt
# then this is the system prompt will be used to generate the response, and the function_description that will be provided to OpenAI API.
#------------------------------------------------------------
function_description: an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
#------------------------------------------------------------
# if a.) this module is able to locate any of the search terms in the user prompt
Expand Down
4 changes: 2 additions & 2 deletions client/src/applications/FunctionCalling.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const FunctionCalling = {
'"tell me about your creator"',
'"what is a good roast chicken recipe?"',
'"send me some information about lawrence"',
'"what did lawrence study in college?"',
'"tell me about projects of lawrence"',
'"where can I get an everlasting gobstopper, and, what is it exactly?"',
'"send me a link for a discount code for an everlasting gobstopper"',
'"Are Lawrence McDaniel and Chuck Norris friends?"',
],
placeholder_text: `ask me anything`,
Expand Down
Binary file added doc/img/openai-function-calling-cloudwatch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/openai-function-calling-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 088db2c

Please sign in to comment.