-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add chat function #118
base: dev
Are you sure you want to change the base?
add chat function #118
Conversation
chat_function/data以下のファイルをgit, githubの管理下に置くかどうかがちょい迷ってます。 |
文言をちょっと修正したりするたびにPRをだす必要があるのはやだなあと思ってますが、そんなに変更するもんでもないならこれでもいいかもです |
それ以外はLGTMです!! |
了解です。PR作ったらすぐコメント追記します。 |
辞書データの作成方法をlocal.pyにコメント追記
|
||
return response_content | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openaiの公式ページに従い、function callを実装
https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function call周りのことは完全お任せです!
"role": item["role"], | ||
"content": item["content"], | ||
**({"name": item["name"]} if "name" in item else {}), | ||
**({"function_call": item["function_call"]} if "function_call" in item else {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"name"と"function_call"はfunction callを使わない時は必要ない
@@ -0,0 +1,6 @@ | |||
requests | |||
urllib3==1.26 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openaiとboto3を同時に利用するためには、urllib3==1.26を用いる必要がある
https://community.openai.com/t/openai-cannot-import-name-default-ciphers-problem-breaking-changes-with-the-latest-version-of-requests/194265
""" | ||
質問には100文字以内で回答する。 | ||
必要に応じて"function"を実行し、その応答を用いて、"user"の言語に合わせた言語で100文字以内で回答する。 | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llama_indexを実行すると、英語で回答する時があるため、言語を"user"と同じ言語に指定
@EndoNrak レビューお願いします。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPENAI_API_KEYのところとCORS対策のところは絶対必要なのでそこの修正必要そうです!
あとはLGTM!!
print("response: ", response) | ||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local動作用まで作っていただいて感謝です!
"statusCode": status_code, | ||
"body": json.dumps({ | ||
"message": message, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORS対策しとかないといけないので、ほかのlambda functionを参考にheaderを追加しといてほしいです
参考→https://github.com/ChallengeClub/tetris_score_server/blob/main/cloud/sam/scripts/get_training_detail_from_dynamodb/get_training_detail_from_dynamodb.py
self.tetris_assistant = TetrisIndexSearch() | ||
|
||
@staticmethod | ||
def get_secret(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openaiのAPIキーってどこから読み込まれるんですか??
このメソッドで読み込まれてるんでしょうか??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
secretmanager使うの初めてだったので、わかってませんでした!
これでOKそうですね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修正してdeploy可能になりました
動作確認出来たらmerge可能です
cloud/sam/Makefile
Outdated
@@ -3,11 +3,13 @@ check: | |||
--config-env $(ENV)\ | |||
--no-execute-changeset\ | |||
--no-fail-on-empty-changeset\ | |||
--resolve-image-repos\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lambda用imagのリポジトリを自動で作成、削除してくれるオプション
cloud/sam/template.yaml
Outdated
@@ -28,7 +28,6 @@ Globals: | |||
Function: | |||
Timeout: 3 | |||
MemorySize: 128 | |||
Runtime: python3.9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globalsに書いたpropertyはすべてのresourceに例外なく適用される。
今回追加したchat_functionではimage typeを使っていて、runtimeが指定されているとsam deploy時にエラーが出る
aws/serverless-application-model#1874
'Access-Control-Allow-Origin': 'frontend_origin', | ||
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS' | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORS対策のheaderを追加
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORS参考link
CORS解説
トラブルシューティング
cloud/sam/template.yaml
Outdated
@@ -52,14 +51,16 @@ Resources: | |||
Name: tetris_api | |||
StageName: tetris_api_stage | |||
Cors: | |||
AllowMethods: "'POST, GET, PUT, OPTIONS'" | |||
AllowMethods: "'POST, GET, PUT, DELETE, OPTIONS'" | |||
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postの場合、Headerを受け取る必要がある。
@EndoNrak |
OKと思います!! |
@EndoNrak
あとでコメント追記します。