Skip to content

Commit

Permalink
changed default text and error still exists if OPENAI key not found a…
Browse files Browse the repository at this point in the history
…t start, but traces back to ta source
  • Loading branch information
j-dominguez9 committed Jul 8, 2024
1 parent 2f5e510 commit daf14a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
5 changes: 2 additions & 3 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def export_txt(strings):
else:
return gr.update(visible=False)


def switch(source_lang, source_text, target_lang, output_final):
if output_final:
return (
Expand Down Expand Up @@ -314,9 +315,7 @@ def close_btn_hide(output_diff):
with gr.Column(scale=4):
source_text = gr.Textbox(
label="Source Text",
value="How we live is so different from how we ought to live that he who studies "
+ "what ought to be done rather than what is done will learn the way to his downfall "
+ "rather than to his preservation.",
value="If one advances confidently in the direction of his dreams, and endeavors to live the life which he has imagined, he will meet with a success unexpected in common hours.",
lines=12,
)
with gr.Tab("Final"):
Expand Down
44 changes: 23 additions & 21 deletions app/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# Hide js_mode in UI now, update in plan.
JS_MODE = False
ENDPOINT = ""
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))


# Add your LLMs here
Expand All @@ -35,26 +34,29 @@ def model_load(
TEMPERATURE = temperature
JS_MODE = js_mode

if endpoint == "Groq":
client = openai.OpenAI(
api_key=api_key if api_key else os.getenv("GROQ_API_KEY"),
base_url="https://api.groq.com/openai/v1",
)
elif endpoint == "TogetherAI":
client = openai.OpenAI(
api_key=api_key if api_key else os.getenv("TOGETHER_API_KEY"),
base_url="https://api.together.xyz/v1",
)
elif endpoint == "CUSTOM":
client = openai.OpenAI(api_key=api_key, base_url=base_url)
elif endpoint == "Ollama":
client = openai.OpenAI(
api_key="ollama", base_url="http://localhost:11434/v1"
)
else:
client = openai.OpenAI(
api_key=api_key if api_key else os.getenv("OPENAI_API_KEY")
)
match endpoint:
case "OpenAI":
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
case "Groq":
client = openai.OpenAI(
api_key=api_key if api_key else os.getenv("GROQ_API_KEY"),
base_url="https://api.groq.com/openai/v1",
)
case "TogetherAI":
client = openai.OpenAI(
api_key=api_key if api_key else os.getenv("TOGETHER_API_KEY"),
base_url="https://api.together.xyz/v1",
)
case "CUSTOM":
client = openai.OpenAI(api_key=api_key, base_url=base_url)
case "Ollama":
client = openai.OpenAI(
api_key="ollama", base_url="http://localhost:11434/v1"
)
case _:
client = openai.OpenAI(
api_key=api_key if api_key else os.getenv("OPENAI_API_KEY")
)


def rate_limit(get_max_per_minute):
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ authors = ["Andrew Ng <[email protected]>"]
license = "MIT"
readme = "README.md"
package-mode = true
packages = [
{ include = "translation_agent", from = "src" },
]
packages = [{ include = "translation_agent", from = "src" }]
repository = "https://github.com/andrewyng/translation-agent"
keywords = ["translation", "agents", "LLM", "machine translation"]

Expand Down

0 comments on commit daf14a6

Please sign in to comment.