Skip to content

Commit c857082

Browse files
committed
fix: refactor request templates for openai api v1 object_type
1 parent 623cee8 commit c857082

File tree

5 files changed

+44
-39
lines changed

5 files changed

+44
-39
lines changed

CHANGELOG.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# [0.8.0](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.7.2...v0.8.0) (2023-12-30)
22

3-
43
### Bug Fixes
54

6-
* add an error boundary ([4b7d021](https://github.com/FullStackWithLawrence/aws-openai/commit/4b7d02113d4c06f57aef067155f458ca3857d60c))
7-
* convert return value to json if necessary. also verify dict keys before attempting to access anything ([376e14d](https://github.com/FullStackWithLawrence/aws-openai/commit/376e14defa77cef7d1bbc55ce98176f7b7be41bc))
8-
* ensure that error messages are strings ([7c01083](https://github.com/FullStackWithLawrence/aws-openai/commit/7c01083e780391e637f551f4f49a76670ff771a7))
9-
* scaffold an Error Boundary for the chatapp ([3fcbdb6](https://github.com/FullStackWithLawrence/aws-openai/commit/3fcbdb6c55d6748a1789d51e051cc8fab9b9456a))
10-
5+
- add an error boundary ([4b7d021](https://github.com/FullStackWithLawrence/aws-openai/commit/4b7d02113d4c06f57aef067155f458ca3857d60c))
6+
- convert return value to json if necessary. also verify dict keys before attempting to access anything ([376e14d](https://github.com/FullStackWithLawrence/aws-openai/commit/376e14defa77cef7d1bbc55ce98176f7b7be41bc))
7+
- ensure that error messages are strings ([7c01083](https://github.com/FullStackWithLawrence/aws-openai/commit/7c01083e780391e637f551f4f49a76670ff771a7))
8+
- scaffold an Error Boundary for the chatapp ([3fcbdb6](https://github.com/FullStackWithLawrence/aws-openai/commit/3fcbdb6c55d6748a1789d51e051cc8fab9b9456a))
119

1210
### Features
1311

14-
* add v2 Settings class ([da8943d](https://github.com/FullStackWithLawrence/aws-openai/commit/da8943d55a568f1196e9389d8f3aaee1b15408bb))
15-
* add v2 Settings class ([240433b](https://github.com/FullStackWithLawrence/aws-openai/commit/240433bd2a50c32da4bdf484420bc86b9db545d6))
12+
- add v2 Settings class ([da8943d](https://github.com/FullStackWithLawrence/aws-openai/commit/da8943d55a568f1196e9389d8f3aaee1b15408bb))
13+
- add v2 Settings class ([240433b](https://github.com/FullStackWithLawrence/aws-openai/commit/240433bd2a50c32da4bdf484420bc86b9db545d6))
1614

1715
## [0.7.2](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.7.1...v0.7.2) (2023-12-19)
1816

api/terraform/apigateway_endpoints.tf

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module "default_grammar" {
2121
path_part = "default-grammar"
2222

2323
# OpenAI application definition
24-
mapping_end_point = "ChatCompletion"
24+
mapping_object_type = "chat.completion"
2525
mapping_model = "gpt-3.5-turbo"
2626
mapping_role_system_content = "You will be provided with statements, and your task is to convert them to standard English."
2727

@@ -43,7 +43,7 @@ module "default_summarize" {
4343
path_part = "default-summarize"
4444

4545
# OpenAI application definition
46-
mapping_end_point = "ChatCompletion"
46+
mapping_object_type = "chat.completion"
4747
mapping_model = "gpt-3.5-turbo"
4848
mapping_role_system_content = "Summarize content you are provided with for a second-grade student."
4949
mapping_temperature = 0
@@ -67,7 +67,7 @@ module "default_parse_data" {
6767
path_part = "default-parse-data"
6868

6969
# OpenAI application definition
70-
mapping_end_point = "ChatCompletion"
70+
mapping_object_type = "chat.completion"
7171
mapping_model = "gpt-3.5-turbo"
7272
mapping_role_system_content = "You will be provided with unstructured data, and your task is to parse it into CSV format."
7373
mapping_temperature = 0
@@ -92,7 +92,7 @@ module "default_emoji_translation" {
9292
path_part = "default-emoji-translation"
9393

9494
# OpenAI application definition
95-
mapping_end_point = "ChatCompletion"
95+
mapping_object_type = "chat.completion"
9696
mapping_model = "gpt-3.5-turbo"
9797
mapping_role_system_content = "You will be provided with text, and your task is to translate it into emojis. Do not use any regular text. Do your best with emojis only."
9898
mapping_temperature = 0.8
@@ -116,7 +116,7 @@ module "default_time_complexity" {
116116
path_part = "default-time-complexity"
117117

118118
# OpenAI application definition
119-
mapping_end_point = "ChatCompletion"
119+
mapping_object_type = "chat.completion"
120120
mapping_model = "gpt-3.5-turbo"
121121
mapping_role_system_content = "You will be provided with Python code, and your task is to calculate its time complexity."
122122
mapping_temperature = 0
@@ -140,7 +140,7 @@ module "default_explain_code" {
140140
path_part = "default-explain-code"
141141

142142
# OpenAI application definition
143-
mapping_end_point = "ChatCompletion"
143+
mapping_object_type = "chat.completion"
144144
mapping_model = "gpt-4"
145145
mapping_role_system_content = "You will be provided with a piece of code, and your task is to explain it in a concise way."
146146
mapping_temperature = 0
@@ -164,7 +164,7 @@ module "default_keywords" {
164164
path_part = "default-keywords"
165165

166166
# OpenAI application definition
167-
mapping_end_point = "ChatCompletion"
167+
mapping_object_type = "chat.completion"
168168
mapping_model = "gpt-3.5-turbo"
169169
mapping_role_system_content = "You will be provided with a block of text, and your task is to extract a list of keywords from it."
170170
mapping_temperature = 0.5
@@ -188,7 +188,7 @@ module "default_product_name_gen" {
188188
path_part = "default-product-name-gen"
189189

190190
# OpenAI application definition
191-
mapping_end_point = "ChatCompletion"
191+
mapping_object_type = "chat.completion"
192192
mapping_model = "gpt-3.5-turbo"
193193
mapping_role_system_content = "You will be provided with a product description and seed words, and your task is to generate product names."
194194
mapping_temperature = 0.8
@@ -212,7 +212,7 @@ module "default_fix_python_bugs" {
212212
path_part = "default-fix-python-bugs"
213213

214214
# OpenAI application definition
215-
mapping_end_point = "ChatCompletion"
215+
mapping_object_type = "chat.completion"
216216
mapping_model = "gpt-4"
217217
mapping_role_system_content = "You will be provided with a piece of Python code, and your task is to find and fix bugs in it."
218218
mapping_temperature = 0
@@ -236,7 +236,7 @@ module "default_spreadsheet_gen" {
236236
path_part = "default-spreadsheet-gen"
237237

238238
# OpenAI application definition
239-
mapping_end_point = "ChatCompletion"
239+
mapping_object_type = "chat.completion"
240240
mapping_model = "gpt-3.5-turbo"
241241
mapping_role_system_content = "Your task is to create spreadsheets from various kinds of data"
242242
mapping_temperature = 0.5
@@ -260,7 +260,7 @@ module "default_tweet_classifier" {
260260
path_part = "default-tweet-classifier"
261261

262262
# OpenAI application definition
263-
mapping_end_point = "ChatCompletion"
263+
mapping_object_type = "chat.completion"
264264
mapping_model = "gpt-3.5-turbo"
265265
mapping_role_system_content = "You will be provided with a tweet, and your task is to classify its sentiment as positive, neutral, or negative."
266266
mapping_temperature = 0
@@ -284,7 +284,7 @@ module "default_airport_codes" {
284284
path_part = "default-airport-codes"
285285

286286
# OpenAI application definition
287-
mapping_end_point = "ChatCompletion"
287+
mapping_object_type = "chat.completion"
288288
mapping_model = "gpt-3.5-turbo"
289289
mapping_role_system_content = "You will be provided with a text, and your task is to extract the airport codes from it."
290290
mapping_temperature = 0
@@ -308,7 +308,7 @@ module "default_mood_color" {
308308
path_part = "default-mood-color"
309309

310310
# OpenAI application definition
311-
mapping_end_point = "ChatCompletion"
311+
mapping_object_type = "chat.completion"
312312
mapping_model = "gpt-3.5-turbo"
313313
mapping_role_system_content = "You will be provided with a description of a mood, and your task is to generate the CSS code for a color that matches it. Write your output in json with a single key called 'css_code'."
314314
mapping_temperature = 0
@@ -332,7 +332,7 @@ module "default_vr_fitness" {
332332
path_part = "default-vr-fitness"
333333

334334
# OpenAI application definition
335-
mapping_end_point = "ChatCompletion"
335+
mapping_object_type = "chat.completion"
336336
mapping_model = "gpt-3.5-turbo"
337337
mapping_role_system_content = "You are a helpful assistant. Your task is to generate ideas for fitness promoting virtual reality games"
338338
mapping_temperature = 0.6
@@ -358,7 +358,7 @@ module "default_marv_sarcastic_chat" {
358358
path_part = "default-marv-sarcastic-chat"
359359

360360
# OpenAI application definition
361-
mapping_end_point = "ChatCompletion"
361+
mapping_object_type = "chat.completion"
362362
mapping_model = "gpt-3.5-turbo"
363363
mapping_role_system_content = "You are Marv, a chatbot that reluctantly answers questions with sarcastic responses."
364364
mapping_temperature = 0.5
@@ -382,7 +382,7 @@ module "default_turn_by_turn_directions" {
382382
path_part = "default-turn-by-turn-directions"
383383

384384
# OpenAI application definition
385-
mapping_end_point = "ChatCompletion"
385+
mapping_object_type = "chat.completion"
386386
mapping_model = "gpt-3.5-turbo"
387387
mapping_role_system_content = "You will be provided with a text, and your task is to create a numbered list of turn-by-turn directions from it."
388388
mapping_temperature = 0.3
@@ -406,7 +406,7 @@ module "default_interview_questions" {
406406
path_part = "default-interview-questions"
407407

408408
# OpenAI application definition
409-
mapping_end_point = "ChatCompletion"
409+
mapping_object_type = "chat.completion"
410410
mapping_model = "gpt-3.5-turbo"
411411
mapping_role_system_content = "Your are a helpful assistant. Your task is to create job interview questions."
412412
mapping_temperature = 0.5
@@ -430,7 +430,7 @@ module "default_function_from_spec" {
430430
path_part = "default-function-from-spec"
431431

432432
# OpenAI application definition
433-
mapping_end_point = "ChatCompletion"
433+
mapping_object_type = "chat.completion"
434434
mapping_model = "gpt-4"
435435
mapping_role_system_content = "You are an expert Python programmer. Your task is to create a Python function from a specification."
436436
mapping_temperature = 0
@@ -454,7 +454,7 @@ module "default_code_improvement" {
454454
path_part = "default-code-improvement"
455455

456456
# OpenAI application definition
457-
mapping_end_point = "ChatCompletion"
457+
mapping_object_type = "chat.completion"
458458
mapping_model = "gpt-4"
459459
mapping_role_system_content = "You will be provided with a piece of Python code, and your task is to provide ideas for efficiency improvements."
460460
mapping_temperature = 0
@@ -478,7 +478,7 @@ module "default_single_page_website" {
478478
path_part = "default-single-page-website"
479479

480480
# OpenAI application definition
481-
mapping_end_point = "ChatCompletion"
481+
mapping_object_type = "chat.completion"
482482
mapping_model = "gpt-4"
483483
mapping_role_system_content = "You are an expert front-end developer. Your task is to create a single page website based on a spec."
484484
mapping_temperature = 0
@@ -502,7 +502,7 @@ module "default_rap_battle" {
502502
path_part = "default-rap-battle"
503503

504504
# OpenAI application definition
505-
mapping_end_point = "ChatCompletion"
505+
mapping_object_type = "chat.completion"
506506
mapping_model = "gpt-4"
507507
mapping_role_system_content = "You are an accomplished rapper. Your task is to generate a rap battle between two characters."
508508
mapping_temperature = 0.8
@@ -526,7 +526,7 @@ module "default_memo_writer" {
526526
path_part = "default-memo-writer"
527527

528528
# OpenAI application definition
529-
mapping_end_point = "ChatCompletion"
529+
mapping_object_type = "chat.completion"
530530
mapping_model = "gpt-4"
531531
mapping_role_system_content = "You are a helpful assistant. Your task is to generate a company memo based on provided points."
532532
mapping_temperature = 0
@@ -550,7 +550,7 @@ module "default_emoji_chatbot" {
550550
path_part = "default-emoji-chatbot"
551551

552552
# OpenAI application definition
553-
mapping_end_point = "ChatCompletion"
553+
mapping_object_type = "chat.completion"
554554
mapping_model = "gpt-4"
555555
mapping_role_system_content = "You will be provided with a message, and your task is to respond using emojis only."
556556
mapping_temperature = 0.8
@@ -574,7 +574,7 @@ module "default_translation" {
574574
path_part = "default-translation"
575575

576576
# OpenAI application definition
577-
mapping_end_point = "ChatCompletion"
577+
mapping_object_type = "chat.completion"
578578
mapping_model = "gpt-4"
579579
mapping_role_system_content = "You will be provided with a sentence in English, and your task is to translate it into French."
580580
mapping_temperature = 0
@@ -598,7 +598,7 @@ module "default_socratic_tutor" {
598598
path_part = "default-socratic-tutor"
599599

600600
# OpenAI application definition
601-
mapping_end_point = "ChatCompletion"
601+
mapping_object_type = "chat.completion"
602602
mapping_model = "gpt-4"
603603
mapping_role_system_content = "You are a Socratic tutor. Use the following principles in responding to students: a.) Ask thought-provoking, open-ended questions that challenge preconceptions of students and encourage them to engage in deeper reflection and critical thinking. b.) Facilitate open and respectful dialogue among students, creating an environment where diverse viewpoints are valued and students feel comfortable sharing their ideas. c.) Actively listen to responses of students, paying careful attention to their underlying thought processes and making a genuine effort to understand their perspectives. d.) Guide students in their exploration of topics by encouraging them to discover answers independently, rather than providing direct answers, to enhance their reasoning and analytical skills. e.) Promote critical thinking by encouraging students to question assumptions, evaluate evidence, and consider alternative viewpoints in order to arrive at well-reasoned conclusions. f.) Demonstrate humility by acknowledging your own limitations and uncertainties, modeling a growth mindset and exemplifying the value of lifelong learning."
604604
mapping_temperature = 0.8
@@ -622,7 +622,7 @@ module "default_sql_translate" {
622622
path_part = "default-sql-translate"
623623

624624
# OpenAI application definition
625-
mapping_end_point = "ChatCompletion"
625+
mapping_object_type = "chat.completion"
626626
mapping_model = "gpt-4"
627627
mapping_role_system_content = "Given the following SQL tables, your job is to write queries given a user’s request.\n\nCREATE TABLE Orders (\n OrderID int,\n CustomerID int,\n OrderDate datetime,\n OrderTime varchar(8),\n PRIMARY KEY (OrderID)\n);\n\nCREATE TABLE OrderDetails (\n OrderDetailID int,\n OrderID int,\n ProductID int,\n Quantity int,\n PRIMARY KEY (OrderDetailID)\n);\n\nCREATE TABLE Products (\n ProductID int,\n ProductName varchar(50),\n Category varchar(50),\n UnitPrice decimal(10, 2),\n Stock int,\n PRIMARY KEY (ProductID)\n);\n\nCREATE TABLE Customers (\n CustomerID int,\n FirstName varchar(50),\n LastName varchar(50),\n Email varchar(100),\n Phone varchar(20),\n PRIMARY KEY (CustomerID)\n);\n"
628628
mapping_temperature = 0
@@ -646,7 +646,7 @@ module "default_meeting_notes_summarizer" {
646646
path_part = "default-meeting-notes-summarizer"
647647

648648
# OpenAI application definition
649-
mapping_end_point = "ChatCompletion"
649+
mapping_object_type = "chat.completion"
650650
mapping_model = "gpt-4"
651651
mapping_role_system_content = "You will be provided with meeting notes, and your task is to summarize the meeting as follows:\n\n-Overall summary of discussion\n-Action items (what needs to be done and who is doing it)\n-If applicable, a list of topics that need to be discussed more fully in the next meeting.\n"
652652
mapping_temperature = 0
@@ -670,7 +670,7 @@ module "default_review_classifier" {
670670
path_part = "default-review-classifier"
671671

672672
# OpenAI application definition
673-
mapping_end_point = "ChatCompletion"
673+
mapping_object_type = "chat.completion"
674674
mapping_model = "gpt-4"
675675
mapping_role_system_content = "You will be presented with user reviews and your job is to provide a set of tags from the following list. Provide your answer in bullet point form. Choose ONLY from the list of tags provided here (choose either the positive or the negative tag but NOT both):\n\n- Provides good value for the price OR Costs too much\n- Works better than expected OR Did not work as well as expected\n- Includes essential features OR Lacks essential features\n- Easy to use OR Difficult to use\n- High quality and durability OR Poor quality and durability\n- Easy and affordable to maintain or repair OR Difficult or costly to maintain or repair\n- Easy to transport OR Difficult to transport\n- Easy to store OR Difficult to store\n- Compatible with other devices or systems OR Not compatible with other devices or systems\n- Safe and user-friendly OR Unsafe or hazardous to use\n- Excellent customer support OR Poor customer support\n- Generous and comprehensive warranty OR Limited or insufficient warranty\n"
676676
mapping_temperature = 0
@@ -694,7 +694,7 @@ module "default_pro_con_discusser" {
694694
path_part = "default-pro-con-discusser"
695695

696696
# OpenAI application definition
697-
mapping_end_point = "ChatCompletion"
697+
mapping_object_type = "chat.completion"
698698
mapping_model = "gpt-4"
699699
mapping_role_system_content = "You are a helpful assistant. Your task is to analyze the pros and cons of a given topic."
700700
mapping_temperature = 0.8
@@ -718,7 +718,7 @@ module "default_lesson_plan_writer" {
718718
path_part = "default-lesson-plan-writer"
719719

720720
# OpenAI application definition
721-
mapping_end_point = "ChatCompletion"
721+
mapping_object_type = "chat.completion"
722722
mapping_model = "gpt-4"
723723
mapping_role_system_content = "You are an experienced teacher. Your task is to generate a lesson plan for a specific topic."
724724
mapping_temperature = 0.8

api/terraform/endpoint/api_gateway_endpoint.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ locals {
88
openai_integration_template = templatefile(
99
"${path.module}/mapping-templates/openai-integration.tpl",
1010
{
11+
mapping_object_type = var.mapping_object_type
1112
mapping_model = var.mapping_model
1213
mapping_role_system_content = var.mapping_role_system_content
1314
mapping_end_point = var.mapping_end_point

api/terraform/endpoint/mapping-templates/openai-integration.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
22
{
3-
"object_type": "chat.completion",
3+
"object_type": "${mapping_object_type}",
44
"model": "${mapping_model}",
55
"end_point": "${mapping_end_point}",
66
"temperature": ${mapping_temperature},

api/terraform/endpoint/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ variable "aws_iam_role_arn" {
3838
###############################################################################
3939
# OpenAI mapping template
4040
###############################################################################
41+
variable "mapping_object_type" {
42+
description = "OpenAI Python API class to invoke."
43+
type = string
44+
default = "chat.completion"
45+
46+
}
4147
variable "mapping_model" {
4248
# see https://platform.openai.com/docs/models/overview
4349
description = "which OpenAI model to use"

0 commit comments

Comments
 (0)