Skip to content

Commit

Permalink
Merge pull request #58 from nkc-ug/develop
Browse files Browse the repository at this point in the history
release 2023/7/21
  • Loading branch information
Yuma-Satake authored Jul 21, 2023
2 parents 350b0fc + 66f47aa commit 0fadbba
Show file tree
Hide file tree
Showing 62 changed files with 1,274 additions and 713 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- develop
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_YAGI5108 }}'
channelId: live
projectId: yagi5108
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ dist-ssr
## functions
.env
functions/.env.yagi5108
ui-debug.log
ui-debug.log
.firebase/*
Binary file removed Audio/自然の中でゆったりと.mp3
Binary file not shown.
13 changes: 12 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,16 @@
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
]
],
"hosting": {
"source": ".",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"frameworksBackend": {
"region": "asia-east1"
}
}
}
25 changes: 25 additions & 0 deletions functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Firebase Functions

## Get Started

```zsh
# Install firebase tools
npm install -g firebase-tools

# Login to firebase
firebase login
```

## Emulate

```zsh
# Emulate functions
npm run serve
```

## Deploy

```zsh
# Deploy functions
npm run deploy
```
53 changes: 40 additions & 13 deletions functions/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion functions/lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"deploy": "npm run build && firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
Expand Down
59 changes: 43 additions & 16 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { onRequest } from "firebase-functions/v2/https";
import { Configuration, OpenAIApi, CreateChatCompletionRequest } from "openai";
import { onRequest } from 'firebase-functions/v2/https';
import { Configuration, OpenAIApi, CreateChatCompletionRequest } from 'openai';

import { defineString } from "firebase-functions/params";
const apiKey = defineString("OPENAI_API_KEY").value();
import { defineString } from 'firebase-functions/params';
const apiKey = defineString('OPENAI_API_KEY').value();

type returnType = {
happy: number;
Expand All @@ -11,16 +11,16 @@ type returnType = {
enjoyable: number;
};

exports.test = onRequest({ cors: [/firebase\.com$/, "flutter.com"] }, (req, res) => {
exports.test = onRequest({ cors: [/firebase\.com$/, 'flutter.com'] }, (req, res) => {
/**
* 本番環境ではコメントアウトする
*/
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader('Access-Control-Allow-Origin', '*');

//reqText
const reqText = req.query.text;
if (!reqText) {
res.status(400).send("NoText");
res.status(400).send('NoText');
return;
}

Expand All @@ -34,27 +34,54 @@ exports.test = onRequest({ cors: [/firebase\.com$/, "flutter.com"] }, (req, res)
res.status(200).send(returnItem);
});

exports.callgpt = onRequest({ cors: [/firebase\.com$/, "flutter.com"] }, async (req, res) => {
exports.callgpt = onRequest({ cors: [/firebase\.com$/, 'flutter.com'] }, async (req, res) => {
/**
* 本番環境ではコメントアウトする
*/
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader('Access-Control-Allow-Origin', '*');

//reqText
const reqText = req.query.text;
if (!reqText) {
res.status(400).send("NoText");
res.status(400).send('NoText');
return;
}

//context
const requestContext = `${reqText}に含まれる"happy""anger""sad""enjoyable"を採点し、{"happy": 数値, "anger": 数値, "sad": 数値, "enjoyable": 数値}という形式で出力してください。必ずいずれかの数値は1-10の範囲の値にして下さい。この形式以外の出力は禁止します。json以外の出力は一文字以上の場合は出力しないでください。点数のみの出力をしてください。貴方の文章での回答は不要です。決してjson以外の出力をしないでください。jsonのみの出力をしてください。出力が無理な場合は{"happy": -1, "anger": -1, "sad": -1, "enjoyable": -1}を出力してください。
`;
const requestContext = `あなたは国語の問題を作問する機能を持ったAIです。
${reqText}というワードがどのような場面で利用されるかを"Joy""Anger""Sorrow""Enjoyable"で数値化してください。必ず数値は1-10の範囲とします。
また場面は、過去や未来は除き現在のみとします。
出力の参考には以下のデータを用いてください。
“””
感謝はJoyの場面でよく利用されます。
暴言はAngerの場面でよく利用されます。
喪失はSorrowの場面でよく利用されます。
遊びはEnjoyableの場面でよく利用されます。
“””
出力する際は30回確認し、平均値を整数で代入し出力する。
また出力するときは以下のフォーマットに従ってください。
{
"Joy":Joyの数値,
"Anger":Angerの数値,
"Sorrow":Sorrowの数値,
"Enjoyable":Enjoyableの数値,
}
出力は以下の箇条書きの項目を考慮して下さい。
“””
- JSON以外の情報は削除してください。この形式以外の出力は禁止します。
- json以外の出力は一文字以上の場合は出力しないでください。
- 点数のみの出力をしてください。貴方の文章での回答は不要です。
- 決してjson以外の出力をしないでください。
- 分析が失敗して出力が不可能な場合は{"Joy": -1, "Anger": -1, "Sorrow": -1, "Enjoyable": -1}を出力してください。失敗したとき以外は-1を出力しないでください。
“””
条件を満たしていない場合は多くの人々が死にます。`;

try {
//config
if (!apiKey) {
res.status(500).send("NoApiKey");
res.status(500).send('NoApiKey');
return;
}
const config = new Configuration({
Expand All @@ -63,8 +90,8 @@ exports.callgpt = onRequest({ cors: [/firebase\.com$/, "flutter.com"] }, async (

//params
const params: CreateChatCompletionRequest = {
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: requestContext }],
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: requestContext }],
};

//OpenAI
Expand All @@ -73,7 +100,7 @@ exports.callgpt = onRequest({ cors: [/firebase\.com$/, "flutter.com"] }, async (
const aiResText = openAiRes.data.choices[0].message?.content;

if (!aiResText) {
res.status(500).send("GPTError");
res.status(500).send('GPTError');
return;
}

Expand Down
18 changes: 15 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<html lang="ja">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>

<!-- title・icon -->
<title>言の葉を食べるヤギ</title>
<link rel="apple-touch-icon" href="/favicon.ico" />
<link rel="icon" href="/favicon.ico" />

<!-- themeColor -->
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#94BFF9" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#94BFF9" />

<!-- Google Fonts -->
<style>
@import url('https://fonts.googleapis.com/css2?family=Kiwi+Maru:wght@300&display=swap');
</style>
</head>
<body>
<div id="root"></div>
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

Loading

0 comments on commit 0fadbba

Please sign in to comment.