Skip to content

Commit 088db2c

Browse files
authored
Merge pull request #278 from FullStackWithLawrence/next
Release Pydantic refactor
2 parents a4a0a38 + dc59a36 commit 088db2c

File tree

7 files changed

+81
-12
lines changed

7 files changed

+81
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
## [0.10.3](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.10.2...v0.10.3) (2024-01-27)
22

3-
43
### Bug Fixes
54

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22
# DO NOT EDIT.
33
# Managed via automated CI/CD in .github/workflows/semanticVersionBump.yml.
4-
__version__ = "0.10.3"
4+
__version__ = "0.10.4"
Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,58 @@
11
# OpenAI Function Calling examples
22

3+
## Sample usage
4+
5+
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.
6+
7+
![Terraform init](https://raw.githubusercontent.com/FullStackWithLawrence/aws-openai/main/doc/img/openai-function-calling-example.png "Function Calling example")
8+
9+
![Terraform init](https://raw.githubusercontent.com/FullStackWithLawrence/aws-openai/main/doc/img/openai-function-calling-cloudwatch.png "Function Calling Cloudwatch")
10+
311
## function_weather.py
412

513
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.
614

715
## function_refers_to.py
816

9-
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.
17+
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.
18+
19+
### Example custom configurations
20+
21+
The following two sample custom configurations are included in this project:
22+
23+
1. [Everlasting Gobstopper](./config/everlasting-gobstopper.yaml): An example of a consumer product, complete with pricing information and coupon codes.
24+
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.
25+
26+
### Custom Configuration Yaml format
27+
28+
```yaml
29+
meta_data:
30+
config_path: aws_openai/lambda_openai_function/custom_configs/example-configuration.yaml
31+
name: ExampleConfiguration
32+
description: an example custom configuration.
33+
version: 0.1.0
34+
author: Lawrence McDaniel
35+
prompting:
36+
search_terms:
37+
strings:
38+
- example function calling configuration
39+
pairs:
40+
- - Example
41+
- configuration
42+
- - example
43+
- function calling
44+
system_prompt: >
45+
Your job is to provide helpful technical information about the OpenAI API Function Calling feature. You should include the following information in your response:
46+
"Congratulations!!! OpenAI API Function Calling chose to call this function. Here is the additional information that you requested:"
47+
function_calling:
48+
function_description: an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
49+
additional_information:
50+
about: >
51+
This is some sample text that will be returned ChatGPT if it opts to invoke the get_additional_info() function.
52+
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.
53+
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).
54+
links:
55+
- documentation: https://platform.openai.com/docs/guides/function-calling
56+
- website: https://openai.com/
57+
- wikipedia: https://en.wikipedia.org/wiki/OpenAI
58+
```

api/terraform/python/openai_api/lambda_openai_function/config/example-configuration.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
---
2+
# ------------------------------------------------------------
3+
# 1. Required field: meta_data.
4+
# Each of these fields is required.
5+
# ------------------------------------------------------------
26
meta_data:
37
config_path: aws_openai/lambda_openai_function/custom_configs/example-configuration.yaml
48
name: ExampleConfiguration
5-
description: an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
9+
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.
610
version: 0.1.0
711
author: Lawrence McDaniel
12+
13+
# ------------------------------------------------------------
14+
# 2. Required field: prompting
15+
# 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.
16+
# This module additionally makes limited use of natural language processing to attempt to account for variations in the user prompt and common misspellings.
17+
# ------------------------------------------------------------
818
prompting:
919
#------------------------------------------------------------
1020
# search terms that will trigger the chatbot to use this customized configuration.
@@ -15,14 +25,25 @@ prompting:
1525
pairs:
1626
- - Example
1727
- configuration
28+
- - example
29+
- function calling
30+
#------------------------------------------------------------
31+
# if this module is able to locate any of the search terms in the user prompt
32+
# then this system prompt text will will be added.
33+
#------------------------------------------------------------
1834
system_prompt: >
1935
Your job is to provide helpful technical information about the OpenAI API Function Calling feature. You should include the following information in your response:
2036
"Congratulations!!! OpenAI API Function Calling chose to call this function. Here is the additional information that you requested:"
37+
38+
# ------------------------------------------------------------
39+
# 3. Required field: function_calling
40+
# 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
41+
# 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
42+
# this dictionary are free form and can include any yaml-compliant data you want returned to OpenAPI API Function Calling.
43+
# OpenAI API Function Calling will return this dictionary to ChatGPT as a JSON object, which it will incorporate into the response at its
44+
# own discretion.
45+
# ------------------------------------------------------------
2146
function_calling:
22-
#------------------------------------------------------------
23-
# if this module is able to locate any of the search terms in the user prompt
24-
# then this is the system prompt will be used to generate the response, and the function_description that will be provided to OpenAI API.
25-
#------------------------------------------------------------
2647
function_description: an example custom configuration to integrate with OpenAI API Function Calling additional information function, in this module.
2748
#------------------------------------------------------------
2849
# if a.) this module is able to locate any of the search terms in the user prompt

client/src/applications/FunctionCalling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const FunctionCalling = {
2222
'"tell me about your creator"',
2323
'"what is a good roast chicken recipe?"',
2424
'"send me some information about lawrence"',
25-
'"what did lawrence study in college?"',
26-
'"tell me about projects of lawrence"',
25+
'"where can I get an everlasting gobstopper, and, what is it exactly?"',
26+
'"send me a link for a discount code for an everlasting gobstopper"',
2727
'"Are Lawrence McDaniel and Chuck Norris friends?"',
2828
],
2929
placeholder_text: `ask me anything`,
852 KB
Loading
995 KB
Loading

0 commit comments

Comments
 (0)