-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from willismax/master
修正至可用狀態
- Loading branch information
Showing
5 changed files
with
40 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,24 @@ | ||
from api.prompt import Prompt | ||
|
||
import os | ||
import openai | ||
from openai import OpenAI | ||
client = OpenAI() | ||
|
||
openai.api_key = os.getenv("OPENAI_API_KEY") | ||
client.api_key = os.getenv("OPENAI_API_KEY") | ||
|
||
|
||
class ChatGPT: | ||
def __init__(self): | ||
self.prompt = Prompt() | ||
self.model = os.getenv("OPENAI_MODEL", default = "text-davinci-003") | ||
self.model = os.getenv("OPENAI_MODEL", default = "gpt-4-1106-preview") | ||
self.temperature = float(os.getenv("OPENAI_TEMPERATURE", default = 0)) | ||
self.frequency_penalty = float(os.getenv("OPENAI_FREQUENCY_PENALTY", default = 0)) | ||
self.presence_penalty = float(os.getenv("OPENAI_PRESENCE_PENALTY", default = 0.6)) | ||
self.max_tokens = int(os.getenv("OPENAI_MAX_TOKENS", default = 240)) | ||
self.max_tokens = int(os.getenv("OPENAI_MAX_TOKENS", default = 500)) | ||
|
||
def get_response(self): | ||
response = openai.Completion.create( | ||
response = client.chat.completions.create( | ||
model=self.model, | ||
prompt=self.prompt.generate_prompt(), | ||
temperature=self.temperature, | ||
frequency_penalty=self.frequency_penalty, | ||
presence_penalty=self.presence_penalty, | ||
max_tokens=self.max_tokens | ||
messages=self.prompt.generate_prompt(), | ||
) | ||
return response['choices'][0]['text'].strip() | ||
return response.choices[0].message.content | ||
|
||
def add_msg(self, text): | ||
self.prompt.add_msg(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Flask==2.2.2 | ||
flask==2.2.2 | ||
Werkzeug==2.3.7 | ||
line-bot-sdk | ||
openai | ||
openai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
{ | ||
"version": 2, | ||
"builds": [ | ||
{ | ||
"src": "api/index.py", | ||
"use": "@vercel/python" | ||
} | ||
{ | ||
"src": "api/index.py", | ||
"use": "@vercel/python" | ||
} | ||
], | ||
"routes": [ | ||
{ | ||
"src": "/(.*)", | ||
"dest": "api/index.py" | ||
} | ||
{ | ||
"src": "/(.*)", | ||
"dest": "api/index.py" | ||
} | ||
] | ||
} | ||
} |
9f6a8c6
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.
Successfully deployed to the following URLs:
gpt-linebot-python-flask-for-vercel – ./
gpt-linebot-python-flask-for-vercel-puce.vercel.app
gpt-linebot-python-flask-for-vercel-git-master-howarder3.vercel.app
gpt-linebot-python-flask-for-vercel-howarder3.vercel.app