robinroy03 commited on
Commit
e226db7
1 Parent(s): ba86ee1

new google gemini added

Browse files
Files changed (2) hide show
  1. main.py +32 -5
  2. requirements.txt +18 -0
main.py CHANGED
@@ -1,17 +1,20 @@
1
  from flask import Flask
2
  from flask import request
3
  from groq import Groq
 
4
 
5
  import os
6
 
7
  app = Flask(__name__)
8
- client = Groq(
9
  api_key=os.environ.get("GROQ_API_KEY")
10
  )
 
 
11
 
12
 
13
- @app.route("/api/generate", methods=['POST'])
14
- def completion():
15
  """
16
  {
17
  "model": "llama3-70b-8192",
@@ -24,7 +27,7 @@ def completion():
24
  model = message['model']
25
  prompt = message['prompt']
26
 
27
- chat_completion = client.chat.completions.create(
28
  messages=[
29
  {
30
  "role": "user",
@@ -36,4 +39,28 @@ def completion():
36
 
37
  return chat_completion.to_dict()
38
 
39
- # curl -v -X POST 'https://robinroy03-fury-bot.hf.space/api/generate' --header 'Content-Type: application/json' --data '{"model": "llama3-70b-8192", "prompt": "why is sky blue?"}'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from flask import Flask
2
  from flask import request
3
  from groq import Groq
4
+ import google.generativeai
5
 
6
  import os
7
 
8
  app = Flask(__name__)
9
+ groq_client = Groq(
10
  api_key=os.environ.get("GROQ_API_KEY")
11
  )
12
+ google.generativeai.configure(
13
+ api_key=os.environ.get("GEMINI_API_KEY"))
14
 
15
 
16
+ @app.route("/api/groq/generate", methods=['POST'])
17
+ def groq_completion():
18
  """
19
  {
20
  "model": "llama3-70b-8192",
 
27
  model = message['model']
28
  prompt = message['prompt']
29
 
30
+ chat_completion = groq_client.chat.completions.create(
31
  messages=[
32
  {
33
  "role": "user",
 
39
 
40
  return chat_completion.to_dict()
41
 
42
+
43
+ @app.route("/api/google/generate", methods=['POST'])
44
+ def google_completion():
45
+ """
46
+ {
47
+ "model": "gemini-1.5-flash",
48
+ "prompt": ""
49
+ }
50
+ """
51
+
52
+ message = request.get_json()
53
+
54
+ model = message['model']
55
+ prompt = message['prompt']
56
+ llm_model = google.generativeai.GenerativeModel(model)
57
+
58
+ chat_completion = llm_model.generate_content(prompt)
59
+
60
+ return chat_completion.to_dict()
61
+
62
+
63
+ # curl -v -X POST 'https://robinroy03-fury-bot.hf.space/api/groq/generate' --header 'Content-Type: application/json' --data '{"model": "llama3-70b-8192", "prompt": "why is sky blue?"}'
64
+
65
+
66
+ # curl -v POST 'http://127.0.0.1:8000/api/google/generate' --header 'Content-Type: application/json' --data '{"model": "gemini-1.5-flash", "prompt": "why is sky blue?"}'
requirements.txt CHANGED
@@ -4,6 +4,7 @@ annotated-types==0.6.0
4
  anyio==4.3.0
5
  attrs==23.2.0
6
  blinker==1.8.2
 
7
  certifi==2024.2.2
8
  charset-normalizer==3.3.2
9
  click==8.1.7
@@ -18,11 +19,21 @@ filelock==3.14.0
18
  Flask==3.0.3
19
  frozenlist==1.4.1
20
  fsspec==2024.5.0
 
 
 
 
 
 
 
21
  greenlet==3.0.3
22
  groq==0.8.0
 
 
23
  gunicorn==22.0.0
24
  h11==0.14.0
25
  httpcore==1.0.5
 
26
  httptools==0.6.1
27
  httpx==0.27.0
28
  huggingface-hub==0.23.0
@@ -49,9 +60,14 @@ mypy-extensions==1.0.0
49
  numpy==1.26.4
50
  orjson==3.10.3
51
  packaging==23.2
 
 
 
 
52
  pydantic==1.10.13
53
  pydantic_core==2.18.2
54
  Pygments==2.18.0
 
55
  pyproject-toml==0.0.10
56
  python-dotenv==1.0.1
57
  python-multipart==0.0.9
@@ -60,6 +76,7 @@ referencing==0.35.1
60
  requests==2.31.0
61
  rich==13.7.1
62
  rpds-py==0.18.1
 
63
  setuptools==70.0.0
64
  shellingham==1.5.4
65
  sniffio==1.3.1
@@ -73,6 +90,7 @@ typer==0.12.3
73
  typing-inspect==0.9.0
74
  typing_extensions==4.11.0
75
  ujson==5.10.0
 
76
  urllib3==2.2.1
77
  uvicorn==0.29.0
78
  uvloop==0.19.0
 
4
  anyio==4.3.0
5
  attrs==23.2.0
6
  blinker==1.8.2
7
+ cachetools==5.3.3
8
  certifi==2024.2.2
9
  charset-normalizer==3.3.2
10
  click==8.1.7
 
19
  Flask==3.0.3
20
  frozenlist==1.4.1
21
  fsspec==2024.5.0
22
+ google-ai-generativelanguage==0.6.6
23
+ google-api-core==2.19.1
24
+ google-api-python-client==2.135.0
25
+ google-auth==2.30.0
26
+ google-auth-httplib2==0.2.0
27
+ google-generativeai==0.7.1
28
+ googleapis-common-protos==1.63.2
29
  greenlet==3.0.3
30
  groq==0.8.0
31
+ grpcio==1.64.1
32
+ grpcio-status==1.62.2
33
  gunicorn==22.0.0
34
  h11==0.14.0
35
  httpcore==1.0.5
36
+ httplib2==0.22.0
37
  httptools==0.6.1
38
  httpx==0.27.0
39
  huggingface-hub==0.23.0
 
60
  numpy==1.26.4
61
  orjson==3.10.3
62
  packaging==23.2
63
+ proto-plus==1.24.0
64
+ protobuf==4.25.3
65
+ pyasn1==0.6.0
66
+ pyasn1_modules==0.4.0
67
  pydantic==1.10.13
68
  pydantic_core==2.18.2
69
  Pygments==2.18.0
70
+ pyparsing==3.1.2
71
  pyproject-toml==0.0.10
72
  python-dotenv==1.0.1
73
  python-multipart==0.0.9
 
76
  requests==2.31.0
77
  rich==13.7.1
78
  rpds-py==0.18.1
79
+ rsa==4.9
80
  setuptools==70.0.0
81
  shellingham==1.5.4
82
  sniffio==1.3.1
 
90
  typing-inspect==0.9.0
91
  typing_extensions==4.11.0
92
  ujson==5.10.0
93
+ uritemplate==4.1.1
94
  urllib3==2.2.1
95
  uvicorn==0.29.0
96
  uvloop==0.19.0