-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
543 additions
and
229 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
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
|
||
from openai import OpenAI | ||
from tenacity import retry, stop_after_attempt, wait_random_exponential | ||
|
||
client = OpenAI(api_key=os.environ.get("OPENAI_KEY")) | ||
|
||
|
||
def get_corrected_message(message: str, language_learn: str) -> str: | ||
""" | ||
Get and process the assistant's (OpenAI's model) message to continue the conversation. | ||
Params: | ||
message: The message from the assistant. | ||
language_learn: The language that the user wants to learn. | ||
Returns: | ||
The corrected message from the assistant. | ||
""" | ||
|
||
message_corrected = _chat_completion_request(message, language_learn) | ||
if message_corrected != message: | ||
return message_corrected | ||
|
||
|
||
@retry(wait=wait_random_exponential(multiplier=1, max=40), stop=stop_after_attempt(3)) | ||
def _chat_completion_request(message: str, language_learn: str) -> str: | ||
""" | ||
Request a response to the user's statement from one of OpenAI's chat models. | ||
Params: | ||
messages: The conversation history between the user and the chat model. | ||
language_learn: The language that the user wants to learn. | ||
Returns: | ||
The corrected message from OpenAI's model. | ||
""" | ||
|
||
try: | ||
content = f"You are an excellent {language_learn} teacher. Correct this sentence for any mistakes:\n{message}" | ||
completion = client.chat.completions.create( | ||
model="gpt-3.5-turbo", messages=[{"role": "system", "content": content}] | ||
) | ||
return completion.choices[0].message.content | ||
except Exception as e: | ||
return e |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
footer = html.Div(id='footer', children=[ | ||
html.P("Practice a Language. All rights reserved."), | ||
html.Div("|", className="footer-pipe"), | ||
dcc.Link("About", href="/about"), | ||
html.Div("|", className="footer-pipe"), | ||
html.A("We're open source!", target="_blank", href="https://github.com/Currie32/practice-a-language"), | ||
html.Div("|", className="footer-pipe"), | ||
html.A( | ||
|
@@ -14,7 +16,7 @@ | |
html.Div("|", className="footer-pipe"), | ||
html.P("[email protected]"), | ||
html.Div("|", className="footer-pipe"), | ||
dcc.Link("Terms & Conditions", href="/terms"), | ||
dcc.Link("Terms", href="/terms"), | ||
html.Div("|", className="footer-pipe"), | ||
dcc.Link("Privacy Policy", href="/privacy_policy"), | ||
]) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from dash import html, register_page | ||
|
||
|
||
register_page(__name__, path="/about") | ||
|
||
meta_tags = [ | ||
{ | ||
"name": "description", | ||
"content": "Practice A Language - Learn and practice languages through conversations.", | ||
}, | ||
] | ||
|
||
layout = html.Div( | ||
id="content", | ||
children=[ | ||
html.H1("About Practice a Language"), | ||
html.P( | ||
"Welcome to Practice A Language, a website to help you practice a language by having conversations. This website started from wanting to make it easier to learn a language before going on trips abroad. I became annoyed with the over-repetition of apps like Duolingo and losing track of how many times I translated “Juan come manzanas”." | ||
), | ||
html.H2("Learn what you want faster"), | ||
html.P( | ||
"Unlike other tools that force you to learn according to their lesson plans, you can practice the conversation topics and phrases that you want, whenever you want. This control should help you to be ready for your next trip abroad much faster." | ||
), | ||
html.H2("Practice at your level"), | ||
html.P( | ||
"You chat in either the language you’re learning or your native language. This allows experienced speakers to practice their vocabulary and grammar, while beginners can write in their native language and it will automatically be translated into the language they are learning." | ||
), | ||
html.H2("Practice writing and speaking"), | ||
html.P( | ||
"You have the choice to practice your new language by either writing your response or recording your voice. If you record your voice, it will be transcribed so that you can see what was understood. If you want to make a change, then you can edit the text or rerecord yourself." | ||
), | ||
html.H2("Learn from your mistakes"), | ||
html.P( | ||
"When speaking or writing in your new language, your responses are always analyzed for mistakes and will be automatically corrected. This quick feedback will help you to learn more from each conversation." | ||
), | ||
], | ||
) |
Oops, something went wrong.