refinement
Browse files- gemini.py +22 -14
- handler.py +1 -1
gemini.py
CHANGED
|
@@ -3,31 +3,39 @@ import os
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from typing import Optional
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
class GeminiModel:
|
| 7 |
"""
|
| 8 |
-
This class is used to interact with the
|
| 9 |
|
| 10 |
Args:
|
| 11 |
-
model: The name of the model to be used. Defaults to '
|
| 12 |
max_output_tokens: The maximum number of tokens to generate. Defaults to 1024.
|
| 13 |
-
|
| 14 |
temperature: The temperature of the model. Defaults to 0.0.
|
| 15 |
top_k: The number of top tokens to consider. Defaults to 5.
|
| 16 |
"""
|
| 17 |
|
| 18 |
-
model=None
|
| 19 |
def __init__(self,
|
| 20 |
model: Optional[str] = 'gemini-pro',
|
| 21 |
-
max_output_tokens: Optional[int] = 1024,
|
| 22 |
-
top_p: Optional[float] = 1.0,
|
| 23 |
-
temperature: Optional[float] = 0.0,
|
| 24 |
-
top_k: Optional[int] = 5
|
| 25 |
):
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 28 |
-
self.model=genai.GenerativeModel(model)
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from typing import Optional
|
| 5 |
|
| 6 |
+
generation_config=genai.types.GenerationConfig(
|
| 7 |
+
# Only one candidate for now.
|
| 8 |
+
#candidate_count=1,
|
| 9 |
+
#stop_sequences=['x'],
|
| 10 |
+
#max_output_tokens=1024,
|
| 11 |
+
temperature=1.0
|
| 12 |
+
)
|
| 13 |
class GeminiModel:
|
| 14 |
"""
|
| 15 |
+
This class is used to interact with the Google LLM models for text generation.
|
| 16 |
|
| 17 |
Args:
|
| 18 |
+
model: The name of the model to be used. Defaults to 'gemini-pro'.
|
| 19 |
max_output_tokens: The maximum number of tokens to generate. Defaults to 1024.
|
| 20 |
+
top_p: The probability of generating the next token. Defaults to 1.0.
|
| 21 |
temperature: The temperature of the model. Defaults to 0.0.
|
| 22 |
top_k: The number of top tokens to consider. Defaults to 5.
|
| 23 |
"""
|
| 24 |
|
|
|
|
| 25 |
def __init__(self,
|
| 26 |
model: Optional[str] = 'gemini-pro',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
):
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
load_dotenv()
|
| 31 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 32 |
+
self.model = genai.GenerativeModel(model)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def execute(self, prompt: str) -> str:
|
| 36 |
|
| 37 |
+
try:
|
| 38 |
+
response = self.model.generate_content(prompt, generation_config=None)
|
| 39 |
+
return response.text
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"An error occurred: {e}"
|
handler.py
CHANGED
|
@@ -15,5 +15,5 @@ def code_review(code,c_prompt=None):
|
|
| 15 |
|
| 16 |
model=GeminiModel()
|
| 17 |
res= model.execute(prompt)
|
| 18 |
-
return res
|
| 19 |
|
|
|
|
| 15 |
|
| 16 |
model=GeminiModel()
|
| 17 |
res= model.execute(prompt)
|
| 18 |
+
return res
|
| 19 |
|