Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 4 |
-
from google.genai import types
|
| 5 |
|
| 6 |
-
# Client initialization
|
| 7 |
-
|
| 8 |
-
api_key=os.environ.get("
|
| 9 |
-
http_options=types.HttpOptions(api_version="v1beta"),
|
| 10 |
)
|
| 11 |
|
| 12 |
SYSTEM_PROMPT = "antworte kurz und knapp. optimiere deine antwort für sprachausgabe."
|
|
@@ -19,34 +17,34 @@ def generate_with_history(input_text, history):
|
|
| 19 |
if history is None:
|
| 20 |
history = []
|
| 21 |
|
| 22 |
-
# Build the
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
for msg in history:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
# Add the current user prompt
|
| 31 |
-
|
| 32 |
-
role
|
| 33 |
-
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
tools = [types.Tool(google_search=types.GoogleSearch())]
|
| 37 |
-
config = types.GenerateContentConfig(
|
| 38 |
-
tools=tools,
|
| 39 |
-
system_instruction=SYSTEM_PROMPT,
|
| 40 |
-
)
|
| 41 |
|
| 42 |
try:
|
| 43 |
-
response =
|
| 44 |
-
model="
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
-
response_text = response.
|
| 50 |
|
| 51 |
# Update history: add the current exchange
|
| 52 |
history.append({"role": "user", "content": input_text})
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from groq import Groq
|
|
|
|
| 4 |
|
| 5 |
+
# Client initialization
|
| 6 |
+
client = Groq(
|
| 7 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
SYSTEM_PROMPT = "antworte kurz und knapp. optimiere deine antwort für sprachausgabe."
|
|
|
|
| 17 |
if history is None:
|
| 18 |
history = []
|
| 19 |
|
| 20 |
+
# Build the messages list including history
|
| 21 |
+
# Note: Groq uses "assistant" instead of Gemini's "model"
|
| 22 |
+
messages = [
|
| 23 |
+
{"role": "system", "content": SYSTEM_PROMPT}
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
for msg in history:
|
| 27 |
+
role = "assistant" if msg["role"] == "model" else msg["role"]
|
| 28 |
+
messages.append({
|
| 29 |
+
"role": role,
|
| 30 |
+
"content": msg["content"]
|
| 31 |
+
})
|
| 32 |
|
| 33 |
# Add the current user prompt
|
| 34 |
+
messages.append({
|
| 35 |
+
"role": "user",
|
| 36 |
+
"content": input_text
|
| 37 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
try:
|
| 40 |
+
response = client.chat.completions.create(
|
| 41 |
+
model="llama-3.3-70b-versatile", # or "llama-3.1-70b-versatile", "mixtral-8x7b-32768", etc.
|
| 42 |
+
messages=messages,
|
| 43 |
+
temperature=0.7,
|
| 44 |
+
max_tokens=1024,
|
| 45 |
)
|
| 46 |
|
| 47 |
+
response_text = response.choices[0].message.content
|
| 48 |
|
| 49 |
# Update history: add the current exchange
|
| 50 |
history.append({"role": "user", "content": input_text})
|