Skip to content

Commit 9033b6d

Browse files
committed
feat: add openai-function-calling app
1 parent f4b076c commit 9033b6d

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

api/terraform/apigateway_endpoints.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,27 @@ module "default_lesson_plan_writer" {
732732
aws_lambda_function_openai_text = aws_lambda_function.lambda_openai_v2.function_name
733733
aws_iam_role_arn = aws_iam_role.apigateway.arn
734734
}
735+
736+
###############################################################################
737+
# 31. Openai function calling example
738+
#
739+
#
740+
###############################################################################
741+
module "openai_function_calling" {
742+
source = "./endpoint"
743+
path_part = "openai-function-calling"
744+
745+
# OpenAI application definition
746+
mapping_object_type = "chat.completion"
747+
mapping_model = "gpt-3.5-turbo"
748+
mapping_role_system_content = "You are a helpful assistant."
749+
mapping_max_tokens = 2048
750+
751+
# integrate this endpoint to the AWS Gateway API.
752+
aws_region = var.aws_region
753+
aws_api_gateway_rest_api_parent_id = aws_api_gateway_resource.examples.id
754+
aws_api_gateway_rest_api_id = aws_api_gateway_rest_api.openai.id
755+
aws_lambda_function_openai_text_invoke_arn = aws_lambda_function.lambda_openai_function.invoke_arn
756+
aws_lambda_function_openai_text = aws_lambda_function.lambda_openai_function.function_name
757+
aws_iam_role_arn = aws_iam_role.apigateway.arn
758+
}

api/terraform/python/openai_api/lambda_openai_function/lambda_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def handler(event, context):
9999
max_tokens=max_tokens,
100100
)
101101
response_message = openai_results.choices[0].message
102+
openai_results = openai_results.model_dump()
102103
tool_calls = response_message.tool_calls
103104
if tool_calls:
104105
# Step 3: call the function

client/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

client/src/App.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Emojibot from "./applications/Emojibot";
3434
import Emojibot4 from "./applications/Emojibot4";
3535
import English2French from "./applications/English2French";
3636
import FunctionCreator from "./applications/FunctionCreator";
37+
import FunctionCalling from "./applications/FunctionCalling";
3738
import GrammarGenius from "./applications/GrammarGenius";
3839
import InterviewQuestions from "./applications/InterviewQuestions";
3940
import KeyWords from "./applications/KeyWords";
@@ -133,6 +134,13 @@ const App = () => {
133134
>
134135
{SarcasticChat.sidebar_title}
135136
</MenuItem>
137+
<MenuItem
138+
onClick={() =>
139+
handleItemClick(APPLICATIONS.FunctionCalling)
140+
}
141+
>
142+
{FunctionCalling.sidebar_title}
143+
</MenuItem>
136144
<MenuItem
137145
onClick={() => handleItemClick(APPLICATIONS.Emojibot)}
138146
>
@@ -385,6 +393,9 @@ const App = () => {
385393
{selectedItem === APPLICATIONS.SarcasticChat && (
386394
<ChatApp {...SarcasticChat} />
387395
)}
396+
{selectedItem === APPLICATIONS.FunctionCalling && (
397+
<ChatApp {...FunctionCalling} />
398+
)}
388399
{selectedItem === APPLICATIONS.SinglePageWebapp && (
389400
<ChatApp {...SinglePageWebapp} />
390401
)}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// see https://platform.openai.com/docs/guides/function-calling
2+
import {
3+
BACKEND_API_URL,
4+
AWS_API_GATEWAY_KEY,
5+
OPENAI_EXAMPLES_URL,
6+
} from "../config";
7+
8+
const SLUG = "openai-function-calling";
9+
10+
const FunctionCalling = {
11+
sidebar_title: "OpenAI Function Calling",
12+
api_url: BACKEND_API_URL + SLUG,
13+
api_key: AWS_API_GATEWAY_KEY,
14+
app_name: "OpenAI Function Calling",
15+
assistant_name: "Lawrence McDaniel",
16+
avatar_url: "/applications/SarcasticChat/Marv.svg",
17+
background_image_url: "/applications/SarcasticChat/SarcasticChat-bg.png",
18+
welcome_message: `Hello, I'm Lawrence McDaniel, an adaptive chatbot. I use natural language processing to adapt myself to your prompts. I also leverage OpenAI API 'Function Calling.' If you ask about Lawrence McDaniel then I'll turn into one heck of a shameless promotor on my own behalf. Otherwise, I'll behave like a regular chatbot.`,
19+
example_prompts: [
20+
'"In what year was William Shakespear 25 years old?"',
21+
'"Is Lawrence McDaniel a web developer?"',
22+
'"what is a good roast chicken recipe?"',
23+
'"Is Lawrence McDaniel a good citizen?"',
24+
'"Are Lawrence McDaniel and Chuck Norris friends?"',
25+
],
26+
placeholder_text: `ask me anything about .... me!`,
27+
info_url: OPENAI_EXAMPLES_URL + SLUG,
28+
file_attach_button: false,
29+
uses_openai: true,
30+
uses_openai_api: false,
31+
uses_langchain: true,
32+
uses_memory: true,
33+
};
34+
35+
export default FunctionCalling;

0 commit comments

Comments
 (0)