Spaces:
Running

mgokg commited on
Commit
5b40f94
·
verified ·
1 Parent(s): 0b78fc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -27
app.py CHANGED
@@ -1,12 +1,10 @@
1
  import os
2
  import gradio as gr
3
- from google import genai
4
- from google.genai import types
5
 
6
- # Client initialization (v1beta is required for Google Search as a tool)
7
- client_genai = genai.Client(
8
- api_key=os.environ.get("GEMINI_API_KEY"),
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 contents list including history
23
- contents = []
 
 
 
 
24
  for msg in history:
25
- contents.append(types.Content(
26
- role=msg["role"],
27
- parts=[types.Part.from_text(text=msg["content"])]
28
- ))
 
29
 
30
  # Add the current user prompt
31
- contents.append(types.Content(
32
- role="user",
33
- parts=[types.Part.from_text(text=input_text)]
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 = client_genai.models.generate_content(
44
- model="gemini-2.5-flash-lite",
45
- contents=contents,
46
- config=config,
 
47
  )
48
 
49
- response_text = response.text
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})