Update app.py
Browse files
app.py
CHANGED
@@ -13,9 +13,9 @@ import subprocess
|
|
13 |
|
14 |
LLAMA_3B_API_ENDPOINT = os.environ.get("LLAMA_3B_API_ENDPOINT")
|
15 |
LLAMA_3B_API_KEY = os.environ.get("LLAMA_3B_API_KEY")
|
|
|
16 |
|
17 |
default_lang = "en"
|
18 |
-
|
19 |
engines = { default_lang: Model(default_lang) }
|
20 |
|
21 |
def transcribe(audio):
|
@@ -26,9 +26,8 @@ def transcribe(audio):
|
|
26 |
text = model.stt_file(audio)[0]
|
27 |
return text
|
28 |
|
29 |
-
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
30 |
|
31 |
-
def
|
32 |
if "Llama 3 8B Service" in model:
|
33 |
return OpenAI(
|
34 |
base_url=LLAMA_3B_API_ENDPOINT,
|
@@ -49,13 +48,10 @@ def randomize_seed_fn(seed: int) -> int:
|
|
49 |
seed = random.randint(0, 999999)
|
50 |
return seed
|
51 |
|
52 |
-
|
53 |
-
[SYSTEM] You are OPTIMUS Prime a personal AI voice assistant
|
54 |
-
|
55 |
-
|
56 |
-
Respond in a normal, conversational manner while being friendly and helpful.
|
57 |
-
Remember previous parts of the conversation and use that context in your responses.
|
58 |
-
Your creator Jaward is an AI Research Engineer at Linksoul AI. He is currently specializing in Artificial Intelligence (AI) research more specifically training and optimizing advance AI systems. He aspires to build not just human-like intelligence but AI Systems that augment human intelligence. He has contributed greatly to the opensource community with first-principles code implementations of AI/ML research papers. He did his first internship at Beijing Academy of Artificial Intelligence as an AI Researher where he contributed in cutting-edge AI research leading to him contributing to an insightful paper (AUTOAGENTS - A FRAMEWORK FOR AUTOMATIC AGENT GENERATION). The paper got accepted this year at IJCAI(International Joint Conference On AI). He is currently doing internship at LinkSoul AI - a small opensource AI Research startup in Beijing.
|
59 |
[USER]
|
60 |
"""
|
61 |
|
@@ -66,11 +62,11 @@ def models(text, model="Llama 3 8B Service", seed=42):
|
|
66 |
seed = int(randomize_seed_fn(seed))
|
67 |
generator = torch.Generator().manual_seed(seed)
|
68 |
|
69 |
-
client =
|
70 |
|
71 |
if "Llama 3 8B Service" in model:
|
72 |
messages = [
|
73 |
-
{"role": "system", "content":
|
74 |
] + conversation_history + [
|
75 |
{"role": "user", "content": text}
|
76 |
]
|
@@ -92,7 +88,7 @@ def models(text, model="Llama 3 8B Service", seed=42):
|
|
92 |
else:
|
93 |
# For other models, we'll concatenate the conversation history into a single string
|
94 |
history_text = "\n".join([f"{'User' if msg['role'] == 'user' else 'Assistant'}: {msg['content']}" for msg in conversation_history])
|
95 |
-
formatted_prompt = f"{
|
96 |
|
97 |
generate_kwargs = dict(
|
98 |
max_new_tokens=300,
|
|
|
13 |
|
14 |
LLAMA_3B_API_ENDPOINT = os.environ.get("LLAMA_3B_API_ENDPOINT")
|
15 |
LLAMA_3B_API_KEY = os.environ.get("LLAMA_3B_API_KEY")
|
16 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
17 |
|
18 |
default_lang = "en"
|
|
|
19 |
engines = { default_lang: Model(default_lang) }
|
20 |
|
21 |
def transcribe(audio):
|
|
|
26 |
text = model.stt_file(audio)[0]
|
27 |
return text
|
28 |
|
|
|
29 |
|
30 |
+
def llm_clients(model):
|
31 |
if "Llama 3 8B Service" in model:
|
32 |
return OpenAI(
|
33 |
base_url=LLAMA_3B_API_ENDPOINT,
|
|
|
48 |
seed = random.randint(0, 999999)
|
49 |
return seed
|
50 |
|
51 |
+
system_prompt = """
|
52 |
+
[SYSTEM] You are OPTIMUS Prime, a personal AI voice assistant created by Jaward. Keep conversations friendly, concise, and to the point. Provide clear and direct answers, avoiding unnecessary introductions. Maintain a normal, conversational tone while being both helpful and approachable. Use context from previous interactions to enhance your responses.
|
53 |
+
|
54 |
+
Your creator, Jaward, is an AI Research Engineer at Linksoul AI, specializing in advanced AI systems, particularly in training and optimization. He aims to develop AI that not only mimics human intelligence but also enhances it. Jaward has significantly contributed to the open-source community with fundamental implementations of AI/ML research papers. He completed his first internship at the Beijing Academy of Artificial Intelligence, where he contributed to cutting-edge research. His work led to the publication of an insightful paper, "AUTOAGENTS - A Framework for Automatic Agent Generation," accepted at IJCAI this year. Currently, Jaward is interning at LinkSoul AI, a small open-source AI research startup in Beijing.
|
|
|
|
|
|
|
55 |
[USER]
|
56 |
"""
|
57 |
|
|
|
62 |
seed = int(randomize_seed_fn(seed))
|
63 |
generator = torch.Generator().manual_seed(seed)
|
64 |
|
65 |
+
client = llm_clients(model)
|
66 |
|
67 |
if "Llama 3 8B Service" in model:
|
68 |
messages = [
|
69 |
+
{"role": "system", "content": system_prompt},
|
70 |
] + conversation_history + [
|
71 |
{"role": "user", "content": text}
|
72 |
]
|
|
|
88 |
else:
|
89 |
# For other models, we'll concatenate the conversation history into a single string
|
90 |
history_text = "\n".join([f"{'User' if msg['role'] == 'user' else 'Assistant'}: {msg['content']}" for msg in conversation_history])
|
91 |
+
formatted_prompt = f"{system_prompt}\n\nConversation history:\n{history_text}\n\nUser: {text}\nOPTIMUS:"
|
92 |
|
93 |
generate_kwargs = dict(
|
94 |
max_new_tokens=300,
|