Neelesh commited on
Commit
02dbdf8
β€’
1 Parent(s): 417fc65

Refactor AI provider selection and update dependencies

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -1,13 +1,17 @@
1
  import os
2
 
3
- import openai
4
- import google.generativeai as palm
5
  from anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic
6
  import streamlit as st
7
  from dotenv import load_dotenv
8
 
9
  load_dotenv()
10
 
 
 
 
 
11
  st.set_page_config(page_title="strftime AI", page_icon="πŸ•˜")
12
 
13
  with open("static/style.css") as f:
@@ -16,35 +20,32 @@ with open("static/style.css") as f:
16
  st.header("strftime AI")
17
 
18
  with st.sidebar:
19
- provider = st.radio("Choose AI Provider", options=["Anthropic", "Google Palm", "OpenAI"])
 
 
20
 
21
  text = st.text_input("Enter datetime text eg. 2023-09-28T15:27:58Z")
22
 
23
  if text:
24
- prompt = ("Convert the following datetime string into strftime format, "
25
- "show the strftime string on top and then breakdown of % symbols: " + text)
 
 
26
 
27
  if provider == "Anthropic":
28
- anthropic = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
29
  completion = anthropic.completions.create(
30
  model="claude-2",
31
  max_tokens_to_sample=300,
32
  prompt=f"{HUMAN_PROMPT} {prompt}{AI_PROMPT}",
33
  )
34
  st.text(completion.completion)
35
- elif provider == "Google Palm":
36
- palm.configure(api_key=os.getenv("PALM_API_KEY"))
37
- completion = palm.generate_text(
38
- model="models/text-bison-001",
39
- prompt=prompt,
40
- temperature=0,
41
- max_output_tokens=800,
42
- )
43
- st.text(completion.result)
44
  elif provider == "OpenAI":
45
- openai.api_key = os.getenv("OPENAI_API_KEY")
46
- chat_completion = openai.ChatCompletion.create(
47
- model="gpt-3.5-turbo",
48
- messages=[{"role": "user", "content": prompt}],
49
  )
50
  st.text(chat_completion.choices[0].message.content)
 
1
  import os
2
 
3
+ from openai import OpenAI
4
+ import google.generativeai as genai
5
  from anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic
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:
 
20
  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")
28
 
29
  if text:
30
+ prompt = (
31
+ "Convert the following datetime string into strftime format, "
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.text(completion.completion)
42
+ elif provider == "Google Gemini":
43
+ model = genai.GenerativeModel("gemini-pro")
44
+ response = model.generate_content(prompt)
45
+ st.text(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.text(chat_completion.choices[0].message.content)