Neelesh commited on
Commit
0214b2e
β€’
1 Parent(s): 3c49a75

Add support for groq

Browse files
Files changed (3) hide show
  1. .env.example +1 -0
  2. app.py +35 -19
  3. requirements.txt +2 -0
.env.example CHANGED
@@ -1,3 +1,4 @@
1
  OPENAI_API_KEY=
2
  ANTHROPIC_API_KEY=
3
  GOOGLE_API_KEY=
 
 
1
  OPENAI_API_KEY=
2
  ANTHROPIC_API_KEY=
3
  GOOGLE_API_KEY=
4
+ GROQ_API_KEY=
app.py CHANGED
@@ -1,17 +1,15 @@
1
  import os
2
 
 
3
  from openai import OpenAI
 
4
  import google.generativeai as genai
5
- from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT
6
- import streamlit as st
7
  from dotenv import load_dotenv
 
8
 
9
  load_dotenv()
10
 
11
- anthropic = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
12
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
14
-
15
  st.set_page_config(page_title="strftime AI", page_icon="πŸ•˜")
16
 
17
  with open("static/style.css") as f:
@@ -21,8 +19,14 @@ st.header("strftime AI")
21
 
22
  with st.sidebar:
23
  provider = st.radio(
24
- "Choose AI Provider", options=["Anthropic", "Google Gemini", "OpenAI"]
25
- )
 
 
 
 
 
 
26
 
27
  text = st.text_input("Enter datetime text eg. 2023-09-28T15:27:58Z", value="2023-09-28T15:27:58Z")
28
 
@@ -32,20 +36,32 @@ if text:
32
  "show the strftime string on top and then breakdown of % symbols: " + text
33
  )
34
 
35
- if provider == "Anthropic":
36
- completion = anthropic.completions.create(
37
- model="claude-2",
38
- max_tokens_to_sample=300,
39
- prompt=f"{HUMAN_PROMPT} {prompt}{AI_PROMPT}",
 
40
  )
41
- st.markdown(completion.completion)
42
- elif provider == "Google Gemini":
43
- model = genai.GenerativeModel("gemini-pro")
44
- response = model.generate_content(prompt)
45
- st.markdown(response.text)
46
  elif provider == "OpenAI":
 
47
  chat_completion = client.chat.completions.create(
 
48
  model="gpt-3.5-turbo",
49
- messages=[{"role": "user", "content": prompt}]
50
  )
51
  st.markdown(chat_completion.choices[0].message.content)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
 
3
+ from groq import Groq
4
  from openai import OpenAI
5
+ from anthropic import Anthropic
6
  import google.generativeai as genai
7
+
 
8
  from dotenv import load_dotenv
9
+ import streamlit as st
10
 
11
  load_dotenv()
12
 
 
 
 
 
13
  st.set_page_config(page_title="strftime AI", page_icon="πŸ•˜")
14
 
15
  with open("static/style.css") as f:
 
19
 
20
  with st.sidebar:
21
  provider = st.radio(
22
+ "Choose AI Provider",
23
+ options=[
24
+ "Groq",
25
+ "Anthropic",
26
+ "OpenAI",
27
+ "Google Gemini",
28
+ ]
29
+ )
30
 
31
  text = st.text_input("Enter datetime text eg. 2023-09-28T15:27:58Z", value="2023-09-28T15:27:58Z")
32
 
 
36
  "show the strftime string on top and then breakdown of % symbols: " + text
37
  )
38
 
39
+ if provider == "Groq":
40
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
41
+ chat_completion = client.chat.completions.create(
42
+ messages=[{"role": "user", "content": prompt}],
43
+ model="mixtral-8x7b-32768",
44
+ max_tokens=1024,
45
  )
46
+ st.markdown(chat_completion.choices[0].message.content)
 
 
 
 
47
  elif provider == "OpenAI":
48
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
49
  chat_completion = client.chat.completions.create(
50
+ messages=[{"role": "user", "content": prompt}],
51
  model="gpt-3.5-turbo",
52
+ max_tokens=1024,
53
  )
54
  st.markdown(chat_completion.choices[0].message.content)
55
+ elif provider == "Anthropic":
56
+ client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
57
+ message = client.messages.create(
58
+ messages=[{"role": "user", "content": prompt}],
59
+ model="claude-3-haiku-20240307",
60
+ max_tokens=1024,
61
+ )
62
+ st.markdown(message.content[0].text)
63
+ elif provider == "Google Gemini":
64
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
65
+ model = genai.GenerativeModel("gemini-pro")
66
+ response = model.generate_content(prompt)
67
+ st.markdown(response.text)
requirements.txt CHANGED
@@ -1,5 +1,7 @@
 
1
  openai
2
  anthropic
3
  google-generativeai
 
4
  python-dotenv
5
  streamlit
 
1
+ groq
2
  openai
3
  anthropic
4
  google-generativeai
5
+
6
  python-dotenv
7
  streamlit